-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterlok2.java
More file actions
78 lines (60 loc) · 2.45 KB
/
Interlok2.java
File metadata and controls
78 lines (60 loc) · 2.45 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
package GUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Interlok2 extends JFrame implements ActionListener {
public static final int LARGHEZZA = 460;
public static final int ALTEZZA = 400;
public static final int RIGHE = 25;
public static final int CARATTERI_PER_RIGA = 40;
public JTextField operando1, operando2;
public JTextArea testo;
private String primoOperando = "Ancora nessun testo";
private String secondoOperando = "Ancora nessun testo";
public Interlok2() {
super();
setSize(LARGHEZZA, ALTEZZA);
addWindowListener(new DistruttoreFinestra()); // Ascoltatore anonimo
setTitle("Concatena");
setLayout(new BorderLayout());
//Pannello Operandi
JPanel pannelloOperandi = new JPanel();
pannelloOperandi.setBackground(Color.LIGHT_GRAY);
pannelloOperandi.setLayout(new FlowLayout());
//Primo Text Fiel del primo operando
operando1 = new JTextField(15);
pannelloOperandi.add(operando1);
//Bottone
JButton pulsanteAddizione = new JButton("+");
pulsanteAddizione.addActionListener(this);
pannelloOperandi.add(pulsanteAddizione);
//Secondo Text Field del secondo operando
operando2 = new JTextField(15);
pannelloOperandi.add(operando2);
add(pannelloOperandi, BorderLayout.SOUTH);
//Pannello principale della finestra
JPanel pannelloTesto = new JPanel();
pannelloTesto.setBackground(Color.GRAY);
//Nome della'area di testo
testo = new JTextArea(RIGHE, CARATTERI_PER_RIGA);
testo.setBackground(Color.WHITE);
pannelloTesto.add(testo);
add(pannelloTesto, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e) {
try {
if(e.getActionCommand().equals("+")) {
primoOperando = operando1.getText();
secondoOperando = operando2.getText();
testo.append(primoOperando + " + " + secondoOperando + " = " + (primoOperando + secondoOperando) + "\n");
}
} catch (Exception err) {
System.out.println("Mona, serve uno String!");
}
}
public static void main(String[] args) {
Interlok2 lok = new Interlok2();
lok.setVisible(true);
}
}