Friday, March 27, 2009
case 1
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.io.*;
import java.text.DecimalFormat;
import javax.swing.*;
import java.lang.*;
import java.util.*;
public class BinaryOperations extends JFrame {
JFrame h = new JFrame();
JPanel p6 = new JPanel();
JPanel p1 = new JPanel();
JLabel fnumber = new JLabel(" First Number:");
JTextField num = new JTextField("");
JLabel binary = new JLabel(" Binary:");
JLabel bin = new JLabel("");
JLabel snumber = new JLabel(" Second Number:");
JTextField num1 = new JTextField("");
JLabel binary1 = new JLabel(" Binary:");
JLabel bin1 = new JLabel("");
JLabel total = new JLabel(" Total:");
JTextField num2 = new JTextField("");
JLabel binary2 = new JLabel(" Binary:");
JLabel bin2 = new JLabel("");
JButton add1 = new JButton("+");
JButton minus = new JButton("-");
JButton multiply = new JButton("*");
JButton divide = new JButton("/");
public static void main(String args[]) {
BinaryOperations Layout = new BinaryOperations();
}
public BinaryOperations( )
{
p1.setLayout(new GridLayout(2, 1));
p6.setLayout(new GridLayout(2, 1));
p1.add(fnumber);
p1.add(num);
num.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int numbers = Integer.parseInt(num.getText());
int array[] = { 128, 64, 32, 16, 8, 4, 2, 1 };
String binaryconvert = "";
for(int i = 0; i <>= array[i])
{
numbers = numbers - array[i];
binaryconvert = binaryconvert + "1";
}
else
binaryconvert = binaryconvert + "0";
}
bin.setText(binaryconvert);
}
}
);
p1.add(binary);
p1.add(bin);
p1.add(snumber);
p1.add(num1);
num1.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int numbers = Integer.parseInt(num1.getText());
int array[] = { 128, 64, 32, 16, 8, 4, 2, 1 };
String binaryconvert = "";
for(int i = 0; i <>= array[i])
{
numbers = numbers - array[i];
binaryconvert = binaryconvert + "1";
}
else
binaryconvert = binaryconvert + "0";
}
bin1.setText(binaryconvert);
}
}
);
p1.add(binary1);
p1.add(bin1);
p6.add(total);
p6.add(num2);
p6.add(binary2);
p6.add(bin2);
p6.add(add1);
add1.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int number1 = Integer.parseInt(num.getText());
int number2 = Integer.parseInt(num1.getText());
int numbers = number1 + number2;
num2.setText(String.valueOf(numbers));
int array[] = { 128, 64, 32, 16, 8, 4, 2, 1 };
String binaryconvert = "";
for(int i = 0; i <>= array[i])
{
numbers = numbers - array[i];
binaryconvert = binaryconvert + "1";
}
else
binaryconvert = binaryconvert + "0";
}
bin2.setText(binaryconvert);
}
}
);
p6.add(minus);
minus.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int number1 = Integer.parseInt(num.getText());
int number2 = Integer.parseInt(num1.getText());
int numbers = number1 - number2;
num2.setText(String.valueOf(numbers));
int array[] = { 128, 64, 32, 16, 8, 4, 2, 1 };
String binaryconvert = "";
for(int i = 0; i <>= array[i])
{
numbers = numbers - array[i];
binaryconvert = binaryconvert + "1";
}
else
binaryconvert = binaryconvert + "0";
}
bin2.setText(binaryconvert);
}
}
);
p6.add(multiply);
multiply.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int number1 = Integer.parseInt(num.getText());
int number2 = Integer.parseInt(num1.getText());
int numbers = number1 * number2;
num2.setText(String.valueOf(numbers));
int array[] = { 128, 64, 32, 16, 8, 4, 2, 1 };
String binaryconvert = "";
for(int i = 0; i <>= array[i])
{
numbers = numbers - array[i];
binaryconvert = binaryconvert + "1";
}
else
binaryconvert = binaryconvert + "0";
}
bin2.setText(binaryconvert);
}
}
);
p6.add(divide);
divide.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int number1 = Integer.parseInt(num.getText());
int number2 = Integer.parseInt(num1.getText());
int numbers = number1 / number2;
num2.setText(String.valueOf(numbers));
int array[] = { 128, 64, 32, 16, 8, 4, 2, 1 };
String binaryconvert = "";
for(int i = 0; i <>= array[i])
{
numbers = numbers - array[i];
binaryconvert = binaryconvert + "1";
}
else
binaryconvert = binaryconvert + "0";
}
bin2.setText(binaryconvert);
}
}
);
add(p1, "North");
setSize(580, 150);
setTitle("Binary Conversion");
setVisible(true);
add(p6, "South");
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment