| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 848 人关注过本帖
标题:[求助]这是什么意思!?
取消只看楼主 加入收藏
ada518618
Rank: 1
等 级:新手上路
帖 子:184
专家分:0
注 册:2006-3-27
收藏
 问题点数:0 回复次数:1 
[求助]这是什么意思!?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JCheckBoxDemo extends JFrame
{
JCheckBox chinButton;
JCheckBox glassesButton;
JCheckBox hairButton;
JCheckBox teethButton;
StringBuffer choices;
JLabel wordLabel;
public JCheckBoxDemo()
{
chinButton = new JCheckBox("Chin");
chinButton.setMnemonic(KeyEvent.VK_C);
chinButton.setSelected(true);
glassesButton = new JCheckBox("Glasses");
glassesButton.setMnemonic(KeyEvent.VK_G);
glassesButton.setSelected(true);
hairButton = new JCheckBox("Hair");
hairButton.setMnemonic(KeyEvent.VK_H);
hairButton.setSelected(true);
teethButton =new JCheckBox("Teeth");
teethButton.setMnemonic(KeyEvent.VK_T);
teethButton.setSelected(true);
CheckBoxListener myListener=new CheckBoxListener();
chinButton.addItemListener(myListener);
glassesButton.addItemListener(myListener);
hairButton.addItemListener(myListener);
teethButton.addItemListener(myListener);
choices = new StringBuffer("cght");
wordLabel = new JLabel(new ImageIcon("images/geek-"+choices.toString()+".gif"));
wordLabel.setToolTipText(choices.toString());
JPanel checkPanel = new JPanel();
checkPanel.setLayout(new GridLayout(0,1));
checkPanel.add(chinButton);
checkPanel.add(glassesButton);
checkPanel.add(hairButton);
checkPanel.add(teethButton);
setLayout(new BorderLayout());
add(checkPanel,BorderLayout.WEST);
add(wordLabel,BorderLayout.CENTER);
checkPanel.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
}
class CheckBoxListener implements ItemListener
{
public void itemStateChanged(ItemEvent e)
{
int index = 0; char c ='_';
Object source =e.getItemSelectable();
if(source==chinButton)
{
index=0; c ='c';
}else if(source==glassesButton)
{
index=1; c='g';
}else if (source==hairButton)
{
index=2; c='h';
}else if (source==teethButton)
{
index=3;c='t';
}
if (e.getStateChange()==ItemEvent.DESELECTED)
c='_';
choices.setCharAt(index ,c);
wordLabel.setText(choices.toString());
}
}
public static void main(String s[])
{
JFrame frame=new JFrame("CheckBoxDemo");
frame.setContentPane(new JCheckBoxDemo());
frame.pack();
frame.setVisible(true);
}
}
我编译了没问题,可是运行却有这样的提示:
Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.addImpl(Container.java:1010)
at javax.swing.JLayeredPane.addImpl(JLayeredPane.java:204)
at java.awt.Container.add(Container.java:899)
at javax.swing.JRootPane.setContentPane(JRootPane.java:562)
at javax.swing.JFrame.setContentPane(JFrame.java:609)
at JCheckBoxDemo.main(JCheckBoxDemo.java:74)

蓝色的意思是不是说:“把窗口加入一个容器”吗!?
可是要怎么加我不知道!麻烦大家给我解说一下可以吗!?加在那里给我标明一下!麻烦了!

搜索更多相关主题的帖子: class public import 
2006-04-29 01:50
ada518618
Rank: 1
等 级:新手上路
帖 子:184
专家分:0
注 册:2006-3-27
收藏
得分:0 

恩!知道了!


Eclipse!尽管我现在不懂祢,可是我却对你情有独钟……
2006-04-30 15:03
快速回复:[求助]这是什么意思!?
数据加载中...
 
   



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

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