I have written code in java:
import java.applet.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ProstyApplet extends Applet
{
Button b1 = new Button("BUTTON");
@Override
public void init()
{
System.out.println("START");
b1.addActionListener(new B1());
add(b1);
}
@Override
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawOval(150,150,100,100);
}
class B1 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
//here I want to draw rectangle
}
}
}
I have created button B1
and I created ActionListener
for B1
. I want my program to draw rectangle when I click it but I have problem with using paint()
, repaint()
methods to do so. What is the way to draw rectangle after pressing the button?