• java checkbox


    简介

    checkbox

    code

    /*
     * @Author: your name
     * @Date: 2020-11-04 09:44:08
     * @LastEditTime: 2020-11-04 09:53:07
     * @LastEditors: your name
     * @Description: In User Settings Edit
     * @FilePath: /java/calcu/CheckBoxTest.java
     */
    package calcu;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    
    public class CheckBoxTest extends JFrame {
        private JLabel label;
        private JCheckBox bold;
        private JCheckBox italic;
        private static final int FONTSIZE = 24;
        public static void main(String[] args){
            CheckBoxTest t = new CheckBoxTest();
            t.setTitle("ImageTest");
            t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            t.setVisible(true);
        }
        public CheckBoxTest() {
            // add the sample text label
    
            label = new JLabel("The quick brown fox jumps over the lazy dog.");
            label.setFont(new Font("Serif", Font.BOLD, FONTSIZE));
            add(label, BorderLayout.CENTER);
    
            // this listener sets the font attribute of
            // the label to the checkbox state
    
            ActionListener listener = event -> {
                int mode = 0;
                if (bold.isSelected())
                    mode += Font.BOLD;
                if (italic.isSelected())
                    mode += Font.ITALIC;
                label.setFont(new Font("Serif", mode, FONTSIZE));
            };
            // add the check boxes
            JPanel buttonPanel = new JPanel();
    
            bold = new JCheckBox("Bold");
            bold.addActionListener(listener);
            bold.setSelected(true);
            buttonPanel.add(bold);
    
            italic = new JCheckBox("Italic");
            italic.addActionListener(listener);
    
            buttonPanel.add(italic);
    
            add(buttonPanel, BorderLayout.SOUTH);
            pack();
        }
    }
    
    

    Q&A

    简单

    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    DEV勾选框按钮呈现
    C#事务
    C#调用python脚本
    centos 磁盘满
    PostgreSQL库表字段信息
    Nginx Configuration for windows
    .NET Core 6.0之读取配置文件
    WinUI迁移到即将"过时"的.NET MAUI个人体验
    客户案例Husqvarna AB
    客户案例SES S.A.
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/13924394.html
Copyright © 2020-2023  润新知