使用swing 可视化

This commit is contained in:
jsh
2025-10-12 12:05:23 +08:00
parent b5a118994a
commit 2949a48e63
3 changed files with 93 additions and 7 deletions

28
pom.xml
View File

@@ -26,4 +26,32 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.dota.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,59 @@
package com.dota;
import javax.swing.*;
import java.awt.*;
public class App {
public static void main(String[] args) {
SwingUtilities.invokeLater(App::lanuch);
}
static String[] doctors = new String[]{"顾磊", "章亮", "唐婷婷", "杨祖怡", "李宁", "周晖"};
static void lanuch() {
JFrame jframe = new JFrame("排班系统");
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setSize(600,400);
jframe.setLayout(new BorderLayout(10, 10));
var dateField = new JTextField("2025-10-13");
var weekNumField = new JTextField("2");
var filePathField = new JTextField("C:\\Users\\yangz\\Documents\\医生排班.xlsx");
var doctorField = new JComboBox<>(doctors);
doctorField.setSelectedIndex(0);
var resText = new JTextArea("点击确定按钮,输出执行结果");
var btn = new JButton("确定");
// 输入区域
JPanel inputPanel = new JPanel(new GridLayout(4,2,10,5));
jframe.add(inputPanel, BorderLayout.NORTH);
inputPanel.add(new JLabel("排班日期"));
inputPanel.add(dateField);
inputPanel.add(new JLabel("排班周数"));
inputPanel.add(weekNumField);
inputPanel.add(new JLabel("第一个值班的医生"));
inputPanel.add(doctorField);
inputPanel.add(new JLabel("输出文件位置"));
inputPanel.add(filePathField);
//结果区域
JPanel resPanel = new JPanel();
jframe.add(resPanel, BorderLayout.CENTER);
resPanel.add(resText);
// 按钮区域
var btnPanel = new JPanel();
jframe.add(btnPanel, BorderLayout.SOUTH);
btnPanel.add(btn);
btn.addActionListener(e->{
resText.setText("运行中,请稍等");
Main.run(dateField.getText(), Integer.parseInt(weekNumField.getText()), (String) doctorField.getSelectedItem(), filePathField.getText());
resText.setText("运行结束,请查看排班文件");
});
jframe.setLocationRelativeTo(null);
jframe.setVisible(true);
}
}

View File

@@ -7,7 +7,6 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream;
import java.text.DateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
@@ -31,6 +30,10 @@ public class Main {
static LocalDate day;
public static void main(String[] args) {
run("2025-10-13", 2, "周晖", "C:\\Users\\yangz\\Documents\\医生排班.xlsx");
}
static void run(String date, int weekNum, String name, String file){
init();
var doctorOrder = new Doctor[]{
gl, zl, ttt, zy, ln, zh
@@ -39,12 +42,8 @@ public class Main {
ln, zy, ttt, zl, zh, gl, tgy
};
// var s = new ArrayList<Doctor>();
// for (int i = -1; i < 2; i++) {
// s.addAll(schedule(doctorOrder, outputOrder));
// }
// print(s);
write("2025-10-13", 4, "顾磊", doctorOrder, outputOrder);
filePath = file;
write(date, weekNum, name, doctorOrder, outputOrder);
}