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
| import java.awt.Container;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class View {
JTextField input = new JTextField();
JTextField output = new JTextField();
JButton button = new JButton("Umrechnen");
JComboBox startsystem = new JComboBox();
JComboBox zielsystem = new JComboBox();
public View() {
JFrame frame = new JFrame("Zahlenrechner");
Container cp = frame.getContentPane();
cp.setLayout(null);
cp.setFocusable(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(280, 140);
input.setBounds(10, 10, 130, 25);
cp.add(input);
output.setBounds(10, 40, 130, 25);
cp.add(output);
startsystem.setBounds(150, 10, 100, 25);
cp.add(startsystem);
zielsystem.setBounds(150, 40, 100, 25);
cp.add(zielsystem);
fillLists();
button.setMargin(new Insets(5, 5, 5, 5));
button.setBounds(10, 70, 130, 25);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
int start = 2+startsystem.getSelectedIndex();
int ziel = 2+zielsystem.getSelectedIndex();
String in = input.getText();
Model m = new Model();
output.setText(m.rechne(m.zuDezimal(in, start), ziel));
}
});
cp.add(button);
frame.setVisible(true);
}
public void fillLists(){
String[] namen = {"2 (binär)", "3", "4", "5", "6", "7",
"8 (oktal)", "9", "10 (dezimal)", "11",
"12", "13", "14", "15", "16 (hexadezimal)",
"17", "18", "19", "20", "21", "22", "23",
"24", "25", "26", "27", "28", "29", "30",
"31", "32", "33", "34", "35", "36"};
for (int i = 0; i < namen.length; i++) {
startsystem.addItem(namen[i]);
zielsystem.addItem(namen[i]);
}
}
public static void main(String[] args) {
new View();
}
}
|