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);
}
}
} |
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
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.
It is throwing error please correct it
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);
}
}
}
Thankx Machu…Don’t repeat it again……..