como enviar datos de salida a a JTextField
Publicado por julio (5 intervenciones) el 03/09/2019 21:44:25
buenas tengo una pregunta como se envían los datos que se introducen en JTextfield a otro y si me pudieran explicar como introducir números enteros o decimales y sumarlo con JButton
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package grafico1;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
public class Grafico1 extends JFrame{
public JFrame ventana;
public JPanel panel;
public JLabel nombre,apellido,numero1,numero2;
public JTextField entname,entape,ent1,ent2,esultado,nom,apel;
public JTextArea txt;
public JButton salir,aceptar,calcular;
public String a,a1,a2;
public ActionListener x;
public int valor1,valor2;
//public JFrame ventana;
public Grafico1(){
ventana = new JFrame();
setBounds(600,200,500,350);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Operaciones Matematicas");
nombre = new JLabel("nombre:");
nombre.setBounds(10,20,80,20);
entname = new JTextField(20);
entname.setBounds(60,20,80,20);
apellido = new JLabel("apellido:");
apellido.setBounds(10,50,80,20);
entape = new JTextField(20);
entape.setBounds(60,50,80,20);
//resultado
nom = new JTextField("");
nom.setBounds(50,120,80,20);
//entrada en valor entero o double con suma
numero1 = new JLabel("valor 1");
numero1.setBounds(10,80,80,20);
ent1 = new JTextField();
ent1.setBounds(50,80,80,20);
numero2 = new JLabel("valor 2");
numero2.setBounds(10,99,80,20);
ent2 = new JTextField();
ent2.setBounds(50,100,80,20);
calcular = new JButton();
calcular.setBounds(200,40,80,20);
calcular.addActionListener(new a(ent1));
// txt = new JTextArea(10,50);
//txt.setBounds(10,100,200,150);
//txt.setText("");
//txt.append("");
//txt.setEditable(false);
aceptar = new JButton("aceptar");
aceptar.setBounds(200,20,80,20);
aceptar.setVisible(true);
aceptar.setEnabled(true);
aceptar.setMnemonic('a');
aceptar.addActionListener(new x(entname));
aceptar.addActionListener(new x(entape));
panel = new JPanel();
setLayout(null);
add(nombre);
add(apellido);
add(entname);
add(entape);
//add(txt);
add(aceptar);
add(numero1);
add(ent1);
add(numero2);
add(ent2);
add(calcular);
add(nom);
setVisible(true);
}
class x implements ActionListener{
private JTextField edit;
public x(JTextField i){
edit = i;
}
//@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
String dato;
System.out.println(edit.getText());
}
}
//boton de sumar
class a implements ActionListener{
private JTextField suma;
// @Override
public a(JTextField s){
suma = s;
}
public void actionPerformed(ActionEvent e) {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
System.out.println(suma.getText());
}
}
public static void main(String[] args) {
new Grafico1();
}
}
Valora esta pregunta


0