-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExistingFrame.java
More file actions
84 lines (73 loc) · 2.81 KB
/
Copy pathExistingFrame.java
File metadata and controls
84 lines (73 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.io.*;
class ExistingFrame extends JFrame implements ActionListener
{
private JButton backButton, processButton;
public ExistingFrame()
{
setTitle("Existing Data Frame");
setLayout(new BorderLayout());
// setResizable(false);
// setUndecorated(true);
// Set background image
setContentPane(new JLabel(new ImageIcon("Graphics/existing.png")));
// Maximize the frame by default
setExtendedState(JFrame.MAXIMIZED_BOTH);
backButton = new JButton();
backButton.setBorderPainted(true);
backButton.setContentAreaFilled(false);
backButton.addActionListener(this);
backButton.setBounds(10, 20, 45, 40);
add(backButton, BorderLayout.CENTER);
processButton = new JButton();
processButton.setBorderPainted(true);
processButton.setContentAreaFilled(false);
processButton.addActionListener(this);
processButton.setBounds(708, 762, 500, 120);
add(processButton, BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
JLabel label = (JLabel) getContentPane();
label.setIcon(new ImageIcon(new ImageIcon("Graphics/existing.png").getImage().getScaledInstance(getWidth(), getHeight(), Image.SCALE_SMOOTH)));
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
// throw new UnsupportedOperationException("Unimplemented method 'actionPerformed'");
if (e.getSource() == backButton)
{
Main main = new Main();
main.setVisible(true);
dispose();
}
if (e.getSource() == processButton)
{
executePythonScript("embedder.py");
}
}
private void executePythonScript(String scriptName) {
try {
// Change directory to where the Python script is located
String workingDirectory = System.getProperty("user.dir");
ProcessBuilder pb = new ProcessBuilder("python", scriptName);
pb.directory(new File(workingDirectory));
@SuppressWarnings("unused")
Process process = pb.start();
// Uncomment the following line if you want to wait for the script to finish execution
// process.waitFor();
} catch (IOException e) {
e.printStackTrace();
}
}
}