JAVA SWING 问题

xingaofeng 2010-03-10 09:48:02
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class J_Button extends JFrame implements ItemListener,ActionListener{


private JLabel [] label={new JLabel("label:"), new JLabel("Left-One"), new JLabel("Right-Two"),
new JLabel("Button:"),
new JLabel("CheckBox:"),
new JLabel("RadioButton:")};
private JButton [] button={new JButton("One"),new JButton("Two")};
private JCheckBox [] checkbox={new JCheckBox("Left"),new JCheckBox("Right")};
private JRadioButton [] radiobutton={new JRadioButton("One"),new JRadioButton("Two")};
public J_Button( )
{
super("example of J_Button");
Container container=getContentPane();
container.setLayout(new FlowLayout(FlowLayout.LEFT));
container.add(label[0]);
container.add(label[1]);
container.add(label[2]);


container.add(label[3]);
container.add(button[0]);
container.add(button[1]);

container.add(label[4]);
container.add(checkbox[0]);
container.add(checkbox[1]);

container.add(label[5]);
container.add(radiobutton[0]);
container.add(radiobutton[1]);

ButtonGroup radioGroup=new ButtonGroup();
radioGroup.add(radiobutton[0]);
radioGroup.add(radiobutton[1]);

checkbox[0].setSelected(true);
checkbox[1].setSelected(true);
radiobutton[0].setSelected(true);
radiobutton[1].setSelected(false);

button[0].addActionListener(this);
button[0].addActionListener(this);
checkbox[0].addItemListener(this);
checkbox[1].addItemListener(this);
radiobutton[0].addItemListener(this);
radiobutton[1].addItemListener(this);

public void actionPerformed(ActionEvent event)
{
if(event.getSource()==button[0])
label[1].setEnabled(true);

}




setSize(200,150);
setVisible(true);




}


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
J_Button app=new J_Button();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


}

}

哪里错了


报错如下
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type J_Button must implement the inherited abstract method ItemListener.itemStateChanged(ItemEvent)
The type J_Button must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
void is an invalid type for the variable actionPerformed
Syntax error on token "(", ; expected
Syntax error on token ")", ; expected

at J_Button.<init>(J_Button.java:4)
at J_Button.main(J_Button.java:76)
...全文
123 6 打赏 收藏 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
孤独剑客 2010-03-11
  • 打赏
  • 举报
回复
赶紧把帖子结掉哈
xingaofeng 2010-03-11
  • 打赏
  • 举报
回复
谢谢大家的指点。我是还是个学生,会好好努力滴。
chenliuyang 2010-03-11
  • 打赏
  • 举报
回复
eclipse给你报错了哦
XOOX1001 2010-03-10
  • 打赏
  • 举报
回复
楼上说的好,函数里不能再定义函数。
liuzch 2010-03-10
  • 打赏
  • 举报
回复
1、没有实现ItemListener中的itemStateChanged(ItemEvent e)方法;
2、企图实现ActionListener中的actionPerformed(ActionEvent e)方法,但是位置却放在构造方法内。
所以肯定就报错了!
自我感觉你代码写的很乱!
bayougeng 2010-03-10
  • 打赏
  • 举报
回复
你的程序编译通过了么?

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧