| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 671 人关注过本帖
标题:指点一下
取消只看楼主 加入收藏
biancku
Rank: 2
等 级:论坛游民
帖 子:41
专家分:19
注 册:2010-11-30
结帖率:64.71%
收藏
已结贴  问题点数:4 回复次数:0 
指点一下
下面代码  为什么我运行后点击Button键后,不能实现所需要的结果,而是出现错误?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class demo1  implements ItemListener{
    JLabel jlabselected;
    JLabel jlabchange;
    JCheckBox jcbAlpha;
    JCheckBox jcbBeta;
    JCheckBox jcbGamma;
    demo1(){
        JFrame jfrm=new JFrame("Java checkBox demo1");
        jfrm.setLayout(new FlowLayout());
        jfrm.setSize(280, 120);
        jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jlabselected=new JLabel("");
        jlabchange=new JLabel("");
        
        jcbAlpha=new JCheckBox("Alpha");
        jcbBeta=new JCheckBox("Beta");
        jcbGamma=new JCheckBox("Gamma");
        
        jcbAlpha.addItemListener(this);
        jcbBeta.addItemListener(this);
        jcbGamma.addItemListener(this);
        
        jfrm.add(jcbAlpha);
        jfrm.add(jcbBeta);
        jfrm.add(jcbGamma);
        jfrm.add(jlabchange);
        jfrm.add(jlabselected);   
        jfrm.setVisible(true);
    }
    public void itemStateChange(ItemEvent  ie){
        String str="";
        JCheckBox cb=(JCheckBox)ie.getItem();
        if(cb.isSelected())
            jlabchange.setText(cb.getText());
        else
            jlabchange.setText(cb.getText()+" was just cleared.");
        if(jcbAlpha.isSelected())
            str+="Alpha ";
        if(jcbBeta.isSelected())
            str+="Beta ";
        if(jcbGamma.isSelected())
            str+="Gamma ";
        jlabselected.setText("select checkbox: "+str);
    }
    public static void main(String[] args){
        new demo1();
    }
   
}
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
    The type demo1 must implement the inherited abstract method ItemListener.itemStateChanged(ItemEvent)

    at demo1.itemStateChanged(demo1.java:5)
    at javax.swing.AbstractButton.fireItemStateChanged(Unknown Source)
    at javax.swing.AbstractButton$Handler.itemStateChanged(Unknown Source)
    at javax.swing.DefaultButtonModel.fireItemStateChanged(Unknown Source)
    at javax.swing.JToggleButton$ToggleButtonModel.setSelected(Unknown Source)
    at javax.swing.JToggleButton$ToggleButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)



































搜索更多相关主题的帖子: class Java import 
2011-08-20 11:10
快速回复:指点一下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031482 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved