JAVA:GirdLayout 无法解析为类型,TitleBorder 无法解析为类型

千夜怪盗 2014-10-25 03:12:40
源程序如下
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.BorderLayout;

public class TestJCheckBox extends JFrame{
private Icon[] icons = {new ImageIcon("images/bird.gif"),
new ImageIcon("images/cat.gif"), new ImageIcon("images/dog.gif"),
new ImageIcon("images/pig.gif"), new ImageIcon("images/rabbit.gif")
};
private JRadioButton[] radioButton = {new JRadioButton("鸟",true),//一开始设定单选按钮选中"鸟"
new JRadioButton("猫",false), new JRadioButton("狗",false),
new JRadioButton("猪",false), new JRadioButton("兔",false)
};
private ButtonGroup buttonGroup = new ButtonGroup();
private JLabel imgLabel = new JLabel(icons[0]);

public TestJCheckBox() {
JPanel westPanel = new JPanel();
westPanel.setLayout(new GirdLayout(5,1)); //这里错了
westPanel.setBorder(new TitleBorder("选择"));//创建并设置标题边框 //这里错了
ItemListener listener = new ItemListener() {
public void itemStateChanged(ItemEvent e) {
int n = 0;
JRadioButton sourceRadioButton = (JRadioButton)e.getSource();
String text = sourceRadioButton.getText();
for( int index = 0; index < radioButton.length; index ++ ) {
if( text.equals(radioButton[index].getText()) ) {
n = index;
break;
}
}
imgLabel.setIcon(icons[n]);
}
};
for( int index = 0; index < radioButton.length; index ++ ) {
radioButton[index].addItemListener(listener);
buttonGroup.add(radioButton[index]);
westPanel.add(radioButton[index]);
}

setLayout(new BorderLayout());
add(imgLabel,BorderLayout.CENTER);
add(westPanel,BorderLayout.WEST);
}

public static void main(String[] args) {
TestJCheckBox frame = new TestJCheckBox();
frame.setTitle("测试JRadioButton");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}

}
...全文
223 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

58,454

社区成员

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

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