0% found this document useful (0 votes)
111 views

Applet Demo

This Java code defines an applet with three buttons for drawing different shapes. The init() method initializes three buttons labeled "circle", "Rect", and "Color circle". The actionPerformed() method gets the button label and calls repaint(). The paint() method checks the button label and either draws an oval, rectangle, or filled oval depending on the label.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views

Applet Demo

This Java code defines an applet with three buttons for drawing different shapes. The init() method initializes three buttons labeled "circle", "Rect", and "Color circle". The actionPerformed() method gets the button label and calls repaint(). The paint() method checks the button label and either draws an oval, rectangle, or filled oval depending on the label.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

APPLETDEMO.

JAVA

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
//<applet code="Appletdemo" height="500"
width="500"></applet>
public class Appletdemo extends Applet implements
ActionListener
{
String s;
Button b1,b2,b3;
public void init()
{
b1=new Button("circle");
b2= new Button("Rect");
b3 = new Button("Color circle");
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
s=ae.getActionCommand();
repaint();
}
public void paint(Graphics g)
//********
{
try
{
if(s.equals("circle"))
g.drawOval(122,53,62,75);
if(s.equals("Rect"))
g.drawRect(122,60,122,60);
if(s.equals("Color circle"))
g.fillOval(122,53,62,75);
}
catch(NullPointerException e)
{
}
}

OUTPUT:

E:\jdk1.3.0\bin> javac appletdemo.java

E:\jdk1.3.0\bin> appletviewer appletdemo.java

You might also like