import javax.swing.JFrame;
public class Breifcase
{
//-----------------------------------------------------------------
// Creates and displays the application frame.
//-----------------------------------------------------------------
public static void main (String[] args)
{
JFrame frame = new JFrame ("Briefcase");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new BriefcasePanel());
frame.pack();
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BriefcasePanel extends JPanel
{
private final int WIDTH = 300, HEIGHT = 200;
private final int IMAGE_SIZE = 20;
private ImageIcon open, close,currentImage;
private int x, y;
//-----------------------------------------------------------------
// Constructor: Sets up this panel and loads the images.
//-----------------------------------------------------------------
public DirectionPanel()
{
addMouseListener (new BriefcaseListener());
x = WIDTH / 2;
y = HEIGHT / 2;
open = new ImageIcon ("caseOpen.gif");
close = new ImageIcon ("caseClose.gif");
currentImage = close;
setBackground (Color.black);
setPreferredSize (new Dimension(WIDTH, HEIGHT));
setFocusable(true);
}
//-----------------------------------------------------------------
// Draws the image in the current location.
//-----------------------------------------------------------------
public void paintComponent (Graphics page)
{
super.paintComponent (page);
currentImage.paintIcon (this, page, x, y);
}
//*****************************************************************
// Represents the listener for mouse activity.
//*****************************************************************
private class BriefcaseListener implements MouseListener
{
public void mouseClicked (MouseEvent event)
{
switch ((int)event.getPoint())
{
case MouseEvent.getPoint:
currentImage=open;
break;
case MouseEvent.getPoint:
currentImage=close;
break;
}
repaint();
}
public void mousePressed (MouseEvent event) {}
public void mouseReleased (MouseEvent event) {}
public void mouseEntered (MouseEvent event) {}
public void mouseExited (MouseEvent event) {}
}
}
Now, the error message that I am getting is where I have: switch ((int)event.getPoint()), it says inconvertible types found :java.awt.Point required: int. So I put a random integer in getPoint() when I did that it gave me an error message saying, getPoint() in java.awt.event.MouseEvent cannot be applied to (int). So I take t=out the type casting and now have switch (event.getPoint(320)) and it gives me the same error message . I have no idea what to do now and the error messages just keep going in circles. Please can you help? Code would be nice to have.

New Topic/Question
Reply



MultiQuote







|