Browse Source

new Task "Dezimal nach binär" added

remotes/origin/develop
fdai6040 2 years ago
parent
commit
52b884d4b6
  1. 52
      src/main/java/src/TasksFrame.java

52
src/main/java/src/TasksFrame.java

@ -82,9 +82,61 @@ public class TasksFrame extends JFrame {
setupKgV();
setupRoundSum();
setupUmrechnen();
}
private void setupUmrechnen() {
JPanel jPanel = setupPanel("Dezimal nach Binär");
JButton button = new JButton("calculate");
button.setVisible(true);
button.setBounds(10, 65, 100, 30);
button.setForeground(Color.WHITE);
button.setBackground(Color.BLUE);
JTextField jTextField = new JTextField();
jTextField.setVisible(true);
jTextField.setBounds( 10, 40, 30, 20);
jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12));
JLabel jLabel = new JLabel();
jLabel.setVisible(true);
jLabel.setBounds(10, 90, 60, 30);
jPanel.add(button);
jPanel.add(jTextField);
jPanel.add(jLabel);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String text = jTextField.getText();
Integer val = Integer.valueOf(text);
int res = Integer.valueOf(umrechnen(val));
jLabel.setText(String.valueOf(res));
}
});
}
public String umrechnen(int dez) {
String binaer = "";
while (dez > 0) {
if (dez % 2 == 0) {
binaer = "0" + binaer;
}
if (dez % 2 == 1) {
binaer = "1" + binaer;
}
dez = dez / 2;
}
return binaer;
}
private void setupRoundSum() {
JPanel jPanel = setupPanel("Runde Summe");

Loading…
Cancel
Save