Java program to implement a shape selector from a given set of shapes

To implement a shape selector from a given set of shapes

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
 
public class shape extend Applet implements itemListener
{
	Chekbox reet,circle,line;
	ChekboxGroup cbg;
 
	String msg;
	String s1="reet";
	String s2="circle";
	string s3="line";
	publice void init()
	{
		cbg=new checkboxGroup();
 
		rect = new checkbox("reet,cbg,tru);
		circle = new Checkbox("circle",cbg.false);
		line = new Checkbox("line",cbg,false);
 
		add(reet);
		add(circle);
		add(line);
 
		rect.addItemListener(this);
		circle.addItemLisener(this);
		line.addItemListener(this);	
	}
	public void item StateChanged(ItemEvent ie)
	{
		repaint();
	}
	publice void paint(Graphics g)
	{
		msg=cbg.getSlectedCheckbox().getLabel();
		if(masg.compareTo(s1)==0)
		{
			g.drawRect(10,40,40,80);
		}
		else if(msg.compareTo(s2)==0)
		{
			g.drawOvel(10,40,80,80);
		}
		else
		{
			g.drawLine(0,0,100,100);
		}
	}
}
Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

5 thoughts on “Java program to implement a shape selector from a given set of shapes

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

    public class shape extends Applet implements itemListener
    {
    Chekbox rect,circle,line;
    ChekboxGroup cbg;

    String msg;
    String s1=”rect”;
    String s2=”circle”;
    string s3=”line”;
    public void init()
    {
    cbg=new checkboxGroup();

    rect = new checkbox(“rect”,cbg,true);
    circle = new Checkbox(“circle”,cbg,false);
    line = new Checkbox(“line”,cbg,false);

    add(rect);
    add(circle);
    add(line);

    rect.addItemListener(this);
    circle.addItemLisener(this);
    line.addItemListener(this);
    }
    public void item StateChanged(ItemEvent ie)
    {
    repaint();
    }
    public void paint(Graphics g)
    {
    msg=cbg.getSelctedCheckbox().getLabel();
    if(msg.compareTo(s1)==0)
    {
    g.drawRect(10,40,40,80);
    }
    else if(msg.compareTo(s2)==0)
    {
    g.drawOvel(10,40,80,80);
    }
    else
    {
    g.drawLine(0,0,100,100);
    }
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in