java radio_java radioButton
簡介
簡單
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);
}
}
總結
以上是生活随笔為你收集整理的java radio_java radioButton的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: imf瞬时频率跳变问题
- 下一篇: 北京电子科技学院计算机怎么样,北京电子科