I am currently writing a program in Netbeans which will perform binary to decimal, decimal to binary, hexadecimal to decimal, decimal to hexadecimal conversions, 1's compliment, 2's compliment, and show the list of boolean algebra rules.
I have created the GUI however, I cannot figure out how to make the Jbuttons generate the coding needed for a binary to decimal conversion of the input in a JTextField. The code is below:
package swing1;
/**
*
* @author James
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.io.*;
public class swing {
public static void main (String[] args) {
JFrame frame = new JFrame("Computer Architecture Conversions");
frame.setVisible(true);
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel ();
frame.add(panel);
JButton button = new JButton ("Binary to Decimal") ;
JButton button2 = new JButton ("Decimal to Binary");
JButton button3 = new JButton ("Decimal to Hexadecimal");
JButton button4 = new JButton ("Hexadecimal to Decimal");
JButton button5 = new JButton ("Library of Boolean Algebra Rules");
JButton button6 = new JButton ("1's Complement");
JButton button7 = new JButton ("2's Complement");
panel.add(button);
panel.add(button2);
panel.add(button3);
panel.add(button4);
panel.add(button5);
panel.add(button6);
panel.add(button7);
button.addActionListener(new Action());
button2.addActionListener(new Action2());
button3.addActionListener(new Action3());
button4.addActionListener(new Action4());
button5.addActionListener(new Action5());
button6.addActionListener(new Action6());
button7.addActionListener(new Action7());
}
static class Action implements ActionListener{
public void actionPerformed (ActionEvent e){
JFrame frame2 = new JFrame ("Binary to Decimal Conversion");
frame2.setVisible(true);
frame2.setSize(500,300);
JLabel label = new JLabel ("Binary");
JPanel panel = new JPanel();
JButton b2d = new JButton("Convert to Decimal Now!");
JTextField text = new JTextField(25);
frame2.add(panel);
panel.add(text);
panel.add(label);
panel.add(b2d);
}
}
static class Action2 implements ActionListener{
public void actionPerformed (ActionEvent e){
JFrame frame3 = new JFrame ("Decimal to Binary Conversion");
frame3.setVisible(true);
frame3.setSize(500,300);
JLabel label = new JLabel ("Decimal");
JPanel panel = new JPanel();
JButton d2b = new JButton("Convert to Binary Now!");
JTextField text = new JTextField(25);
frame3.add(panel);
panel.add(text);
panel.add(label);
panel.add(d2b);
class Actiond2b implements ActionListener{
public void actionPerformed (ActionEvent e){
int result = Integer.parseInt(JTextField.getText(Integer.toBinaryString(i)));
}
}
d2b.addActionListener(new Actiond2b());
}
}
}
}
static class Action3 implements ActionListener{
public void actionPerformed (ActionEvent e){
JFrame frame4 = new JFrame ("Decimal to Hexadecimal Conversion");
frame4.setVisible(true);
frame4.setSize(500,300);
JLabel label = new JLabel ("Decimal");
JPanel panel = new JPanel();
JButton d2h = new JButton("Convert to Hexadecimal Now!");
JTextField text = new JTextField(25);
frame4.add(panel);
panel.add(text);
panel.add(label);
panel.add(d2h);
}
}
static class Action4 implements ActionListener{
public void actionPerformed (ActionEvent e){
JFrame frame5 = new JFrame ("Hexadecimal to Decimal Conversion");
frame5.setVisible(true);
frame5.setSize(500,300);
JLabel label = new JLabel ("Hexadecimal");
JPanel panel = new JPanel();
JButton h2d = new JButton("Convert to Decimal Now!");
JTextField text = new JTextField(25);
frame5.add(panel);
panel.add(text);
panel.add(label);
panel.add(h2d);
}
}
static class Action5 implements ActionListener{
public void actionPerformed (ActionEvent e){
JFrame frame6 = new JFrame ("Library of Boolean Algebra Rules");
frame6.setVisible(true);
frame6.setSize(500,300);
JLabel label = new JLabel ("You clicked me!");
JPanel panel = new JPanel();
frame6.add(panel);
panel.add(label);
}
}
static class Action6 implements ActionListener{
public void actionPerformed (ActionEvent e){
JFrame frame7 = new JFrame ("1's Complement Conversion");
frame7.setVisible(true);
frame7.setSize(500,300);
JLabel label = new JLabel ("You clicked me!");
JPanel panel = new JPanel();
frame7.add(panel);
panel.add(label);
}
}
static class Action7 implements ActionListener{
public void actionPerformed (ActionEvent e){
JFrame frame8 = new JFrame ("2's Complement Conversion");
frame8.setVisible(true);
frame8.setSize(500,300);
JLabel label = new JLabel ("You clicked me!");
JPanel panel = new JPanel();
frame8.add(panel);
panel.add(label);
}
}
}