?? checkboxexample.java
字號(hào):
//CheckBoxExample.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class CheckBoxExample
{
public static void main(String[] args)
{
CheckBoxFrame frame = new CheckBoxFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class CheckBoxFrame extends JFrame
{
public CheckBoxFrame()
{
setTitle("CheckBoxExample");
setSize(WIDTH, HEIGHT);
Container contentPane = getContentPane();
//新建標(biāo)簽
myLabel = new JLabel(checkedLabel, JLabel.CENTER);
myLabel.setFont(new Font("Serif", Font.PLAIN, 12));
contentPane.add(myLabel, BorderLayout.CENTER);
//建立容器面板
checkPanel = new JPanel();
//新建復(fù)選框
boldCheck = new JCheckBox("Bold");
//增加事件監(jiān)聽器
boldCheck.addActionListener(new checkListener());
italicCheck = new JCheckBox("Italic");
italicCheck.addActionListener(new checkListener());
checkPanel.add(boldCheck);
checkPanel.add(italicCheck);
contentPane.add(checkPanel, BorderLayout.SOUTH);
}
//兩個(gè)復(fù)選框共用的事件監(jiān)聽器
private class checkListener
implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
int fontStyle = 0;
//判斷復(fù)選框是否被選取
if(boldCheck.isSelected())
fontStyle += Font.BOLD;
if(italicCheck.isSelected())
fontStyle += Font.ITALIC;
myLabel.setFont(new Font("Serif", fontStyle , 12));
}
}
public static final int WIDTH = 200;
public static final int HEIGHT = 140;
public static final String checkedLabel="You choosed: ";
private JLabel myLabel;
private JCheckBox boldCheck;
private JCheckBox italicCheck;
private JPanel checkPanel;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -