-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreateMenu.java
More file actions
95 lines (80 loc) · 3.44 KB
/
CreateMenu.java
File metadata and controls
95 lines (80 loc) · 3.44 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
85
86
87
88
89
90
91
92
93
94
95
import GLOOP.*;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.util.Locale;
import java.util.Objects;
public class CreateMenu {
public CreateMenu() {
final String[] texturePath = {"standart.png"};
JFrame nameFrame = new JFrame();
nameFrame.setSize(200,100);
nameFrame.setVisible(false);
nameFrame.setTitle("Name");
nameFrame.setLocationRelativeTo(null); // Middle of the screen
JPanel namePanel = new JPanel();
namePanel.setLayout(new GridLayout(0,1));
nameFrame.add(namePanel);
JTextField text = new JTextField(1);
text.setBounds(10,10,100,20);
namePanel.add(text);
JTextField answer = new JTextField("This name is already existing!");
answer.setVisible(false);
namePanel.add(answer);
JButton nameButton = new JButton("Ok");
namePanel.add(nameButton);
JFrame frame = new JFrame();
frame.setTitle("Create");
frame.setLocationRelativeTo(null);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(0,1));
String[] items = {"Cube", "Sphere", "Torus", "Cone", "Truncated Cone", "Cylinder"};
JComboBox<String> cb = new JComboBox<>(items);
panel.add(cb);
JFileChooser fileChooser = new JFileChooser();
JButton addTexture = new JButton("Add a texture");
addTexture.addActionListener(e -> {
int returnVal = fileChooser.showOpenDialog(nameFrame); // Opens the fileChooser
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
texturePath[0] = file.getAbsolutePath();
}
});
namePanel.add(addTexture);
JButton button = new JButton("Create");
button.addActionListener(createEvent -> {
nameFrame.setVisible(true);
frame.dispose();
});
panel.add(button);
frame.add(panel);
frame.pack();
frame.setVisible(true);
nameButton.addActionListener(nameEvent -> {
String input = text.getText();
if(Main.objectName.contains(input)) {
answer.setVisible(true); // Makes the answer visible if the name already exists
}
else {
Main.objectName.add(input);
switch (Objects.requireNonNull(cb.getSelectedItem()).toString().toLowerCase(Locale.ROOT)) {
case "cube": Util.createObject(new GLWuerfel(0, 0, 0, 10, texturePath[0]));
break;
case "sphere": Util.createObject(new GLKugel(0, 0, 0, 10, texturePath[0]));
break;
case "torus": Util.createObject(new GLTorus(0, 0, 0, 10, 10, texturePath[0]));
break;
case "cone": Util.createObject(new GLKegel(0, 0, 0, 10, 10, texturePath[0]));
break;
case "truncated cone": Util.createObject(new GLKegelstumpf(0,0,0,10,10,10, texturePath[0]));
break;
case "cylinder": Util.createObject(new GLZylinder(0, 0, 0, 10, 10, texturePath[0]));
break;
default: System.out.println("Tried to create not handheld object");
break;
}
nameFrame.dispose(); // Closes the frame
}
});
}
}