当前位置:网站首页 > Java基础 > 正文

java应用开发教程



/*

  • Created by JFormDesigner on Tue Dec 28 15:24:42 CST 2021 */

package cn.huanzi.qch.view;

import java.awt.; import java.awt.event.; import javax.swing.*;

/

  • 测试 */ public class TestFrame extends javax.swing.JFrame{ public TestFrame() {
    initComponents(); setVisible(</span><span style="color: rgba(0, 0, 255, 1)">true</span>);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 显示</span> setLocationRelativeTo(<span style="color: rgba(0, 0, 255, 1)">null</span>);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> JFrame 窗口居中显示</span> 

    }

    public static void main(String[] args) {

    java.awt.EventQueue.invokeLater(() </span>-&gt;<span style="color: rgba(0, 0, 0, 1)"> { </span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> TestFrame(); System.out.println(</span>"启动成功!"<span style="color: rgba(0, 0, 0, 1)">); }); 

    }

    private void SubmitActionPerformed(ActionEvent e) {

    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> TODO add your code here</span> System.out.println("---------------------------"<span style="color: rgba(0, 0, 0, 1)">); System.out.println(</span>"姓名:"+<span style="color: rgba(0, 0, 0, 1)">userNameTestField.getText()); String sex </span>= ""<span style="color: rgba(0, 0, 0, 1)">; </span><span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (xyRadioButton.isSelected()) { sex </span>= "男"<span style="color: rgba(0, 0, 0, 1)">; } </span><span style="color: rgba(0, 0, 255, 1)">else</span> <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (xxRadioButton.isSelected()) { sex </span>= "女"<span style="color: rgba(0, 0, 0, 1)">; }</span><span style="color: rgba(0, 0, 255, 1)">else</span> <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (yyRadioButton.isSelected()) { sex </span>= "不确定"<span style="color: rgba(0, 0, 0, 1)">; } System.out.println(</span>"性别:"+<span style="color: rgba(0, 0, 0, 1)">sex); String hobby </span>= ""<span style="color: rgba(0, 0, 0, 1)">; </span><span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (singCheckBox.isSelected()) { hobby </span>+= "唱、"<span style="color: rgba(0, 0, 0, 1)">; } </span><span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (skipCheckBox.isSelected()) { hobby </span>+= "跳、"<span style="color: rgba(0, 0, 0, 1)">; } </span><span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (rapCheckBox.isSelected()) { hobby </span>+= "rap、"<span style="color: rgba(0, 0, 0, 1)">; } System.out.println(</span>"爱好:"+<span style="color: rgba(0, 0, 0, 1)">hobby); System.out.println(</span>"自我评价:"+<span style="color: rgba(0, 0, 0, 1)">selfTextArea.getText()); 

    }

    private void initComponents() {

    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> JFormDesigner - Component initialization - DO NOT MODIFY </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">GEN-BEGIN:initComponents</span> label1 = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JLabel(); userNameTestField </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JTextField(); label2 </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JLabel(); label3 </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JLabel(); submit </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JButton(); reset </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JButton(); xxRadioButton </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JRadioButton(); xyRadioButton </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JRadioButton(); yyRadioButton </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JRadioButton(); scrollPane1 </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JScrollPane(); selfTextArea </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JTextArea(); label4 </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JLabel(); label5 </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JLabel(); singCheckBox </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JCheckBox(); skipCheckBox </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JCheckBox(); rapCheckBox </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JCheckBox(); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">======== this ========</span> 

    setBackground(Color.gray);

    setTitle(</span>"Test GUI"<span style="color: rgba(0, 0, 0, 1)">); setForeground(SystemColor.windowText); setMinimumSize(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Dimension(300, 200<span style="color: rgba(0, 0, 0, 1)">)); setResizable(</span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container contentPane </span>=<span style="color: rgba(0, 0, 0, 1)"> getContentPane(); contentPane.setLayout(</span><span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- label1 ----</span> label1.setText("姓名:"<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(label1); label1.setBounds(</span>34, 55, 65, 30<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(userNameTestField); userNameTestField.setBounds(</span>119, 55, 200<span style="color: rgba(0, 0, 0, 1)">, userNameTestField.getPreferredSize().height); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- label2 ----</span> label2.setText("性别:"<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(label2); label2.setBounds(</span>34, 95, 65, 30<span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- label3 ----</span> label3.setText("自我评价:"<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(label3); label3.setBounds(</span>34, 165, 65, 30<span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- submit ----</span> submit.setText("提交"<span style="color: rgba(0, 0, 0, 1)">); submit.addActionListener(e </span>-&gt;<span style="color: rgba(0, 0, 0, 1)"> SubmitActionPerformed(e)); contentPane.add(submit); submit.setBounds(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Rectangle(<span style="color: rgba(0, 0, 255, 1)">new</span> Point(64, 271<span style="color: rgba(0, 0, 0, 1)">), submit.getPreferredSize())); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- reset ----</span> reset.setText("重置"<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(reset); reset.setBounds(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Rectangle(<span style="color: rgba(0, 0, 255, 1)">new</span> Point(219, 271<span style="color: rgba(0, 0, 0, 1)">), reset.getPreferredSize())); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- xxRadioButton ----</span> xxRadioButton.setText("女"<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(xxRadioButton); xxRadioButton.setBounds(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Rectangle(<span style="color: rgba(0, 0, 255, 1)">new</span> Point(184, 100<span style="color: rgba(0, 0, 0, 1)">), xxRadioButton.getPreferredSize())); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- xyRadioButton ----</span> xyRadioButton.setText("男"<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(xyRadioButton); xyRadioButton.setBounds(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Rectangle(<span style="color: rgba(0, 0, 255, 1)">new</span> Point(129, 100<span style="color: rgba(0, 0, 0, 1)">), xyRadioButton.getPreferredSize())); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- yyRadioButton ----</span> yyRadioButton.setText("不确定"<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(yyRadioButton); yyRadioButton.setBounds(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Rectangle(<span style="color: rgba(0, 0, 255, 1)">new</span> Point(239, 100<span style="color: rgba(0, 0, 0, 1)">), yyRadioButton.getPreferredSize())); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">======== scrollPane1 ========</span> 

    {

     scrollPane1.setViewportView(selfTextArea); } contentPane.add(scrollPane1); scrollPane1.setBounds(</span>117, 165, 202, 71<span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- label4 ----</span> label4.setText("测试表单"<span style="color: rgba(0, 0, 0, 1)">); label4.setFont(label4.getFont().deriveFont(22f)); contentPane.add(label4); label4.setBounds(</span>124, 0, 100, 45<span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- label5 ----</span> label5.setText("爱好:"<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(label5); label5.setBounds(</span>34, 130, 65, 30<span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- singCheckBox ----</span> singCheckBox.setText("唱"<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(singCheckBox); singCheckBox.setBounds(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Rectangle(<span style="color: rgba(0, 0, 255, 1)">new</span> Point(129, 135<span style="color: rgba(0, 0, 0, 1)">), singCheckBox.getPreferredSize())); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- skipCheckBox ----</span> skipCheckBox.setText("跳"<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(skipCheckBox); skipCheckBox.setBounds(</span><span style="color: rgba(0, 0, 255, 1)">new</span> Rectangle(<span style="color: rgba(0, 0, 255, 1)">new</span> Point(184, 135<span style="color: rgba(0, 0, 0, 1)">), skipCheckBox.getPreferredSize())); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- rapCheckBox ----</span> rapCheckBox.setText("rap"<span style="color: rgba(0, 0, 0, 1)">); contentPane.add(rapCheckBox); rapCheckBox.setBounds(</span>239, 135, 50<span style="color: rgba(0, 0, 0, 1)">, rapCheckBox.getPreferredSize().height); { </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> compute preferred size</span> Dimension preferredSize = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Dimension(); </span><span style="color: rgba(0, 0, 255, 1)">for</span>(<span style="color: rgba(0, 0, 255, 1)">int</span> i = 0; i &lt; contentPane.getComponentCount(); i++<span style="color: rgba(0, 0, 0, 1)">) { Rectangle bounds </span>=<span style="color: rgba(0, 0, 0, 1)"> contentPane.getComponent(i).getBounds(); preferredSize.width </span>= Math.max(bounds.x +<span style="color: rgba(0, 0, 0, 1)"> bounds.width, preferredSize.width); preferredSize.height </span>= Math.max(bounds.y +<span style="color: rgba(0, 0, 0, 1)"> bounds.height, preferredSize.height); } Insets insets </span>=<span style="color: rgba(0, 0, 0, 1)"> contentPane.getInsets(); preferredSize.width </span>+=<span style="color: rgba(0, 0, 0, 1)"> insets.right; preferredSize.height </span>+=<span style="color: rgba(0, 0, 0, 1)"> insets.bottom; contentPane.setMinimumSize(preferredSize); contentPane.setPreferredSize(preferredSize); } setSize(</span>400, 365<span style="color: rgba(0, 0, 0, 1)">); setLocationRelativeTo(</span><span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">---- buttonGroup2 ----</span> ButtonGroup buttonGroup2 = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> ButtonGroup(); buttonGroup2.add(xxRadioButton); buttonGroup2.add(xyRadioButton); buttonGroup2.add(yyRadioButton); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> JFormDesigner - End of component initialization </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">GEN-END:initComponents</span> 

    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables private JLabel label1; private JTextField userNameTestField; private JLabel label2; private JLabel label3; private JButton submit; private JButton reset; private JRadioButton xxRadioButton; private JRadioButton xyRadioButton; private JRadioButton yyRadioButton; private JScrollPane scrollPane1; private JTextArea selfTextArea; private JLabel label4; private JLabel label5; private JCheckBox singCheckBox; private JCheckBox skipCheckBox; private JCheckBox rapCheckBox; // JFormDesigner - End of variables declaration //GEN-END:variables }

版权声明


相关文章:

  • java快递网站教程2025-12-08 16:42:02
  • java材质包使用教程2025-12-08 16:42:02
  • java教程1882025-12-08 16:42:02
  • java高频教程2025-12-08 16:42:02
  • 求java新手教程2025-12-08 16:42:02
  • 自动农场教程java2025-12-08 16:42:02
  • java 中文教程2025-12-08 16:42:02
  • 马士兵java视频教程2025-12-08 16:42:02
  • java编程helloworld教程2025-12-08 16:42:02
  • java核心类教程2025-12-08 16:42:02