-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.java
More file actions
62 lines (49 loc) · 1.8 KB
/
GUI.java
File metadata and controls
62 lines (49 loc) · 1.8 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
package GUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GUI extends JFrame {
private static final int LARGHEZZA = 460;
private static final int ALTEZZA = 400;
private JTextField text;
private JButton pulsante1, pulsante2;
public GUI() {
super("Esercizio 5");
setSize(LARGHEZZA, ALTEZZA);
addWindowListener(new DistruttoreFinestra());
setLayout(new BorderLayout());
//Pannello JTextField
JPanel field = new JPanel();
field.setBackground(Color.DARK_GRAY);
field.setLayout(new BorderLayout());
text = new JTextField(8);
field.add(text);
add(field, BorderLayout.NORTH);
//Pannello Operandi
JPanel pannelloOperandi = new JPanel();
pannelloOperandi.setBackground(Color.LIGHT_GRAY);
pannelloOperandi.setLayout(new FlowLayout());
pulsante1 = new JButton("B1");
pulsante1.addActionListener(new Ascoltatore());
pannelloOperandi.add(pulsante1);
pulsante2 = new JButton("B2");
pulsante2.addActionListener(new Ascoltatore());
pannelloOperandi.add(pulsante2);
add(pannelloOperandi, BorderLayout.SOUTH);
}
public static void main(String[] args) {
GUI myGUI = new GUI();
myGUI.setVisible(true);
}
public class Ascoltatore implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("B1")) {
pulsante2.setText(text.getText());
} else if (e.getActionCommand().equals("B2")) {
pulsante1.setText(text.getText());
}
}
}
}