forked from IPC1s2017/TareaFinal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEF4.java
More file actions
79 lines (66 loc) · 2.06 KB
/
Copy pathEF4.java
File metadata and controls
79 lines (66 loc) · 2.06 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
79
package ef4;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
/**
*
* @author lenovo
*/
public class EF4 extends JFrame {
/**
* @param args the command line arguments
*/
JTextField txtentrada= new JTextField();
JButton boton= new JButton("Sumar");
JPanel contentPane= new JPanel();
JLabel label= new JLabel("Resultado");
public static void main(String[] args) {
EF4 ventana = new EF4();
ventana.show();
}
public EF4(){
setSize(250, 300);
setTitle("Sumadora");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
txtentrada.setSize(150,30 );
txtentrada.setLocation(40,95);
//txtentrada.setEnabled(true);
txtentrada.setVisible(true);
contentPane.add(txtentrada);
label.setSize(120, 30);
label.setLocation(50, 175);
label.setVisible(true);
contentPane.add(label);
boton.setSize(100,20);
boton.setLocation(45,150);
boton.setVisible(true);
boton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButtonResult(evt);
}
private void ButtonResult(ActionEvent evt) {
label.setText( getSuma(txtentrada.getText()));
}
});
contentPane.add(boton);
}
public String getSuma(String entrada){
String[] numeros = entrada.split(",");
int suma = 0;
//Realizar suma
for(String numero:numeros)
{
suma+=Integer.parseInt(numero);
}
return suma+"";
}
}