-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculadora.java
142 lines (115 loc) · 3.89 KB
/
Calculadora.java
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package br.com.danilomarcus;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Calculadora {
private JFrame frame;
private JTextField textField;
private JTextField textField_1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Calculadora window = new Calculadora();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Calculadora() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel lblCalculadora = new JLabel("CALCULADORA");
lblCalculadora.setFont(new Font("Tahoma", Font.PLAIN, 50));
lblCalculadora.setBounds(51, 0, 358, 74);
frame.getContentPane().add(lblCalculadora);
JLabel lblNewLabel = new JLabel("Valor1");
lblNewLabel.setBounds(82, 85, 46, 14);
frame.getContentPane().add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Valor2");
lblNewLabel_1.setBounds(82, 124, 46, 14);
frame.getContentPane().add(lblNewLabel_1);
textField = new JTextField();
textField.setBounds(137, 85, 86, 20);
frame.getContentPane().add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setBounds(137, 121, 86, 20);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
JButton btnSomar = new JButton("Somar");
btnSomar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String valor1 = textField.getText();
String valor2 = textField_1.getText();
double val1 = Double.parseDouble(valor1);
double val2 = Double.parseDouble(valor2);
double total = val1 + val2;
JOptionPane.showMessageDialog(null, "A soma é: " + total);
}
});
btnSomar.setBounds(51, 180, 91, 23);
frame.getContentPane().add(btnSomar);
JButton btnSubtrair = new JButton("Subtrair");
btnSubtrair.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String valor1 = textField.getText();
String valor2 = textField_1.getText();
double val1 = Double.parseDouble(valor1);
double val2 = Double.parseDouble(valor2);
double total = val1 - val2;
JOptionPane.showMessageDialog(null, "A subtração é: " + total);
}
});
btnSubtrair.setBounds(154, 180, 91, 23);
frame.getContentPane().add(btnSubtrair);
JButton btnMultiplicar = new JButton("Multiplicar");
btnMultiplicar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String valor1 = textField.getText();
String valor2 = textField_1.getText();
double val1 = Double.parseDouble(valor1);
double val2 = Double.parseDouble(valor2);
double total = val1 * val2;
JOptionPane.showMessageDialog(null, "A multiplicação é: " + total);
}
});
btnMultiplicar.setBounds(51, 213, 91, 23);
frame.getContentPane().add(btnMultiplicar);
JButton btnDividir = new JButton("Dividir");
btnDividir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String valor1 = textField.getText();
String valor2 = textField_1.getText();
double val1 = Double.parseDouble(valor1);
double val2 = Double.parseDouble(valor2);
double total = val1 / val2;
JOptionPane.showMessageDialog(null, "A divisão é: " + total);
}
});
btnDividir.setBounds(154, 213, 91, 23);
frame.getContentPane().add(btnDividir);
}
}