jradiobuttondemo.java
来自「ssd3的教程 是我们老师给我们的 纯英文 有兴趣的可以」· Java 代码 · 共 63 行
JAVA
63 行
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 + =
减小字号Ctrl + -
显示快捷键?