展开全部
那个本人初学java,还不知道java3d是什么啊!!!惭愧惭愧
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Circle extends Applet implements ItemListener
{
Checkbox red,black,green,yellow;
Color co;
String colorname[]={"红色","黑色","绿色","黄色"};
Color color[]={Color.red,Color.black,Color.green,Color.yellow};
public void init()
{
CheckboxGroup cg=new CheckboxGroup();
co=Color.red;
red=new Checkbox(colorname[0],cg,true);
red.addItemListener(this);
add(red);
black=new Checkbox(colorname[1],cg,false);
black.addItemListener(this);
add(black);
green=new Checkbox(colorname[2],cg,false);
green.addItemListener(this);
add(green);
yellow=new Checkbox(colorname[3],cg,false);
yellow.addItemListener(this);
add(yellow);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==red) co=Color.red;
if(e.getSource()==black) co=Color.black;
if(e.getSource()==green) co=Color.green;
if(e.getSource()==yellow) co=Color.yellow;
repaint();
}
public void paint(Graphics g)
{
int x=120,y=120,r=70;
g.setColor(co);
g.fillOval(x-r,y-r,2*r,2*r);
}
}
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Circle extends Applet implements ItemListener
{
Checkbox red,black,green,yellow;
Color co;
String colorname[]={"红色","黑色","绿色","黄色"};
Color color[]={Color.red,Color.black,Color.green,Color.yellow};
public void init()
{
CheckboxGroup cg=new CheckboxGroup();
co=Color.red;
red=new Checkbox(colorname[0],cg,true);
red.addItemListener(this);
add(red);
black=new Checkbox(colorname[1],cg,false);
black.addItemListener(this);
add(black);
green=new Checkbox(colorname[2],cg,false);
green.addItemListener(this);
add(green);
yellow=new Checkbox(colorname[3],cg,false);
yellow.addItemListener(this);
add(yellow);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==red) co=Color.red;
if(e.getSource()==black) co=Color.black;
if(e.getSource()==green) co=Color.green;
if(e.getSource()==yellow) co=Color.yellow;
repaint();
}
public void paint(Graphics g)
{
int x=120,y=120,r=70;
g.setColor(co);
g.fillOval(x-r,y-r,2*r,2*r);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询