From 8e20d43e045c391b7f757ede726d7fec9cbb022e Mon Sep 17 00:00:00 2001 From: fdai6499 Date: Fri, 10 Feb 2023 13:18:44 +0100 Subject: [PATCH] new ntoi function --- src/main/java/src/TasksFrame.java | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index 7932b72..354605c 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -64,6 +64,8 @@ public class TasksFrame extends JFrame { public void run() { + setupAtoi(); + setupFib(); setupHelloWorld(); @@ -113,6 +115,62 @@ public class TasksFrame extends JFrame { setupReverse(); } + private void setupAtoi(){ + JPanel jPanel = setupPanel("atoi"); + + JLabel jLabel = new JLabel(); + jLabel.setVisible(true); + jLabel.setText("Enter a Integer and get and a Bit"); + jPanel.setBounds(5, 20, 200, 30); + jPanel.add(jLabel); + + JTextField input = new JTextField(); + input.setVisible(true); + input.setBounds(5, 30, 200, 30); + jPanel.add(input); + + JTextField output = new JTextField(); + output.setVisible(true); + output.setBounds(5, 60, 200, 30); + jPanel.add(output); + + JButton jButton = new JButton("iton"); + jButton.setVisible(true); + jButton.setBounds(210, 30, 100, 30); + jPanel.add(jButton); + jButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String text = input.getText(); + int value = Integer.valueOf(text); + + String binary = calcAtoi(value); + output.setText(binary); + + } + }); + +// JButton jButton2 = new JButton("ntoi"); +// jButton2.setVisible(true); +// jButton2.setBounds(210, 30, 100, 30); +// jPanel.add(jButton2); +// jButton2.addActionListener(new ActionListener() { +// @Override +// public void actionPerformed(ActionEvent e) { +// String text = output.getText(); +// int value = Integer.valueOf(text); +// +// String binary = calcAtoi(value); +// output.setText(binary); +// +// } +// }); + } + + public String calcAtoi(int value) { + return Integer.toBinaryString(value); + } + private void setupFib() { JPanel jPanel = setupPanel("Fibonacci");