📄 checkboxes.java
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Checkboxes extends JFrame implements ItemListener
{
CheckboxAdapter checks[];
JTextField text;
public Checkboxes()
{
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
checks = new CheckboxAdapter[4];
for(int loopIndex = 0; loopIndex
<= checks.length - 1; loopIndex++){
checks[loopIndex] = new CheckboxAdapter("Check " +
loopIndex);
checks[loopIndex].addItemListener(this);
contentPane.add(checks[loopIndex]);
}
text = new JTextField(30);
contentPane.add(text);
}
public void itemStateChanged(ItemEvent e)
{
String outString = new String("Selected: ");
for(int loopIndex = 0; loopIndex
<= checks.length - 1; loopIndex++){
if(checks[loopIndex].isSelected()) {
outString += " checkbox " + loopIndex;
}
}
text.setText(outString);
}
public static void main(String args[])
{
final Checkboxes f = new Checkboxes();
f.setBounds(100, 100, 400, 300);
f.setVisible(true);
f.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -