Repository navigation
Expand file tree
/
Copy pathtask12_punkt3.java
More file actions
71 lines (45 loc) · 1.52 KB
/
Copy pathtask12_punkt3.java
File metadata and controls
71 lines (45 loc) · 1.52 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
public class task12_punkt3 extends JFrame implements ActionListener {
Image planet = new ImageIcon("src/planet.jpg").getImage();
JComboBox comboBox;
JLabel label;
// OverlayLayout
//task12_punkt1 task = task12_punkt1;
task12_punkt3() {
//JFrame jf = new JFrame("TEST");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
ArrayList<String> arr = new ArrayList<String>();
for (task12_punkt1 task : task12_punkt1.values()) {
arr.add(task.name());
}
String[] array = arr.toArray(new String[arr.size()]);
comboBox = new JComboBox(array);
label = new JLabel();
this.add(label);
this.pack();
this.setSize(600, 600);
this.setVisible(true);
comboBox.addActionListener(this);
this.add(comboBox);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == comboBox) {
JComboBox cb = (JComboBox)e.getSource();
String msg = (String)cb.getSelectedItem();
for (task12_punkt1 task : task12_punkt1.values()) {
if (msg.equals(task.name())) {
label.setText(task.toString());
}
}
}
}
public static void main(String[] args) {
new task12_punkt3();
}
}