feat(experiment_4): 添加注册登录界面
- 新增 RegisterGUI 类实现注册登录界面 - 使用 JFormDesigner 工具设计界面布局 - 添加账户输入框、密码输入框、登录和注册按钮 - 创建 task 类作为程序入口,初始化注册登录界面
This commit is contained in:
parent
d62bb73cf3
commit
ac7ab26d72
@ -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
|
||||
}
|
@ -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 )
|
||||
} )
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package cn.vscoder.experiment_4;
|
||||
|
||||
public class task {
|
||||
public static void main(String[] args) {
|
||||
new RegisterGUI();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user