No muestra en la ventana el lblResultado
Publicado por Melvin Hernandez (2 intervenciones) el 25/10/2019 20:53:17
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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class conversor extends JFrame implements ActionListener
{
private JTextField txtValor1;
private JButton btnM_CM, btnCM_M;
private JLabel lblResultado;
public conversor()
{
setLayout(null);
JTextField txtValor1 = new JTextField();
txtValor1.setBounds(10,10,100,30);
add(txtValor1);
JButton btnM_CM = new JButton();
btnM_CM.setBounds(10,50,100,30);
btnM_CM.setText("M a CM");
add(btnM_CM);
JButton btnCM_M = new JButton();
btnCM_M.setBounds(10,90,100,30);
btnCM_M.setText("CM a M");
add(btnCM_M);
JLabel lblResultado = new JLabel();
lblResultado.setBounds(10,150,100,30);
add(lblResultado);
btnM_CM.addActionListener(this);
btnCM_M.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnM_CM)
{
String result;
String valor1 = txtValor1.getText();
int v1 = Integer.parseInt(valor1);
int MaCM = v1 * 100;
result = String.valueOf(MaCM);
lblResultado.setText(result);
}
if(e.getSource()==btnCM_M)
{
String result;
String valor1 = txtValor1.getText();
int v1 = Integer.parseInt(valor1);
int CMaM = v1 / 100;
result = String.valueOf(CMaM);
lblResultado.setText(result);
}
}
public static void main()
{
conversor ventana = new conversor();
ventana.setBounds(0,0,400,600);
ventana.setVisible(true);
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
//Se supone que deberia mostrar, con el label, el resultado de la conversion debajo de los buttons, sin embargo despues de ejecutar no se muestra en la ventana.
Valora esta pregunta


0