private static void openMainFrame() {
JFrame mainFrame = new JFrame("Fruitz Client");
mainFrame.setSize(400, 400);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setLocationRelativeTo(null);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(null);
mainPanel.setBackground(new Color(20, 20, 20));
JLabel titleLabel = new JLabel("Fruitz Client", SwingConstants.CENTER);
titleLabel.setForeground(Color.WHITE);
titleLabel.setFont(new Font("Arial", Font.BOLD, 28));
titleLabel.setBounds(0, 50, 400, 40);
mainPanel.add(titleLabel);
String[] versions = { "1.16.5", "1.21.1" };
JComboBox<String> versionSelect = new JComboBox<>(versions);
versionSelect.setBounds(100, 200, 200, 35);
versionSelect.setBackground(new Color(45, 45, 45));
versionSelect.setForeground(Color.WHITE);
versionSelect.setFont(new Font("Arial", Font.BOLD, 14));
versionSelect.setFocusable(false);
versionSelect.setBorder(BorderFactory.createLineBorder(new Color(80, 80, 80), 1));
mainPanel.add(versionSelect);
JButton runButton = new JButton("Запустить");
runButton.setBounds(100, 260, 200, 40);
runButton.setFont(new Font("Arial", Font.BOLD, 14));
runButton.setForeground(Color.WHITE);
runButton.setBackground(new Color(60, 160, 60));
runButton.setFocusPainted(false);
runButton.setBorderPainted(false);
runButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
runButton.addActionListener(e -> {
try {
String dirPath = "C:\\FruitzClient";
String fileUrl = "http://localhost:3000/client.jar";
String filePath = dirPath + "\\client.jar";
ProcessDetect.mainProcess();
Files.createDirectories(Paths.get(dirPath));
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(fileUrl))
.build();
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
Files.copy(response.body(), Paths.get(filePath), StandardCopyOption.REPLACE_EXISTING);
new ProcessBuilder("java", "-jar", filePath).start();
} catch (Exception ex) {
ex.printStackTrace();
}
});
mainPanel.add(runButton);
mainFrame.add(mainPanel);
mainFrame.setResizable(false);
mainFrame.setVisible(true);
}