Simple Help required....
I am just trying to entertain myself in java to keep myself interested
in learning it. I want to create a square, and every time I press 'Up'
on the keyboard the square size increases. I can draw everything, but
I am unsure where I would go from there...any hints?
so far I have...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Line{
private int x;
private int y;
public static void main(String args[])
{
x = 50;
y = 100;
JPanel face = new JPanel()
{
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawRect (50,50,100,100);
}
};
face.setBackground(Color.WHITE);
face.setPreferredSize( new Dimension(100, 100) );
JScrollPane scrollPane = new JScrollPane( face );
scrollPane.setPreferredSize( new Dimension(200, 200) );
JFrame frame = new JFrame();
frame.getContentPane().add( scrollPane );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible( true );
}
public void keyPressed(KeyEvent e) {
//what do I do here??? If(e = 'up key'){x= x+25; y = y+25 }
}
}
Thanks,
Peter