From ac7ab26d726b48dd69f09e16ccfe59212ab78062 Mon Sep 17 00:00:00 2001 From: dev_xulongjin Date: Tue, 29 Apr 2025 16:57:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(experiment=5F4):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E7=99=BB=E5=BD=95=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 RegisterGUI 类实现注册登录界面 - 使用 JFormDesigner 工具设计界面布局 - 添加账户输入框、密码输入框、登录和注册按钮 - 创建 task 类作为程序入口,初始化注册登录界面 --- .../cn/vscoder/experiment_4/RegisterGUI.java | 141 ++++++++++++++++++ .../cn/vscoder/experiment_4/RegisterGUI.jfd | 74 +++++++++ .../java/cn/vscoder/experiment_4/task.java | 7 + 3 files changed, 222 insertions(+) create mode 100644 java-lesson/src/main/java/cn/vscoder/experiment_4/RegisterGUI.java create mode 100644 java-lesson/src/main/java/cn/vscoder/experiment_4/RegisterGUI.jfd create mode 100644 java-lesson/src/main/java/cn/vscoder/experiment_4/task.java diff --git a/java-lesson/src/main/java/cn/vscoder/experiment_4/RegisterGUI.java b/java-lesson/src/main/java/cn/vscoder/experiment_4/RegisterGUI.java new file mode 100644 index 0000000..175d620 --- /dev/null +++ b/java-lesson/src/main/java/cn/vscoder/experiment_4/RegisterGUI.java @@ -0,0 +1,141 @@ +/* + * Created by JFormDesigner on Mon Apr 28 16:01:14 CST 2025 + */ + +package cn.vscoder.experiment_4; + +import java.awt.*; +import javax.swing.*; + +/** + * @author xulongjin + */ +public class RegisterGUI { + public RegisterGUI() { + initComponents(); + } + + private void initComponents() { + // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents @formatter:off + title = new JFrame(); + panel1 = new JPanel(); + label1 = new JLabel(); + tfaccount = new JTextField(); + panel2 = new JPanel(); + label2 = new JLabel(); + passwordField1 = new JPasswordField(); + panel3 = new JPanel(); + button1 = new JButton(); + button2 = new JButton(); + + //======== title ======== + { + title.setTitle("\u6ce8\u518c\u767b\u5f55"); + var titleContentPane = title.getContentPane(); + titleContentPane.setLayout(new GridLayout(3, 1)); + + //======== panel1 ======== + { + panel1.setLayout(null); + + //---- label1 ---- + label1.setText("\u8d26\u6237\uff1a"); + panel1.add(label1); + label1.setBounds(95, 45, 40, 30); + panel1.add(tfaccount); + tfaccount.setBounds(140, 40, 255, tfaccount.getPreferredSize().height); + + { + // compute preferred size + Dimension preferredSize = new Dimension(); + for(int i = 0; i < panel1.getComponentCount(); i++) { + Rectangle bounds = panel1.getComponent(i).getBounds(); + preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); + preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); + } + Insets insets = panel1.getInsets(); + preferredSize.width += insets.right; + preferredSize.height += insets.bottom; + panel1.setMinimumSize(preferredSize); + panel1.setPreferredSize(preferredSize); + } + } + titleContentPane.add(panel1); + + //======== panel2 ======== + { + panel2.setLayout(null); + + //---- label2 ---- + label2.setText("\u5bc6\u7801\uff1a"); + panel2.add(label2); + label2.setBounds(95, 35, 40, 30); + panel2.add(passwordField1); + passwordField1.setBounds(140, 30, 255, passwordField1.getPreferredSize().height); + + { + // compute preferred size + Dimension preferredSize = new Dimension(); + for(int i = 0; i < panel2.getComponentCount(); i++) { + Rectangle bounds = panel2.getComponent(i).getBounds(); + preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); + preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); + } + Insets insets = panel2.getInsets(); + preferredSize.width += insets.right; + preferredSize.height += insets.bottom; + panel2.setMinimumSize(preferredSize); + panel2.setPreferredSize(preferredSize); + } + } + titleContentPane.add(panel2); + + //======== panel3 ======== + { + panel3.setLayout(null); + + //---- button1 ---- + button1.setText("\u767b\u5f55"); + panel3.add(button1); + button1.setBounds(new Rectangle(new Point(270, 25), button1.getPreferredSize())); + + //---- button2 ---- + button2.setText("\u6ce8\u518c"); + panel3.add(button2); + button2.setBounds(135, 25, 78, 34); + + { + // compute preferred size + Dimension preferredSize = new Dimension(); + for(int i = 0; i < panel3.getComponentCount(); i++) { + Rectangle bounds = panel3.getComponent(i).getBounds(); + preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); + preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); + } + Insets insets = panel3.getInsets(); + preferredSize.width += insets.right; + preferredSize.height += insets.bottom; + panel3.setMinimumSize(preferredSize); + panel3.setPreferredSize(preferredSize); + } + } + titleContentPane.add(panel3); + title.pack(); + title.setLocationRelativeTo(title.getOwner()); + } + // JFormDesigner - End of component initialization //GEN-END:initComponents @formatter:on + } + + // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables @formatter:off + private JFrame title; + private JPanel panel1; + private JLabel label1; + private JTextField tfaccount; + private JPanel panel2; + private JLabel label2; + private JPasswordField passwordField1; + private JPanel panel3; + private JButton button1; + private JButton button2; + // JFormDesigner - End of variables declaration //GEN-END:variables @formatter:on +} diff --git a/java-lesson/src/main/java/cn/vscoder/experiment_4/RegisterGUI.jfd b/java-lesson/src/main/java/cn/vscoder/experiment_4/RegisterGUI.jfd new file mode 100644 index 0000000..a3c6ca1 --- /dev/null +++ b/java-lesson/src/main/java/cn/vscoder/experiment_4/RegisterGUI.jfd @@ -0,0 +1,74 @@ +JFDML JFormDesigner: "8.2.4.0.393" Java: "21.0.6" encoding: "UTF-8" + +new FormModel { + contentType: "form/swing" + root: new FormRoot { + add( new FormWindow( "javax.swing.JFrame", new FormLayoutManager( class java.awt.GridLayout ) { + "columns": 1 + "rows": 3 + } ) { + name: "title" + "title": "注册登录" + add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) ) { + name: "panel1" + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label1" + "text": "账户:" + }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { + "x": 95 + "y": 45 + "width": 40 + "height": 30 + } ) + add( new FormComponent( "javax.swing.JTextField" ) { + name: "tfaccount" + }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { + "x": 140 + "y": 40 + "width": 255 + } ) + } ) + add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) ) { + name: "panel2" + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label2" + "text": "密码:" + }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { + "width": 40 + "height": 30 + "x": 95 + "y": 35 + } ) + add( new FormComponent( "javax.swing.JPasswordField" ) { + name: "passwordField1" + }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { + "x": 140 + "y": 30 + "width": 255 + } ) + } ) + add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) ) { + name: "panel3" + add( new FormComponent( "javax.swing.JButton" ) { + name: "button1" + "text": "登录" + }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { + "x": 270 + "y": 25 + } ) + add( new FormComponent( "javax.swing.JButton" ) { + name: "button2" + "text": "注册" + }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { + "width": 78 + "height": 34 + "x": 135 + "y": 25 + } ) + } ) + }, new FormLayoutConstraints( null ) { + "location": new java.awt.Point( 0, 0 ) + "size": new java.awt.Dimension( 490, 350 ) + } ) + } +} diff --git a/java-lesson/src/main/java/cn/vscoder/experiment_4/task.java b/java-lesson/src/main/java/cn/vscoder/experiment_4/task.java new file mode 100644 index 0000000..1cb354b --- /dev/null +++ b/java-lesson/src/main/java/cn/vscoder/experiment_4/task.java @@ -0,0 +1,7 @@ +package cn.vscoder.experiment_4; + +public class task { + public static void main(String[] args) { + new RegisterGUI(); + } +}