Electrofriends

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

by Ranjith | April 4th, 2010.

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);
		}
	}
}

Share and Enjoy:
  • Digg
  • Technorati
  • StumbleUpon
  • Twitter
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • Mixx
  • Yahoo! Buzz
  • LinkedIn
  • NewsVine
  • RSS
  • email
Similar Posts:

Leave a Reply

Share and enjoy

    • Digg
    • Facebook
    • Technorati
    • StumbleUpon
    • Twitter
    • Reddit
    • del.icio.us
    • Yahoo! Buzz
Copyright©2009 www.electrofriends.com All Rights Reserved. Powered by Dhyeya