Java API 分類導覽 - javax.swing.JRadioButton

JRadioButton 類別 (class) 為 Swing 中可被點選的選項元件,通常作為單選按鈕。



修飾子
public class JRadioButton


父類別
javax.swing.JToggleButton


實作介面
Accessible


建構子
public JRadioButton()
public JRadioButton(Icon icon)
public JRadioButton(Action a)
public JRadioButton(Icon icon, boolean selected)
public JRadioButton(String text)
public JRadioButton(String text, boolean selected)
public JRadioButton(String text, Icon icon)
public JRadioButton(String text, Icon icon, boolean selected)


舉例如下
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class JToggleButtonDemo {
    public static void main(String[] args) {
        JFrame frame = new JFrame("SwingDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        JToggleButton button1 = new JToggleButton("b1");
        JToggleButton button2 = new JToggleButton("b2");
        JCheckBox button3 = new JCheckBox("b3");
        JCheckBox button4 = new JCheckBox("b4");
        JRadioButton button5 = new JRadioButton("b5");
        JRadioButton button6 = new JRadioButton("b6");
        
        frame.setLayout(new FlowLayout());
        frame.add(button1);
        frame.add(button2);
        frame.add(button3);
        frame.add(button4);
        frame.add(button5);
        frame.add(button6);
        
        frame.pack();
        frame.setVisible(true);
    }
}

/* 《程式語言教學誌》的範例程式
    http://pydoing.blogspot.com/
    檔名:JToggleButtonDemo.java
    功能:示範 Java 程式 
    作者:張凱慶
    時間:西元 2012 年 9 月 */


此例建立兩個 JToggleButton 按鈕,另外各兩個繼承 JToggleButton 的 JCheckBox 與 JRadioButton
JToggleButton button1 = new JToggleButton("b1");
JToggleButton button2 = new JToggleButton("b2");
JCheckBox button3 = new JCheckBox("b3");
JCheckBox button4 = new JCheckBox("b4");
JRadioButton button5 = new JRadioButton("b5");
JRadioButton button6 = new JRadioButton("b6");


編譯後執行,結果如下



由於沒有設定 ButtonGroup 將按鈕分組,因此每個按鈕都可被選取。


中英文術語對照
類別class


您可以繼續參考
Swing 元件
  • ButtonGroup
  • JComponent
    • AbstractButton
      • JButton
      • JToggleButton
        • JCheckBox
        • JRadioButton
      • JMenuItem
        • JCheckBoxMenuItem
        • JMenu
        • JRadioButtonMenuItem
    • JColorChooser
    • JComboBox
    • JFileChooser
    • JInternalFrame
    • JLabel
    • JLayeredPane
      • JDesktopPane
    • JList
    • JMenuBar
    • JOptionPane
    • JPanel
    • JPopupMenu
    • JProgressBar
    • JRootPane
    • JScrollBar
    • JScrollPane
    • JSeparator
    • JSlider
    • JSpinner
    • JSplitPane
    • JTabbedPane
    • JTable
    • text.JTextComponent
      • JEditorPane
        • JTextPane
      • JTextField
        • JFormattedTextField
        • JPasswordField
      • JTextArea
    • JToolBar
    • JToolTip
    • JTree
    • JViewport
  • JDialog
  • JFrame
  • JWindow


相關目錄
Java API 分類導覽
Java 教材
首頁


參考資料
http://docs.oracle.com/javase/6/docs/api/javax/swing/JRadioButton.html

沒有留言: