import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class NewApplet extends Applet implements ActionListener{
TextField t1;
Button b1;
Label l1;
int r=0;
public void init() {
l1 = new Label("Enter radius of circle:");
t1 = new TextField(5);
b1 = new Button("Draw Circle");
add(l1);
add(t1);
add(b1);
b1.addActionListener(this);
}
public void paint(Graphics g)
{
g.drawOval(50, 50, r*2, r*2);
g.setColor(Color.blue);
g.fillOval(50, 50, r*2, r*2);
}
public void actionPerformed(ActionEvent e)
{
r= Integer.parseInt(t1.getText());
repaint();
}
}
Applet code:
<html>
<head>
<title>circle in Blue color</title>
</head>
<body>
<applet code="NewApplet.class" width="800" height="800"></applet>
</body>
</html>
OUTPUT: