
Actualizar JLabel desde Clase
Publicado por Alex (1 intervención) el 25/08/2015 08:29:18
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
---------- // MAIN CLASS
package gui;
public class Gui {
public static void main(String[] args) {
Myframe a = new Myframe();
a.My_frame();
prints b = new prints();
b.Counter();
}
}
-------- // JFRAME
package gui;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public class Myframe extends JFrame {
public JLabel Label;
Myframe(){}
public void My_frame(){
prints m = new prints();
JFrame screen = new JFrame("Test");
screen.setSize(1024, 768);
screen.setExtendedState(JFrame.MAXIMIZED_BOTH);
screen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Label = new JLabel("Orginal Text", JLabel.LEFT);
screen.add(Label);
screen.setVisible(true);
screen.add(Label);
}
public void c_text(String text) {
Label.setText(text);
System.out.print(text);
}
}
------ // LOOP
package gui;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class prints extends JFrame{
prints() { }
public void Counter(){
int x = 20;
for(int i =0; i < 21; i++){
System.out.println(i);
Myframe f = new Myframe();
String n = Integer.toString(i);
f.c_text(n);
}
}
}
Prácticamente lo que quiero lograr es que el label se actualice con el resultado, una vez que esta iniciado el jframe no puedo acceder al elemento, si creo un nuevo jframe ( My_frame() ) y le paso el valor desde el loop a Label me crea ventanas nuevas y el valor si se actualiza pero es lo que no quiero crear miles de ventanas... no se que estoy haciendo mal.
Muchas gracias de antemano.
Valora esta pregunta


0