-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswing.java
More file actions
52 lines (44 loc) · 1.57 KB
/
Copy pathswing.java
File metadata and controls
52 lines (44 loc) · 1.57 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
package swing;
import javax.swing.*;
public class MainForm {
private JTextPane pricePane;
private JTextPane taxPane;
private JTextPane totalPane;
private JButton Calculate;
public ActionListener botonPulsado(){
return actionPerformed(ActionEvent e){
}
}
public MainForm () {
Calculate.addActionListener(new ActionListener() {
@override
public void actionPerformed(ActionEvent e){
boolean comprobacion = false;
double precio = 0;
while (!comprobacion){
try {
precio = Double.ParseDouble(pricePane.getText());
comprobacion = true;
pricePane.setText(precio);
} catch (NumberFormatException e){
System.out.println("error no se puede convertir texto en double tiene que digitar un numero tipo double con decimales");
}
}
}
});
pricePane.addKeyListener(new KeyAdapter() {
@override // sobre escribe metodos genericos
public void keyTyped(KeyEvent e){
super.keyTypad(e);
pricePane.getText();
String valorPrecio = pricePane.getText() + "ñ";
pricePane.setText(valorPrecio);
}
});
}
public static void main(string []args) {
JFrame frame = new JFrame("swingTax");
frame.setContentPane(new MainForm().taxPane);
frame.setVisible(true);
}
}