Browse Source

new ntoi function

main
fdai6499 2 years ago
committed by fdai6040
parent
commit
8e20d43e04
  1. 58
      src/main/java/src/TasksFrame.java

58
src/main/java/src/TasksFrame.java

@ -64,6 +64,8 @@ public class TasksFrame extends JFrame {
public void run() { public void run() {
setupAtoi();
setupFib(); setupFib();
setupHelloWorld(); setupHelloWorld();
@ -113,6 +115,62 @@ public class TasksFrame extends JFrame {
setupReverse(); 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() { private void setupFib() {
JPanel jPanel = setupPanel("Fibonacci"); JPanel jPanel = setupPanel("Fibonacci");

Loading…
Cancel
Save