I got the square and I got the mouse click input working but I'm not sure how to move the square.
import java.awt.*;
import javax.swing.*;
public class JavaSquare extends JApplet implements MouseListener
{
int height=20;
int width=20;
int x=10;
int y=10;
public void paint(Graphics g )
{
g.setColor(Color.red);
g.drawRect(10,10,height,width);
g.setColor(Color.blue);
g.fillRect(x,y,height,width);
}
public void Frame()
{
JFrame frame = new JFrame("Java Square Assignment");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setLayout(new BorderLayout());
}
public JavaSquare()
{
addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
System.out.println("Mouse clicked; # of clicks: " + e.getClickCount() );
if (e.getClickCount() == 2)
{
}
}
});
}
}

New Topic/Question
Reply


MultiQuote


|