Q:

Java Applet - Draw Shape using Button Component

0

This Program is used to draw various through Button using Java Applet.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class buttshape extends Applet
{
Label l1,l2;
Button b1,b2;
Graphics g;

public void init()
{
l1 = new Label("Circle");
l2 = new Label("Square");

b1 = new Button("Circle");
b2 = new Button("Square");

add(l1); add(b1); add(l2); add(b2);

b1.addActionListener(new s());
b2.addActionListener(new s());

g=getGraphics();
}

class s implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
g.drawOval(100,100,100,100);
}

if(e.getSource()==b2)
{
g.drawRect(250,100,100,100);
}
}
}
}

/* <applet code = "buttshape.class" height = 400 width = 400>
</applet> */

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now