修改Confirm_Panel.java数据读取,数据源位MySQL数据库

taojinfeng_branch
zaczq 6 months ago
parent 0e06f45c08
commit d2aa102917

@ -3,40 +3,48 @@ package frame.UserPanel;
import constant.Constant;
import frame.Main_Frame;
import model.eachFlight;
import model_new.Flight;
import service.FlightService;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
/**
* <p>This page is mainly for passengers to confirm the previously selected information for final confirmation.</p>
* <p></p>
*
* @author Qingwei Gao
* @version 3.1
*/
public class Confirm_Panel extends JPanel {
/**
* -
*/
public Confirm_Panel() {
//Set background color
// 设置背景颜色
setBackground(new Color(72, 46, 115));
//Set initial panel
// 创建主面板
JPanel panel = new JPanel();
panel.setBackground(new Color(72, 46, 115));
panel.setPreferredSize(new Dimension(1200, 680));
add(panel);
// 创建信息显示面板
JPanel panel1 = new JPanel();
panel1.setBackground(new Color(96,62,151));
// 从食物选择面板获取选择的食物类型
Main_Frame.foodType=Foods_Panel.food;
// ==================== 创建所有文本标签 ====================
// 提示信息标签
JLabel label1 = new JLabel("PLEASE PUT YOUR ");
JLabel label2 = new JLabel("ID DOCUMENT");
JLabel label3 = new JLabel("UNDER THE CAMERA TO SCAN");
@ -46,19 +54,51 @@ public class Confirm_Panel extends JPanel {
JLabel label7 = new JLabel("COMPLETING THE SCAN");
JLabel label8 = new JLabel("CLICK");
JLabel label9 = new JLabel("CONFIRM");
// 信息标题标签
JLabel label11 = new JLabel("BOARDING TIME");
JLabel label12 = new JLabel("GATE");
JLabel label13 = new JLabel("SEATS");
JLabel label14 = new JLabel("FOODS");
// 具体信息标签
JLabel label15 = new JLabel(Main_Frame.flightNum);
JLabel label16 = new JLabel(eachFlight.boardingTime(Main_Frame.flightNum));
JLabel label17 = new JLabel(eachFlight.GATE(Main_Frame.flightNum));
// ===============================================修改前=======================================
// JLabel label16 = new JLabel(eachFlight.boardingTime(Main_Frame.flightNum));
// JLabel label17 = new JLabel(eachFlight.GATE(Main_Frame.flightNum));
// JLabel label18 = new JLabel(Seats_Panel.number+" "+Seats_Panel.letter);
// JLabel label19 = new JLabel(Main_Frame.foodType);
// JLabel label20 = new JLabel(eachFlight.COMPANY(Main_Frame.flightNum));
// ===============================================修改前=======================================
// ===============================================修改后=======================================
FlightService flightService = new FlightService(); // 创建航班服务函数
Optional<Flight> optionalFlight = flightService.findFlightById(Main_Frame.flightNum); // 查找对应的航班
Flight flight = optionalFlight.orElse(new Flight()); // 如果航班不存在则创建一个新对象
// 获取Flight对象方法二
// if (optionalFlight.isPresent()) {
// Flight flight = optionalFlight.get();
// }
// 获取航班登机时间
JLabel label16 = new JLabel(flight.getBoarding_time().toLocalDateTime().format(DateTimeFormatter.ofPattern("HH:mm")));
// 获取航班登机口
JLabel label17 = new JLabel(flight.getGate());
// 获取座位位置
JLabel label18 = new JLabel(Seats_Panel.number+" "+Seats_Panel.letter);
// 获取食物类型
JLabel label19 = new JLabel(Main_Frame.foodType);
JLabel label20 = new JLabel(eachFlight.COMPANY(Main_Frame.flightNum));
// 获取航空公司名
JLabel label20 = new JLabel(flight.getAirline_company());
// ===============================================修改后=======================================
// ==================== 设置标签字体和颜色 ====================
// 设置普通文本标签样式
label1.setFont(new Font(Font.DIALOG,Font.PLAIN,25));//Set text font
label1.setForeground(Color.white);//Set text color
label3.setFont(new Font(Font.DIALOG,Font.PLAIN,25));//Set text font
@ -69,6 +109,8 @@ public class Confirm_Panel extends JPanel {
label6.setForeground(Color.white);//Set text color
label8.setFont(new Font(Font.DIALOG,Font.PLAIN,25));//Set text font
label8.setForeground(Color.white);//Set text color
// 设置加粗文本标签样式
label2.setFont(new Font(Font.DIALOG,Font.BOLD,26));//Set text font
label2.setForeground(Color.white);//Set text color
label5.setFont(new Font(Font.DIALOG,Font.BOLD,26));//Set text font
@ -87,6 +129,8 @@ public class Confirm_Panel extends JPanel {
label14.setForeground(Color.white);//Set text color
label15.setFont(new Font(Font.DIALOG,Font.BOLD,26));//Set text font
label15.setForeground(Color.white);//Set text color
// 设置信息显示标签样式(普通字体)
label16.setFont(new Font(Font.DIALOG,Font.PLAIN,26));//Set text font
label16.setForeground(Color.white);//Set text color
label17.setFont(new Font(Font.DIALOG,Font.PLAIN,26));//Set text font
@ -99,26 +143,32 @@ public class Confirm_Panel extends JPanel {
label20.setForeground(Color.white);//Set text color
// ==================== 创建和设置图标 ====================
JLabel icon = new JLabel();
int width = 600,height = 300;//This is the width and height of the picture and JLabel
ImageIcon image = new ImageIcon(Constant.RESOURCE_PATH + "card.png");//Instantiate imageicon object
int width = 600,height = 300;// 图片和JLabel的宽度和高度
ImageIcon image = new ImageIcon(Constant.RESOURCE_PATH + "card.png");// 实例化ImageIcon对象
image.setImage(image.getImage().getScaledInstance(width, height,Image.SCALE_DEFAULT ));
icon.setIcon(image);
// ==================== 设置布局和添加组件 ====================
panel.setLayout(null);// 使用绝对布局
panel.setLayout(null);
// 设置图标位置并添加到面板
icon.setBounds(300,-350,1000,1000);
panel.add(icon);
// 设置信息面板位置并添加到主面板
panel1.setBounds(100,300,1000,150);
panel.add(panel1);
// ==================== 创建特殊需求按钮 ====================
JButton button = new JButton("<html>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SPECIAL<br>REQUIREMENT</html>");//add button
button.setFont(new Font(Font.DIALOG,Font.PLAIN,20));//Set text font
button.setForeground(Color.white);//Set text color
button.setBackground(new Color(218,65,71));//Set background color
// 添加按钮点击事件监听器
button.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
@ -128,6 +178,7 @@ public class Confirm_Panel extends JPanel {
// ==================== 设置提示文本标签位置 ====================
button.setBounds(950,50,170,80);
panel.add(button);
@ -150,6 +201,7 @@ public class Confirm_Panel extends JPanel {
label9.setBounds(610,550,1000,100);
panel.add(label9);
// ==================== 设置信息面板内部布局 ====================
panel1.setLayout(null);
label11.setBounds(400,-20,1000,100);
panel1.add(label11);
@ -172,8 +224,60 @@ public class Confirm_Panel extends JPanel {
label20.setBounds(180,-20,1000,100);
panel1.add(label20);
}
/**
* -
* @param args
*/
public static void main(String[] args) {
// 设置Swing外观为系统默认外观
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
// 创建主框架
JFrame frame = new JFrame("确认面板测试 - Confirm Panel Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1200, 700);
frame.setLocationRelativeTo(null); // 窗口居中显示
// 模拟必要的静态数据(在实际应用中这些数据会从其他面板获取)
//setupTestData();
// 创建确认面板并添加到框架
Confirm_Panel confirmPanel = new Confirm_Panel();
frame.add(confirmPanel);
// 显示窗口
frame.setVisible(true);
System.out.println("确认面板测试程序已启动");
}
/**
* -
*/
private static void setupTestData() {
// 模拟航班号
Main_Frame.flightNum = "CA1234";
// 模拟座位选择
Seats_Panel.number = "15";
Seats_Panel.letter = "A";
// 模拟食物选择
Foods_Panel.food = "Vegetarian Meal";
Main_Frame.foodType = Foods_Panel.food;
// 模拟特殊需求
Main_Frame.req = "No special requirements";
System.out.println("测试数据已设置完成");
System.out.println("航班号: " + Main_Frame.flightNum);
System.out.println("座位: " + Seats_Panel.number + " " + Seats_Panel.letter);
System.out.println("食物: " + Main_Frame.foodType);
}
}
Loading…
Cancel
Save