⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demojcheckradioframe.java

📁 精通NetBeans光盘源代码,很好很好的资料
💻 JAVA
字号:
/*
 * DemoJCheckRadioFrame.java
 *
 * Created on 2006年3月17日, 下午9:59
 */

package org.netbeans.swing.container;

/**
 *
 * @author  boyingking
 */
public class DemoJCheckRadioFrame extends javax.swing.JFrame {
    
    /** Creates new form DemoJCheckRadioFrame */
    public DemoJCheckRadioFrame() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        buttonGroupOne = new javax.swing.ButtonGroup();
        jCheckBoxBold = new javax.swing.JCheckBox();
        jCheckBoxItalic = new javax.swing.JCheckBox();
        jRadioButtonSmall = new javax.swing.JRadioButton();
        jRadioButtonCommon = new javax.swing.JRadioButton();
        jRadioButtonBig = new javax.swing.JRadioButton();
        jLabelMessage = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("JCheckBox\u4e0eJRadioButton\u5e94\u7528\u793a\u4f8b");
        jCheckBoxBold.setText("\u9ed1\u4f53");
        jCheckBoxBold.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxBold.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jCheckBoxBold.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCheckBoxBoldItemStateChanged(evt);
            }
        });

        jCheckBoxItalic.setText("\u659c\u4f53");
        jCheckBoxItalic.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxItalic.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jCheckBoxItalic.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCheckBoxItalicItemStateChanged(evt);
            }
        });

        buttonGroupOne.add(jRadioButtonSmall);
        jRadioButtonSmall.setText("\u7f29\u5c0f");
        jRadioButtonSmall.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jRadioButtonSmall.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jRadioButtonSmall.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButtonSmallItemStateChanged(evt);
            }
        });

        buttonGroupOne.add(jRadioButtonCommon);
        jRadioButtonCommon.setSelected(true);
        jRadioButtonCommon.setText("\u666e\u901a");
        jRadioButtonCommon.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jRadioButtonCommon.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jRadioButtonCommon.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButtonCommonItemStateChanged(evt);
            }
        });

        buttonGroupOne.add(jRadioButtonBig);
        jRadioButtonBig.setText("\u52a0\u5927");
        jRadioButtonBig.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jRadioButtonBig.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jRadioButtonBig.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButtonBigItemStateChanged(evt);
            }
        });

        jLabelMessage.setFont(new java.awt.Font("宋体", 0, 18));
        jLabelMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelMessage.setText("JCheckBox\u4e0eJRadioButton");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jCheckBoxBold)
                    .add(jCheckBoxItalic))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(39, 39, 39)
                        .add(jRadioButtonSmall)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 65, Short.MAX_VALUE)
                        .add(jRadioButtonCommon)
                        .add(59, 59, 59)
                        .add(jRadioButtonBig)
                        .add(63, 63, 63))
                    .add(layout.createSequentialGroup()
                        .add(15, 15, 15)
                        .add(jLabelMessage, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(43, 43, 43)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jCheckBoxBold)
                        .add(43, 43, 43)
                        .add(jCheckBoxItalic))
                    .add(jLabelMessage, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(37, 37, 37)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jRadioButtonBig)
                    .add(jRadioButtonSmall)
                    .add(jRadioButtonCommon))
                .addContainerGap(32, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButtonBigItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButtonBigItemStateChanged
// TODO add your handling code here:
            this.setFontSize(22);
            this.setLableFont();
    }//GEN-LAST:event_jRadioButtonBigItemStateChanged

    private void jRadioButtonCommonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButtonCommonItemStateChanged
// TODO add your handling code here:
            this.setFontSize(18);
            this.setLableFont();
    }//GEN-LAST:event_jRadioButtonCommonItemStateChanged

    private void jRadioButtonSmallItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButtonSmallItemStateChanged
// TODO add your handling code here:
            this.setFontSize(14);
            this.setLableFont();
    }//GEN-LAST:event_jRadioButtonSmallItemStateChanged

    private void jCheckBoxItalicItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBoxItalicItemStateChanged
// TODO add your handling code here:
        if(this.jCheckBoxItalic.isSelected())
        {
            this.setStyle(java.awt.Font.ITALIC);
        }
        else
        {
            this.setStyle(-java.awt.Font.ITALIC);
        }
         this.setLableFont();            
    }//GEN-LAST:event_jCheckBoxItalicItemStateChanged

    private void jCheckBoxBoldItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBoxBoldItemStateChanged
// TODO add your handling code here:
        if(this.jCheckBoxBold.isSelected())
        {
            this.setStyle(java.awt.Font.BOLD);
        }
        else
        {
            this.setStyle(-java.awt.Font.BOLD);
        }    
        this.setLableFont();
    }//GEN-LAST:event_jCheckBoxBoldItemStateChanged
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DemoJCheckRadioFrame().setVisible(true);
            }
        });
    }

    private int style = java.awt.Font.PLAIN;
    private void setStyle(int style) {
        this.style=this.style+style;
    }

    private int getStyle() {
        return this.style; 
    }
    private void setFontSize(int fontSize) {   
        this.fontSize=fontSize; 
    }

    private int getFontSize() {     
        return this.fontSize;
    }
   private void setLableFont()
   {
       this.jLabelMessage.setFont(new java.awt.Font("宋体",this.getStyle(),this.getFontSize()));
   }

    private int fontSize = 18;
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupOne;
    private javax.swing.JCheckBox jCheckBoxBold;
    private javax.swing.JCheckBox jCheckBoxItalic;
    private javax.swing.JLabel jLabelMessage;
    private javax.swing.JRadioButton jRadioButtonBig;
    private javax.swing.JRadioButton jRadioButtonCommon;
    private javax.swing.JRadioButton jRadioButtonSmall;
    // End of variables declaration//GEN-END:variables
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -