1 package demo9;
2
3 import javax.swing.JPanel;
4 import javax.swing.JLabel;
5 import javax.swing.JTextField;
6
7 import fi.jyu.mit.ohj2.Mjonot;
8 import javax.swing.JCheckBox;
9
10
15 public class PanelSumma extends JPanel {
16
17 private static final long serialVersionUID = 1L;
18 private final JLabel lblB = new JLabel("B = ");
19 private final JTextField textA = new JTextField();
20 private final JLabel lblA = new JLabel("* A + ");
21 private final JTextField textB = new JTextField();
22 private final JLabel lblB_1 = new JLabel("* B");
23 private final JCheckBox cbSummaa = new JCheckBox(" ");
24
25
28 public PanelSumma() {
29 textB.setText("-1.0");
30 textB.setColumns(5);
31 textA.setText("1.0");
32 textA.setColumns(4);
33 cbSummaa.setToolTipText("Valitse lasketaanko t\u00E4m\u00E4 summa");
34
35 add(cbSummaa);
36 add(lblB);
37 add(textA);
38 add(lblA);
39 add(textB);
40 add(lblB_1);
41 }
42
43
44
47 public double getA() {
48 return Mjonot.erotaDouble(textA.getText(), 0.0);
49 }
50
51
52
55 public double getB() {
56 return Mjonot.erotaDouble(textB.getText(), 0.0);
57 }
58
59
60
64 public void setA(double value) {
65 textA.setText(""+value);
66 }
67
68
69
73 public void setB(double value) {
74 textB.setText(""+value);
75 }
76
77
78
81 public boolean isSelected() {
82 return cbSummaa.isSelected();
83 }
84
85
86
90 public void setSelected(boolean value) {
91 cbSummaa.setSelected(value);
92 }
93
94 }
95