📄 checkboxdemo.java
字号:
// CheckBoxDemo.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class CheckBoxDemo extends JFrame implements ActionListener
{
CheckBoxDemo (String title)
{
super (title);
addWindowListener (new WindowAdapter ()
{
public void windowClosing (WindowEvent e)
{
System.exit (0);
}
});
ButtonGroup bg = new ButtonGroup ();
JCheckBox north = new JCheckBox ("North");
north.setMnemonic ('o');
north.addActionListener (this);
bg.add (north);
getContentPane ().add (north, BorderLayout.NORTH);
JCheckBox west = new JCheckBox ("West", true);
west.addActionListener (this);
bg.add (west);
getContentPane ().add (west, BorderLayout.WEST);
JCheckBox center = new JCheckBox ("Center");
center.addActionListener (this);
// bg.add (center);
getContentPane ().add (center, BorderLayout.CENTER);
JCheckBox east = new JCheckBox ("East");
east.addActionListener (this);
bg.add (east);
getContentPane ().add (east, BorderLayout.EAST);
JCheckBox south = new JCheckBox ("South",
new ImageIcon ("bullet.gif"));
south.addActionListener (this);
bg.add (south);
getContentPane ().add (south, BorderLayout.SOUTH);
pack ();
setVisible (true);
}
public void actionPerformed (ActionEvent e)
{
System.out.println (e.getActionCommand ());
}
public static void main (String [] args)
{
new CheckBoxDemo ("CheckBox Demo");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -