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

Applet

1. The document describes an algorithm to create a Java applet that draws different shapes when buttons are pressed. 2. It involves creating an Applet class that extends Applet and implements ActionListener, adding buttons to draw shapes, registering the buttons with ActionListener, and drawing different shapes in paint() based on the button pressed. 3. The shapes drawn are an oval and rectangle, with the button's action command checked in paint() to determine which shape to draw.

Uploaded by

vplvpl
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Applet

1. The document describes an algorithm to create a Java applet that draws different shapes when buttons are pressed. 2. It involves creating an Applet class that extends Applet and implements ActionListener, adding buttons to draw shapes, registering the buttons with ActionListener, and drawing different shapes in paint() based on the button pressed. 3. The shapes drawn are an oval and rectangle, with the button's action command checked in paint() to determine which shape to draw.

Uploaded by

vplvpl
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Aim: to create a Java Bean to draw various graphical shapes and display it using or without using BDK Algorithm:

1. Create a class Appletdemo which extends Applet superclass and which implements ActionListener interface 2. Create five buttons with the required captions and add them to the container 3. Register the buttons with the ActionListener interface 4. In the Actionperformed () method, with the help of the instance, perform the action respectively 5. In the paint() method, check which button is pressed and display the shapes accordingly
Program 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; public void init() { b1= new Button("Test"); b2=new Button("circle"); add(b1); add(b2); b1.addActionListener(this); b2.addActionListener(this); } public void actionPerformed(ActionEvent ae) {

s=ae.getActionCommand(); repaint(); } public void paint(Graphics g) { try { if(s.equals("Test")); g.drawOval(122,53,62,75); //g.setColor(212, 23,45); if(s.equals("circle")); g.drawRect(122,122,122,122); } catch(NullPointerException e) {} } }

You might also like