Skip to content

Commit 171e208

Browse files
committedOct 30, 2024
first commit
0 parents  commit 171e208

22 files changed

+634
-0
lines changed
 

‎.gitignore

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store
39+
40+
.idea/
41+
.exe
42+
.dll
43+
.so
44+
.jar

‎README.md

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
## java-swing-gui-stater
2+
3+
本项目是一个 `Java Swing GUI` 项目基础模板,你的一切想法都可以基于这个项目开发
4+
5+
大部分 `Java GUI` 是基于 `JavaFX` 开发的,但我不喜欢,我推荐 `Swing` 原因如下:
6+
7+
- 无需依赖:`JRE` 自带,无需引入多余的依赖即可直接开发,不用考虑用户 `JRE` 版本做特殊适配
8+
- 学习成本低:使用 `IDEA` 自带的 `GUI Designer` 即可,只使用 `Java` 语言,不用学习 `FXML`
9+
- 美观程度:原生 `Java Swing` 界面看起来是老古董,但是使用 `flatlaf` 会大幅美化
10+
11+
## Desc
12+
13+
本项目做的事情:
14+
15+
- 提供了基础的依赖和配置(配套注释)
16+
- 提供了构建和打包配置(一键生成 `Jar` 文件)
17+
-`README` 中提供了详细的开发教程
18+
- 在代码中提供了详细的注释
19+
- 提供了常见的 `Java Swing GUI` 开发工具类
20+
21+
## Quick Start
22+
23+
(1) 推荐准备 `JDK 8` 环境,无论 `OpenJDK``Oracle JDK` 都可,不要求版本
24+
25+
(2) 准备一个 `IntelliJ IDEA` 社区版专业版都可,推荐使用较新的版本
26+
27+
(3) 使用 `IDEA` 打开本项目,参考下图配置 `GUI Designer`
28+
29+
![](image/001.png)
30+
31+
(4) 本项目已经有一个默认的 `Form` 你可以按照下图这样自行添加
32+
33+
![](image/002.png)
34+
35+
(5) 打包成一个 `Fat Jar` 然后使用 `java -jar xxx.jar` 即可启动
36+
37+
使用 `mvn clean package` 或者 `IDEA` 自带按钮即可打包
38+
39+
![](image/003.png)
40+
41+
打包后的 `Jar` 文件位于
42+
43+
![](image/004.png)
44+
45+
这是一个类似 `SpringBoot` 装满了依赖的 `Fat Jar` 使用简短的命令即可启动
46+
47+
```shell
48+
java -jar java-swing-gui-starter-0.0.1-jar-with-dependencies.jar
49+
```
50+
51+
文件名是自动生成的,自己开发时按需修改 `pom.xml` 文件内容即可(我已经给出注释)
52+
53+
![](image/006.png)
54+
55+
## About
56+
57+
以下是一些基于 `Java Swing` 开发的程序
58+
59+
Jar Analyzer 项目 (开源)
60+
61+
![](image/case01.png)
62+
63+
Shell Analyzer 项目 (开源)
64+
65+
![](image/case04.png)
66+
67+
Mysql Fake Server 项目 (开源)
68+
69+
![](image/case03.png)
70+
71+
Jar Obfuscator 项目 (开源)
72+
73+
![](image/case02.png)
74+
75+
Jar Analyzer 子项目 Java DBG (开源)
76+
77+
![](image/case05.png)
78+
79+
Super Xray 项目 (开源)
80+
81+
![](image/case06.png)

‎image/001.png

17.2 KB
Loading

‎image/002.png

55.4 KB
Loading

‎image/003.png

5.73 KB
Loading

‎image/004.png

5.85 KB
Loading

‎image/006.png

26.2 KB
Loading

‎image/case01.png

171 KB
Loading

‎image/case02.png

66 KB
Loading

‎image/case03.png

55.5 KB
Loading

‎image/case04.png

551 KB
Loading

‎image/case05.png

48.2 KB
Loading

‎image/case06.png

119 KB
Loading

‎pom.xml

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<!-- 修改成你自己的包名 -->
8+
<groupId>me.n1ar4</groupId>
9+
<!-- 修改成你自己的项目名 -->
10+
<artifactId>java-swing-gui-starter</artifactId>
11+
<!-- 修改成你自己的版本 -->
12+
<version>0.0.1</version>
13+
14+
<packaging>jar</packaging>
15+
<!-- 你的项目描述 -->
16+
<description>java-swing-gui-starter</description>
17+
18+
<properties>
19+
<!-- 目前最新版 建议自行升级 -->
20+
<flatlaf.version>3.5.1</flatlaf.version>
21+
<!-- 目前最新版 建议自行升级 -->
22+
<idea.forms.version>7.0.3</idea.forms.version>
23+
<!-- 建议不要动 -->
24+
<maven.compiler.source>8</maven.compiler.source>
25+
<!-- 建议不要动 -->
26+
<maven.compiler.target>8</maven.compiler.target>
27+
<!-- 建议不要动 -->
28+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
29+
<!-- 修改成你自己的主类 -->
30+
<main.name>me.n1ar4.gui.Application</main.name>
31+
<!-- 构建插件按需升级 -->
32+
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-resources-plugin -->
33+
<maven.resources.version>3.3.1</maven.resources.version>
34+
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-assembly-plugin -->
35+
<maven.assembly.version>3.7.1</maven.assembly.version>
36+
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
37+
<maven.compiler.version>3.13.0</maven.compiler.version>
38+
</properties>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>com.formdev</groupId>
43+
<artifactId>flatlaf</artifactId>
44+
<version>${flatlaf.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>com.intellij</groupId>
48+
<artifactId>forms_rt</artifactId>
49+
<version>${idea.forms.version}</version>
50+
</dependency>
51+
</dependencies>
52+
53+
<build>
54+
<pluginManagement>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-resources-plugin</artifactId>
59+
<version>${maven.resources.version}</version>
60+
</plugin>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-assembly-plugin</artifactId>
64+
<version>${maven.assembly.version}</version>
65+
</plugin>
66+
<plugin>
67+
<groupId>org.apache.maven.plugins</groupId>
68+
<artifactId>maven-compiler-plugin</artifactId>
69+
<version>${maven.compiler.version}</version>
70+
</plugin>
71+
</plugins>
72+
</pluginManagement>
73+
<plugins>
74+
<plugin>
75+
<groupId>org.apache.maven.plugins</groupId>
76+
<artifactId>maven-resources-plugin</artifactId>
77+
</plugin>
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-assembly-plugin</artifactId>
81+
<executions>
82+
<execution>
83+
<id>build</id>
84+
<configuration>
85+
<attach>false</attach>
86+
<appendAssemblyId>true</appendAssemblyId>
87+
<descriptorRefs>
88+
<descriptorRef>jar-with-dependencies</descriptorRef>
89+
</descriptorRefs>
90+
<archive>
91+
<manifest>
92+
<mainClass>${main.name}</mainClass>
93+
</manifest>
94+
<manifestEntries>
95+
<Multi-Release>true</Multi-Release>
96+
</manifestEntries>
97+
</archive>
98+
</configuration>
99+
<phase>package</phase>
100+
<goals>
101+
<goal>single</goal>
102+
</goals>
103+
</execution>
104+
</executions>
105+
</plugin>
106+
<plugin>
107+
<groupId>org.apache.maven.plugins</groupId>
108+
<artifactId>maven-compiler-plugin</artifactId>
109+
<configuration>
110+
<source>${maven.compiler.source}</source>
111+
<target>${maven.compiler.target}</target>
112+
</configuration>
113+
</plugin>
114+
</plugins>
115+
</build>
116+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package me.n1ar4.gui;
2+
3+
import com.formdev.flatlaf.FlatLightLaf;
4+
5+
@SuppressWarnings("all")
6+
public class Application {
7+
public static void main(String[] args) {
8+
// 使用 flatlaf 的皮肤
9+
FlatLightLaf.setup();
10+
// 黑暗主题和一些其他主题的皮肤尝试
11+
// FlatDarkLaf.setup();
12+
// FlatIntelliJLaf.setup();
13+
DemoForm.start();
14+
}
15+
}
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="me.n1ar4.gui.DemoForm">
3+
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="8" left="8" bottom="8" right="8"/>
5+
<constraints>
6+
<xy x="20" y="20" width="500" height="400"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<component id="af4d5" class="javax.swing.JLabel" binding="usernameLabel">
12+
<constraints>
13+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
14+
</constraints>
15+
<properties>
16+
<text value="Username"/>
17+
</properties>
18+
</component>
19+
<component id="9a9be" class="javax.swing.JLabel" binding="passwordLabel">
20+
<constraints>
21+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
22+
</constraints>
23+
<properties>
24+
<text value="Password"/>
25+
</properties>
26+
</component>
27+
<component id="13bf3" class="javax.swing.JTextField" binding="userNameText">
28+
<constraints>
29+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
30+
<minimum-size width="300" height="-1"/>
31+
<preferred-size width="300" height="-1"/>
32+
</grid>
33+
</constraints>
34+
<properties/>
35+
</component>
36+
<component id="460ab" class="javax.swing.JPasswordField" binding="passwordText">
37+
<constraints>
38+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
39+
<minimum-size width="300" height="-1"/>
40+
<preferred-size width="300" height="-1"/>
41+
</grid>
42+
</constraints>
43+
<properties/>
44+
</component>
45+
<grid id="1f091" binding="actionPanel" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
46+
<margin top="0" left="0" bottom="0" right="0"/>
47+
<constraints>
48+
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
49+
</constraints>
50+
<properties/>
51+
<border type="none"/>
52+
<children>
53+
<component id="61e77" class="javax.swing.JButton" binding="cleanBtn">
54+
<constraints>
55+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
56+
</constraints>
57+
<properties>
58+
<text value="CLEAN"/>
59+
</properties>
60+
</component>
61+
<component id="66384" class="javax.swing.JButton" binding="registerBtn">
62+
<constraints>
63+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
64+
</constraints>
65+
<properties>
66+
<text value="REGISTER"/>
67+
</properties>
68+
</component>
69+
<component id="e6032" class="javax.swing.JButton" binding="loginBtn">
70+
<constraints>
71+
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
72+
</constraints>
73+
<properties>
74+
<text value="LOGIN"/>
75+
</properties>
76+
</component>
77+
<component id="498d5" class="javax.swing.JLabel" binding="logoLabel">
78+
<constraints>
79+
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
80+
</constraints>
81+
<properties>
82+
<text value=""/>
83+
</properties>
84+
</component>
85+
</children>
86+
</grid>
87+
</children>
88+
</grid>
89+
</form>
+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package me.n1ar4.gui;
2+
3+
import com.intellij.uiDesigner.core.GridConstraints;
4+
import com.intellij.uiDesigner.core.GridLayoutManager;
5+
6+
import javax.swing.*;
7+
import java.awt.*;
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
11+
public class DemoForm {
12+
private JPanel rootPanel;
13+
private JTextField userNameText;
14+
private JPasswordField passwordText;
15+
private JButton cleanBtn;
16+
private JButton registerBtn;
17+
private JButton loginBtn;
18+
private JLabel usernameLabel;
19+
private JLabel passwordLabel;
20+
private JPanel actionPanel;
21+
private JLabel logoLabel;
22+
23+
private static final Map<String, String> database = new HashMap<>();
24+
25+
private static JFrame frame;
26+
27+
public DemoForm() {
28+
// 参考 IconManager.getLogoIcon()
29+
// 如何获得 JAR 内部的图片文件作为 GUI 界面的图片
30+
logoLabel.setIcon(IconManager.getLogoIcon());
31+
32+
// 如何给按钮绑定事件
33+
cleanBtn.addActionListener(e -> {
34+
// 清空输入框
35+
userNameText.setText("");
36+
passwordText.setText("");
37+
// 提示用户清理完成
38+
JOptionPane.showMessageDialog(null, "clean finish");
39+
});
40+
41+
loginBtn.addActionListener(e -> {
42+
// 获取用户名密码
43+
String username = userNameText.getText();
44+
String password = new String(passwordText.getPassword());
45+
if (username == null || password.isEmpty()) {
46+
// 如何弹出提示
47+
JOptionPane.showMessageDialog(null, "username or password is empty");
48+
return;
49+
}
50+
System.out.println("username = " + username);
51+
System.out.println("password = " + password);
52+
// 查询用户
53+
String userPass = database.get(username);
54+
if (userPass != null && userPass.equals(password)) {
55+
JOptionPane.showMessageDialog(null, "login finish");
56+
// 如何跳转另一个页面
57+
frame.dispose();
58+
IndexForm.show(username);
59+
} else {
60+
JOptionPane.showMessageDialog(null, "username or password is incorrect");
61+
}
62+
});
63+
64+
registerBtn.addActionListener(e -> {
65+
// 如何注册
66+
String username = userNameText.getText();
67+
String password = new String(passwordText.getPassword());
68+
if (username == null || password.isEmpty()) {
69+
JOptionPane.showMessageDialog(null, "username or password is empty");
70+
return;
71+
}
72+
database.put(username, password);
73+
JOptionPane.showMessageDialog(null, "register " + username + " finish");
74+
});
75+
}
76+
77+
public static void start() {
78+
frame = new JFrame("java-swing-gui-starter");
79+
80+
// 参考 MenuUtil.createMenuBar()
81+
// 如何设置一个菜单
82+
frame.setJMenuBar(MenuUtil.createMenuBar());
83+
// 居中显示
84+
frame.setLocationRelativeTo(null);
85+
frame.setContentPane(new DemoForm().rootPanel);
86+
// 退出后程序完全退出
87+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
88+
// 展示
89+
frame.pack();
90+
frame.setVisible(true);
91+
}
92+
93+
// 下面的代码是 IDEA GUI Designer 生成的
94+
// !!!不要改动!!!
95+
96+
{
97+
// GUI initializer generated by IntelliJ IDEA GUI Designer
98+
// >>> IMPORTANT!! <<<
99+
// DO NOT EDIT OR ADD ANY CODE HERE!
100+
$$$setupUI$$$();
101+
}
102+
103+
/**
104+
* Method generated by IntelliJ IDEA GUI Designer
105+
* >>> IMPORTANT!! <<<
106+
* DO NOT edit this method OR call it in your code!
107+
*
108+
* @noinspection ALL
109+
*/
110+
private void $$$setupUI$$$() {
111+
rootPanel = new JPanel();
112+
rootPanel.setLayout(new GridLayoutManager(3, 2, new Insets(8, 8, 8, 8), -1, -1));
113+
usernameLabel = new JLabel();
114+
usernameLabel.setText("Username");
115+
rootPanel.add(usernameLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
116+
passwordLabel = new JLabel();
117+
passwordLabel.setText("Password");
118+
rootPanel.add(passwordLabel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
119+
userNameText = new JTextField();
120+
rootPanel.add(userNameText, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, -1), new Dimension(300, -1), null, 0, false));
121+
passwordText = new JPasswordField();
122+
rootPanel.add(passwordText, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, -1), new Dimension(300, -1), null, 0, false));
123+
actionPanel = new JPanel();
124+
actionPanel.setLayout(new GridLayoutManager(1, 4, new Insets(0, 0, 0, 0), -1, -1));
125+
rootPanel.add(actionPanel, new GridConstraints(2, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
126+
cleanBtn = new JButton();
127+
cleanBtn.setText("CLEAN");
128+
actionPanel.add(cleanBtn, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
129+
registerBtn = new JButton();
130+
registerBtn.setText("REGISTER");
131+
actionPanel.add(registerBtn, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
132+
loginBtn = new JButton();
133+
loginBtn.setText("LOGIN");
134+
actionPanel.add(loginBtn, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
135+
logoLabel = new JLabel();
136+
logoLabel.setText("");
137+
actionPanel.add(logoLabel, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
138+
}
139+
140+
/**
141+
* @noinspection ALL
142+
*/
143+
public JComponent $$$getRootComponent$$$() {
144+
return rootPanel;
145+
}
146+
147+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package me.n1ar4.gui;
2+
3+
import javax.imageio.ImageIO;
4+
import javax.swing.*;
5+
import java.awt.*;
6+
import java.util.Objects;
7+
8+
@SuppressWarnings("all")
9+
public class IconManager {
10+
private static ImageIcon getIcon(String path, int x, int y) {
11+
try {
12+
ImageIcon showIcon = new ImageIcon(ImageIO.read(
13+
Objects.requireNonNull(IconManager.class
14+
.getClassLoader().getResourceAsStream(path))));
15+
Image image = showIcon.getImage();
16+
Image resizedImage = image.getScaledInstance(x, y, Image.SCALE_SMOOTH);
17+
showIcon = new ImageIcon(resizedImage);
18+
return showIcon;
19+
} catch (Exception ex) {
20+
throw new RuntimeException(ex);
21+
}
22+
}
23+
24+
public static ImageIcon getLogoIcon() {
25+
// 传入名称 和 你希望得到的 长 宽
26+
return getIcon("img/logo.png", 60, 60);
27+
}
28+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="me.n1ar4.gui.IndexForm">
3+
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="0" left="0" bottom="0" right="0"/>
5+
<constraints>
6+
<xy x="20" y="20" width="500" height="400"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<scrollpane id="6195e" binding="rootScroll">
12+
<constraints>
13+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
14+
</constraints>
15+
<properties/>
16+
<border type="none"/>
17+
<children>
18+
<component id="1000" class="javax.swing.JTextArea" binding="rootArea">
19+
<constraints/>
20+
<properties>
21+
<columns value="50"/>
22+
<rows value="30"/>
23+
</properties>
24+
</component>
25+
</children>
26+
</scrollpane>
27+
</children>
28+
</grid>
29+
</form>
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package me.n1ar4.gui;
2+
3+
import com.intellij.uiDesigner.core.GridConstraints;
4+
import com.intellij.uiDesigner.core.GridLayoutManager;
5+
6+
import javax.swing.*;
7+
import java.awt.*;
8+
9+
public class IndexForm {
10+
private JPanel rootPanel;
11+
private JTextArea rootArea;
12+
private JScrollPane rootScroll;
13+
14+
public static void show(String message) {
15+
JFrame frame = new JFrame("IndexForm");
16+
frame.setLocationRelativeTo(null);
17+
IndexForm form = new IndexForm();
18+
form.rootArea.setText("welcome: " + message);
19+
frame.setContentPane(form.rootPanel);
20+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21+
frame.pack();
22+
frame.setVisible(true);
23+
}
24+
25+
{
26+
// GUI initializer generated by IntelliJ IDEA GUI Designer
27+
// >>> IMPORTANT!! <<<
28+
// DO NOT EDIT OR ADD ANY CODE HERE!
29+
$$$setupUI$$$();
30+
}
31+
32+
/**
33+
* Method generated by IntelliJ IDEA GUI Designer
34+
* >>> IMPORTANT!! <<<
35+
* DO NOT edit this method OR call it in your code!
36+
*
37+
* @noinspection ALL
38+
*/
39+
private void $$$setupUI$$$() {
40+
rootPanel = new JPanel();
41+
rootPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
42+
rootScroll = new JScrollPane();
43+
rootPanel.add(rootScroll, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
44+
rootArea = new JTextArea();
45+
rootArea.setColumns(50);
46+
rootArea.setRows(30);
47+
rootScroll.setViewportView(rootArea);
48+
}
49+
50+
/**
51+
* @noinspection ALL
52+
*/
53+
public JComponent $$$getRootComponent$$$() {
54+
return rootPanel;
55+
}
56+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package me.n1ar4.gui;
2+
3+
import javax.swing.*;
4+
5+
public class MenuUtil {
6+
public static JMenuBar createMenuBar() {
7+
JMenuBar menuBar = new JMenuBar();
8+
menuBar.add(createAboutMenu());
9+
return menuBar;
10+
}
11+
12+
private static JMenu createAboutMenu() {
13+
try {
14+
JMenu newMenu = new JMenu("File");
15+
16+
JMenuItem connectItem = new JMenuItem("New");
17+
connectItem.addActionListener(e -> {
18+
// 完成你的逻辑
19+
System.out.println("Do New File");
20+
// 如何弹出一个框
21+
JOptionPane.showMessageDialog(null,"Do New File");
22+
});
23+
newMenu.add(connectItem);
24+
return newMenu;
25+
} catch (Exception ex) {
26+
return null;
27+
}
28+
}
29+
}

‎src/main/resources/img/logo.png

17.5 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.