📄 jradiobuttondemo.java
字号:
import java.awt.*;
import javax.swing.*;
/**
* Demonstrates the component {@link JRadioButton}. This class extends
* class {@link @JPanel}.
*
* @author author name
* @version 1.0.0
*/
public class JRadioButtonDemo extends JPanel {
private JRadioButton buttonOne;
private JRadioButton buttonTwo;
private JRadioButton buttonThree;
/**
* Creates a window.
*
* @param args not used.
*/
public static void main(String[] args) {
JFrame frame = new JFrame("JRadioButtonDemo");
frame.setContentPane(new JRadioButtonDemo());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack(); // Adjust the size of the window
frame.setVisible(true);
}
/**
* Creates three {@link JRadioButton} components.
*/
public JRadioButtonDemo() {
setLayout(new GridLayout(1, 3));
setBackground(Color.white);
// Create the radio buttons
buttonOne = new JRadioButton("One", true);
buttonTwo = new JRadioButton("Two");
buttonThree = new JRadioButton("Three");
// Group the radio buttons
ButtonGroup group = new ButtonGroup();
group.add(buttonOne);
group.add(buttonTwo);
group.add(buttonThree);
// Change the radio buttons colors
buttonOne.setBackground(Color.white);
buttonTwo.setBackground(Color.white);
buttonThree.setBackground(Color.white);
// Add radio buttons to the container
add(buttonOne);
add(buttonTwo);
add(buttonThree);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -