Main Page | Report Page

 

  Computers Forum Index » Computer Languages (Java - Advocacy) » Java Programming Help (conversions)...

Author Message
Murph25...
Posted: Wed Mar 17, 2010 5:37 pm
 
I am currently writing a program 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 the corresponding JTextField. Please help me. The code
is below:



package swing1;

/**
*
* at (no spam) 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);

}
}

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);
}
}
}
 
John B. Matthews...
Posted: Wed Mar 17, 2010 10:15 pm
 
In article
<d2279b97-a3c3-4d43-95cb-cc8c0febdd0d at (no spam) t23g2000yqt.googlegroups.com>,
Murph25 <jxmst32 at (no spam) mail.rmu.edu> wrote:

Quote:
I am currently writing a program which will perform binary to
decimal, decimal to binary, hexadecimal to decimal, decimal to
hexadecimal conversions, 1's complement, 2's complement, 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 the corresponding JTextField. Please help
me. The code is below:

....
button7.addActionListener(new Action7());
frame.pack();
frame.setVisible(true);
}
....

Also, build your GUI on the EDT:

<http://java.sun.com/docs/books/tutorial/uiswing/concurrency/initial.html>

[Followup-To: comp.lang.java.gui]
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Roedy Green...
Posted: Thu Mar 18, 2010 12:43 pm
 
On Wed, 17 Mar 2010 10:37:08 -0700 (PDT), Murph25
<jxmst32 at (no spam) mail.rmu.edu> wrote, quoted or indirectly quoted someone who
said :

Quote:
I am currently writing a program 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.

ints and longs are binary internally. What you are doing is creating
various Strings that display them as a string of characters for humans
in various number bases. Keep that foremost in mind. If you forget
it, you will quickly get discombobulated.

See http://mindprod.com/jgloss/hex.html
http://mindprod.com/jgloss/radix.html
http://mindprod.com/jgloss/binary.html

You are complementing (enhancing), not complimenting (flattering).
--
Roedy Green Canadian Mind Products
http://mindprod.com

Responsible Development is the style of development I aspire to now. It can be summarized by answering the question, How would I develop if it were my money? Im amazed how many theoretical arguments evaporate when faced with this question.
~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming.
 
 
Page 1 of 1    
All times are GMT
The time now is Tue Sep 02, 2014 4:26 am