简介
checkbox
code
/*
* @Author: your name
* @Date: 2020-11-04 09:44:08
* @LastEditTime: 2020-11-04 09:53:07
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: /java/calcu/CheckBoxTest.java
*/
package calcu;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CheckBoxTest extends JFrame {
private JLabel label;
private JCheckBox bold;
private JCheckBox italic;
private static final int FONTSIZE = 24;
public static void main(String[] args){
CheckBoxTest t = new CheckBoxTest();
t.setTitle("ImageTest");
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t.setVisible(true);
}
public CheckBoxTest() {
// add the sample text label
label = new JLabel("The quick brown fox jumps over the lazy dog.");
label.setFont(new Font("Serif", Font.BOLD, FONTSIZE));
add(label, BorderLayout.CENTER);
// this listener sets the font attribute of
// the label to the checkbox state
ActionListener listener = event -> {
int mode = 0;
if (bold.isSelected())
mode += Font.BOLD;
if (italic.isSelected())
mode += Font.ITALIC;
label.setFont(new Font("Serif", mode, FONTSIZE));
};
// add the check boxes
JPanel buttonPanel = new JPanel();
bold = new JCheckBox("Bold");
bold.addActionListener(listener);
bold.setSelected(true);
buttonPanel.add(bold);
italic = new JCheckBox("Italic");
italic.addActionListener(listener);
buttonPanel.add(italic);
add(buttonPanel, BorderLayout.SOUTH);
pack();
}
}
Q&A
简单
---------------------------我的天空里没有太阳,总是黑夜,但并不暗,因为有东西代替了太阳。虽然没有太阳那么明亮,但对我来说已经足够。凭借着这份光,我便能把黑夜当成白天。我从来就没有太阳,所以不怕失去。
--------《白夜行》