package window;
|
|
import java.awt.*;
|
import java.sql.Connection;
|
import javax.swing.*;
|
import javax.swing.border.EmptyBorder;
|
import java.util.ResourceBundle;
|
|
public class WindowFactory {
|
|
@SuppressWarnings("unused")
|
private static JPanel createWelcomePanel(ResourceBundle messages, Connection conn) {
|
JPanel panel = new JPanel(new BorderLayout());
|
|
JLabel titleLabel = new JLabel(messages.getString("APP_NAME"), SwingConstants.CENTER);
|
titleLabel.setFont(new Font("΢ÈíÑźÚ", Font.BOLD, 36));
|
titleLabel.setForeground(new Color(0, 120, 215));
|
titleLabel.setBorder(new EmptyBorder(50, 0, 20, 0));
|
|
JLabel subtitleLabel = new JLabel(messages.getString("WELCOME_MSG"), SwingConstants.CENTER);
|
subtitleLabel.setFont(new Font("΢ÈíÑźÚ", Font.PLAIN, 24));
|
subtitleLabel.setForeground(new Color(100, 100, 100));
|
|
JPanel infoPanel = new JPanel(new GridLayout(0, 1, 10, 10));
|
infoPanel.setBorder(new EmptyBorder(30, 100, 30, 100));
|
|
infoPanel.add(createInfoLabel(messages.getString("SYSTEM_STATUS"),
|
messages.getString("RUNNING_NORMAL"),
|
Color.GREEN.darker()));
|
|
infoPanel.add(createInfoLabel(messages.getString("DB_CONNECTION"),
|
conn != null ? messages.getString("CONNECTED") : messages.getString("DISCONNECTED"),
|
conn != null ? Color.GREEN.darker() : Color.RED));
|
|
try {
|
if (conn != null) {
|
try (java.sql.Statement stmt = conn.createStatement();
|
java.sql.ResultSet rs = stmt.executeQuery("SELECT VERSION()")) {
|
if (rs.next()) {
|
infoPanel.add(createInfoLabel(messages.getString("DB_VERSION"),
|
rs.getString(1),
|
Color.BLUE));
|
}
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
infoPanel.add(createInfoLabel(messages.getString("CURRENT_USER"),
|
messages.getString("ADMIN"),
|
Color.BLUE));
|
|
infoPanel.add(createInfoLabel(messages.getString("SYSTEM_TIME"),
|
new java.util.Date().toString(),
|
Color.BLUE));
|
|
panel.add(titleLabel, BorderLayout.NORTH);
|
panel.add(subtitleLabel, BorderLayout.CENTER);
|
panel.add(infoPanel, BorderLayout.SOUTH);
|
|
return panel;
|
}
|
|
private static JLabel createInfoLabel(String title, String value, Color color) {
|
JLabel label = new JLabel("<html><b>" + title + ":</b> " + value + "</html>");
|
label.setFont(new Font("΢ÈíÑźÚ", Font.PLAIN, 18));
|
label.setForeground(color);
|
return label;
|
}
|
|
public static JInternalFrame createWelcomeFrame(ResourceBundle messages, Connection conn) {
|
return new WelcomeFrame(messages, conn);
|
}
|
|
public static JInternalFrame createFunctionFrame(String title) {
|
JInternalFrame frame = new JInternalFrame(
|
title, true, true, true, true);
|
frame.setSize(600, 400);
|
frame.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
|
frame.setLocation(0, 0);
|
|
frame.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
|
|
frame.setMaximizable(true);
|
frame.setIconifiable(true);
|
frame.setClosable(true);
|
return frame;
|
}
|
}
|