Java

Java Applet - Draw Shape using Button Component

Java Applet - Draw Shape using Button Component
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> */
Senthilvelan Sambamoorthy

Senthilvelan Sambamoorthy is working as a Professor in Department of Master of Computer Applications, Paavai Engineering College, Namakkal, Tamilnadu, India, He is Masters in Computers Applications. Having 18+ years of experience and his area of interest is Java, JSP, Servlet, J2EE, C#, PHP, Python ASP.NET, SQL Server and etc.