• 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);
        }
    }
    
    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    Cygwin配置总结
    javap 指令集
    超好用的Vim配置
    超过 130 个你需要了解的 vim 命令
    21、面向对象
    20、MySQLdb
    深入java字符串原理及其效率分析
    数据库执行计划
    SQL中EXISTS的用法
    mybatis之foreach用法
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/13924596.html
Copyright © 2020-2023  润新知