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); 
            } 
        } 
    }

So like, the exact thing you posted yesterday? Except that yesterday you had a different explanation of your problem. I don't know what it means to "make a JButton generate a coding" so you may want to ask clear questions and provide examples, otherwise, you won't get many enlightening replies.

edit: And even if you didn't like the reply I gave you yesterday, if it didn't make sense to you, or you thought it was stupid, you could at least reply back with something clarifying your issue, or disagreeing with me, or whatever. Not replying at all then posting a new thread on what seems to be the same topic is rude IMO.

your code will have to be done here...

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);
}

no auto-generated code... its something you will have to code yourself.

infact its quiet simple... read the binary value as a String... the parse it to int...

Integer.parseInt(string, 2)

I have re-posted this problem on different websites and I am sure I probably didn't see your reply yet. If I have and didn't reply I apologize. I'm not on here to disrespect anyone, but I am on here for assistance. Once again, thank you for any concerns, thoughts, or questions.

Sidebar: This was reposted because my code was changed entirely! I went from having a netbeans generated gui to me actually creating the gui myself! Although I am happy that I have accomplished that feat, I must deal with the problems ahead. When I go into my submenu, a user should be able to type in a number and get it converted into decimal/binary/hexadecimal by clicking on the JButton that 'says Convert to "decimal/binary/hexadecimal" now. This is where my problem comes in.

So like, the exact thing you posted yesterday? Except that yesterday you had a different explanation of your problem. I don't know what it means to "make a JButton generate a coding" so you may want to ask clear questions and provide examples, otherwise, you won't get many enlightening replies.

edit: And even if you didn't like the reply I gave you yesterday, if it didn't make sense to you, or you thought it was stupid, you could at least reply back with something clarifying your issue, or disagreeing with me, or whatever. Not replying at all then posting a new thread on what seems to be the same topic is rude IMO.

This was code I have generated from following tutorials. So are you saying add that one line of code and it will now read the user input as a binary string and convert it to decimal now? I just need more clarification if you don't mind.

your code will have to be done here...

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);
}

no auto-generated code... its something you will have to code yourself.

infact its quiet simple... read the binary value as a String... the parse it to int...

Integer.parseInt(string, 2)

it should work...

String bin = "";
bin = console.readln()
console.writeln(Integer.parseInt(bin , 2))

havent tried it myself

When I did input this code you just gave me, it could not find a symbol for variable console. Any other suggestions Phoenix?

it should work...

String bin = "";
bin = console.readln()
console.writeln(Integer.parseInt(bin , 2))

havent tried it myself

yeah sorry your not using a console app... try assigning the value of a textbox or labe to that

something like
Help with Code Tags
Java Syntax (Toggle Plain Text)

1.
textbox1.setText(Integer.parseInt(bin , 2))

textbox1.setText(Integer.parseInt(bin , 2))
..
remember to create the textbox


if that gives an error... just add .toString() at the end after the (bin, 2)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.