代码是这样的:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class b1 extends JApplet implements ItemListener,ActionListener
{
int i1=0,i2=0,i3=0;
int fonti=10;
Font font;
Container ctp=getContentPane();
JLabel lb=new JLabel("请选择");
JCheckBox cb1,cb2,cb3;
JRadioButton r1,r2,r3;
ButtonGroup bg=new ButtonGroup();
public void init()
{
ctp.setLayout(new FlowLayout());
cb1=new JCheckBox("红色",false);
cb1.addItemListener(this);
ctp.add(cb1);
cb2=new JCheckBox("绿色",false);
cb2.addItemListener(this);
ctp.add(cb2);
cb3=new JCheckBox("蓝色",false);
cb3.addItemListener(this);
ctp.add(cb3);
r1=new JRadioButton("10");
r1.addActionListener(this);
ctp.add(r1);
r2=new JRadioButton("16");
r2.addActionListener(this);
ctp.add(r2);
r3=new JRadioButton("24");
r3.addActionListener(this);
ctp.add(r3);
bg.add(r1);
bg.add(r2);
bg.add(r3);
ctp.add(lb);
}
public void itemStateChange(ItemEvent e)
{
JCheckBox cbx=(JCheckBox)e.getItem();
if(cbx.getText()=="红色")
{
if(e.getStateChange()==e.SELECTED) i1=255;
else i1=0;
}
if(cbx.getText()=="绿色")
{
if(e.getStateChange()==e.SELECTED) i2=255;
else i2=0;
}
if(cbx.getText()=="蓝色")
{
if(cbx.isSelected()) i3=255;
else i3=0;
}
font=new Font("宋体",Font.BOLD,fonti);
lb.setFont(font);
lb.setForeground(new Color(i1,i2,i3));
}
public void actionPerformed(ActionEvent e)
{
String rbt=e.getActionCommand();
if(rbt=="10") fonti=10;
else if(rbt=="16") fonti=16;
else fonti=24;
font=new Font("宋体",Font.BOLD,fonti);
lb.setFont(font);
lb.setForeground(new Color(i1,i2,i3));
}
}以下是运行时出现的提示,帮忙看下为什么!
---------- javac ----------
E:\java\b1.java:4: b1 is not abstract and does not override abstract method itemStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener
public class b1 extends JApplet implements ItemListener,ActionListener
^
1 error输出完成(耗时 1秒)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class b1 extends JApplet implements ItemListener,ActionListener
{
int i1=0,i2=0,i3=0;
int fonti=10;
Font font;
Container ctp=getContentPane();
JLabel lb=new JLabel("请选择");
JCheckBox cb1,cb2,cb3;
JRadioButton r1,r2,r3;
ButtonGroup bg=new ButtonGroup();
public void init()
{
ctp.setLayout(new FlowLayout());
cb1=new JCheckBox("红色",false);
cb1.addItemListener(this);
ctp.add(cb1);
cb2=new JCheckBox("绿色",false);
cb2.addItemListener(this);
ctp.add(cb2);
cb3=new JCheckBox("蓝色",false);
cb3.addItemListener(this);
ctp.add(cb3);
r1=new JRadioButton("10");
r1.addActionListener(this);
ctp.add(r1);
r2=new JRadioButton("16");
r2.addActionListener(this);
ctp.add(r2);
r3=new JRadioButton("24");
r3.addActionListener(this);
ctp.add(r3);
bg.add(r1);
bg.add(r2);
bg.add(r3);
ctp.add(lb);
}
public void itemStateChange(ItemEvent e)
{
JCheckBox cbx=(JCheckBox)e.getItem();
if(cbx.getText()=="红色")
{
if(e.getStateChange()==e.SELECTED) i1=255;
else i1=0;
}
if(cbx.getText()=="绿色")
{
if(e.getStateChange()==e.SELECTED) i2=255;
else i2=0;
}
if(cbx.getText()=="蓝色")
{
if(cbx.isSelected()) i3=255;
else i3=0;
}
font=new Font("宋体",Font.BOLD,fonti);
lb.setFont(font);
lb.setForeground(new Color(i1,i2,i3));
}
public void actionPerformed(ActionEvent e)
{
String rbt=e.getActionCommand();
if(rbt=="10") fonti=10;
else if(rbt=="16") fonti=16;
else fonti=24;
font=new Font("宋体",Font.BOLD,fonti);
lb.setFont(font);
lb.setForeground(new Color(i1,i2,i3));
}
}以下是运行时出现的提示,帮忙看下为什么!
---------- javac ----------
E:\java\b1.java:4: b1 is not abstract and does not override abstract method itemStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener
public class b1 extends JApplet implements ItemListener,ActionListener
^
1 error输出完成(耗时 1秒)
解决方案 »
- 求高手啊,
- Web服务器如何接受用户请求
- 遍历hashMap出现java.util.concurrentmodificationexception异常
- 关于str!=null和null!=str的思考
- 谁能解释一下java io里的字节流和字符流究竟有什么具体的区别
- 如何显示view ——eclipse rcp
- Tomcat5.5的配置问题
- jtree中怎样屏蔽掉F2键的编辑功能
- jdk问题
- spring怎么实现不重启tomcat切换数据库连接?
- 在JSP中,向数据库插入记录,values后用具体的值插入成功,用变量就不行,为什么呢?
- s.length()和s.length???????为什么一个加()一个不加????????
public void itemStateChange(ItemEvent e)
改为:
public void itemStateChanged(ItemEvent e)
就行了。