简介
简单
code
/*
* @Author: your name
* @Date: 2020-11-04 10:19:14
* @LastEditTime: 2020-11-04 10:28:50
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /java/calcu/RadioButtonFrame.java
*/
package calcu;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RadioButtonFrame extends JFrame {
private JPanel buttonPanel;
private ButtonGroup group;
private JLabel label;
private static final int DEFAULT_SIZE = 36;
public static void main(String[] args) {
RadioButtonFrame t = new RadioButtonFrame();
t.setTitle("ImageTest");
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t.setVisible(true);
}
public RadioButtonFrame() {
label = new JLabel("The quick brown fox jumps over the lazy dog.");
label.setFont(new Font("Serif", Font.PLAIN, DEFAULT_SIZE));
add(label, BorderLayout.CENTER);
// add the radio buttons
buttonPanel = new JPanel();
group = new ButtonGroup();
addRadioButton("Small", 8);
addRadioButton("Medium", 12);
addRadioButton("Large", 18);
addRadioButton("Extra large", 36);
add(buttonPanel, BorderLayout.SOUTH);
pack();
}
public void addRadioButton(String name, int size) {
boolean selected = size == DEFAULT_SIZE;
JRadioButton button = new JRadioButton(name, selected);
group.add(button);
buttonPanel.add(button);
// this listener sets the label font size
ActionListener listener = event -> label.setFont(new Font("Serif", Font.PLAIN, size));
button.addActionListener(listener);
}
}
---------------------------我的天空里没有太阳,总是黑夜,但并不暗,因为有东西代替了太阳。虽然没有太阳那么明亮,但对我来说已经足够。凭借着这份光,我便能把黑夜当成白天。我从来就没有太阳,所以不怕失去。
--------《白夜行》