-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyFrame.java
More file actions
52 lines (41 loc) · 1.35 KB
/
MyFrame.java
File metadata and controls
52 lines (41 loc) · 1.35 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
package GUI;
import java.awt.*;
import java.awt.event.*;
public class MyFrame extends Frame {
private Choice c = new Choice();
private Panel p1 = new Panel();
private Panel p2 = new Panel();
private TextArea t = new TextArea(10,20 );
private Button b = new Button("Ripeti");
private TextField f = new TextField();
public MyFrame() {
super("MioFrame");
p1.add(f);
p1.add(c);
this.add(p1, "North");
this.add(t, "Center");
p2.add(b);
this.add(p2, "South");
c.add("*");
c.add("#");
this.setVisible(true);
this.pack();
AscoltaScelta listener = new AscoltaScelta(c,t); //Riceve due parametri di tipo Choice e TextArea
c.addItemListener(listener);
AscoltaPulsante ascoltatore = new AscoltaPulsante();
b.addActionListener(ascoltatore);
}
public static void main(String[] args) {
new MyFrame();
}
public class AscoltaPulsante implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("Ripeti")) {
int n = Integer.parseInt(f.getText());
for(int i = 1; i <= n; i++) {
t.append(t.getText());
}
}
}
}
}