Java Help

Soldato
Joined
30 Nov 2005
Posts
3,084
Location
London
I need some help with a Java Novice,

What I have been trying to do for a few hours now is link a Button in a Java Apllet to draw a rectangles on the screen.

I have created a button which when pressed I would like to draw around 10 boxes in a specific area.

Thanks
 
Right ok,

In the
public void init()
{



I have added


squares = new Button("Squares");
add(squares);
squares.addActionListener(this);



How do I get the button to draw when clicked, I have become confused by the Tutorials and other information on the net.

I think its to do with the


public void paint(Graphics g)
{



and
public void actionPerformed(ActionEvent event)
{



But cant for the life of me work it out.
 
have the actionlistener class (the main class that is creating the buttons needs to implement the actionListener) run the paint method each time the button is pressed (so each time the actionperformed method is ran).

Not done any java awt/2d graphics for a year or so so can't remember the code off the top of my head but this should help you a bit.

Code:
public void actionPerformed(ActionEvent e) {
//call the paint method for the graphics      }

Hope this helps.
 
Back
Top Bottom