IISPL - Indian Institute Of Software Programming Language

IT Education & Training

Java Project with source code - A program to identify decimal To Roman using frame and awt package

Jun 062016

Save This file ConvertDec.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ConvertDec extends JFrame{
public JLabel alabel,blabel,clabel;
public JPanel x,down,alien,last;
public JTextField screenfield;
public ButtonGroup radioGroup;
JRadioButton on,off;
FlowLayout rd;
JButton b;
NumberUsed polly=new NumberUsed();
public ConvertDec(){
super("Leonard Converter");

Container can=getContentPane();
can.setLayout(new FlowLayout());
Icon bendz=new ImageIcon( "cute.jpg");
alabel=new JLabel(bendz,SwingConstants.CENTER);
alabel.setToolTipText( "IISPL BS Computer Science II-B");
can.add(alabel);
Icon leon=new ImageIcon( "cute1.jpg");
blabel=new JLabel(leon,SwingConstants.RIGHT);
blabel.setToolTipText( "Leonard Bendal 085-Prk 5 Brgy.3 EM's Bo. East Leg. City (052)820-46-40");
can.add(blabel);
last=new JPanel();
clabel=new JLabel("CS13 PROJECT");
last.add(clabel);
can.add(last);

x=polly.s;
can.add(x);

b=new JButton();
b=polly.leftbutton1;

rd=new FlowLayout();
down=new JPanel();
down.setLayout(rd);
on=new JRadioButton("ON",true);
on.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent event){
NumberUsed polly1=new NumberUsed();
polly1=polly;
if(on.isSelected()){
polly1.leftbutton1.setEnabled(true);
polly1.centerbutton1.setEnabled(true);
polly1.rightbutton1.setEnabled(true);
polly1.leftbutton2.setEnabled(true);
polly1.centerbutton2.setEnabled(true);
polly1.rightbutton2.setEnabled(true);
polly1.leftbutton3.setEnabled(true);
polly1.centerbutton3.setEnabled(true);
polly1.rightbutton3.setEnabled(true);
polly1.leftbutton4.setEnabled(true);
polly1.centerbutton4.setEnabled(true);
polly1.rightbutton4.setEnabled(true);
polly1.bendal="";
polly1.currentNumber=0;
}
}
});
down.add(on);
off=new JRadioButton("OFF",false);
off.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
NumberUsed polly1=new NumberUsed();
polly1=polly;
polly1.leftbutton1.setEnabled(false);
polly1.centerbutton1.setEnabled(false);
polly1.rightbutton1.setEnabled(false);
polly1.leftbutton2.setEnabled(false);
polly1.centerbutton2.setEnabled(false);
polly1.rightbutton2.setEnabled(false);
polly1.leftbutton3.setEnabled(false);
polly1.centerbutton3.setEnabled(false);
polly1.rightbutton3.setEnabled(false);
polly1.leftbutton4.setEnabled(false);
polly1.centerbutton4.setEnabled(false);
polly1.rightbutton4.setEnabled(false);
polly1.bend.setText("");
polly1.bendal="";
polly1.currentNumber=0;
}
});
down.add(off);
radioGroup=new ButtonGroup();
radioGroup.add(on);
radioGroup.add(off);
can.add(down);

can.add(polly.xpanel);
can.add(polly.ypanel);
can.add(polly.zpanel);
can.add(polly.lpanel);


setSize(300,550);
setVisible(true);
}

public static void main(String args[]){
ConvertDec Apply=new ConvertDec();
Apply.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

 

Second File To Be Saved NumberUsed.java


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class NumberUsed{
public JButton leftbutton1,centerbutton1,rightbutton1;
public JButton leftbutton2,centerbutton2,rightbutton2;
public JButton leftbutton3,centerbutton3,rightbutton3;
public JButton leftbutton4,centerbutton4,rightbutton4;
public JPanel lpanel,xpanel,ypanel,zpanel,s;
FlowLayout Dec1,Dec2,Dec3,Dec4;
public JTextField bend;

boolean isfirstNumber=true;
public int currentNumber=0;

public String bendal="";

public NumberUsed (){

s=new JPanel();
bend=new JTextField(bendal,20);
bend.setEditable(false);
s.add(bend);

Dec1=new FlowLayout();
xpanel=new JPanel();
xpanel.setLayout(Dec1);

leftbutton1=new JButton( " 1 " );
leftbutton1.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
int num;
if(isfirstNumber){
isfirstNumber=!isfirstNumber;
num=(currentNumber*10)+1;
currentNumber=1;
bendal+="1";
bend.setText(bendal);
}else{
num=(currentNumber*10)+1;
bendal+="1";
currentNumber=num;
bend.setText(bendal);
}

}
}
);
xpanel.add(leftbutton1);


centerbutton1=new JButton( " 2 " );
centerbutton1.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
int num;
if(isfirstNumber){
isfirstNumber=!isfirstNumber;
num=(currentNumber*10)+2;
currentNumber=1;
bendal+="2";
bend.setText(bendal);
}else{
num=(currentNumber*10)+2;
bendal+="2";
currentNumber=num;
bend.setText(bendal);
}
}
}
);
xpanel.add(centerbutton1);

rightbutton1=new JButton( " 3 " );
rightbutton1.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
int num;
if(isfirstNumber){
isfirstNumber=!isfirstNumber;
num=(currentNumber*10)+3;
currentNumber=3;
bendal+="3";
bend.setText(bendal);
}else{
num=(currentNumber*10)+3;
bendal+="3";
currentNumber=num;
bend.setText(bendal);
}
}
}
);
xpanel.add(rightbutton1);


Dec2=new FlowLayout();
ypanel=new JPanel();
ypanel.setLayout(Dec2);

leftbutton2=new JButton( " 4 " );
leftbutton2.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
int num;
if(isfirstNumber){
isfirstNumber=!isfirstNumber;
num=(currentNumber*10)+4;
currentNumber=4;
bendal+="4";
bend.setText(bendal);
}else{
num=(currentNumber*10)+4;
bendal+="4";
currentNumber=num;
bend.setText(bendal);
}
}
}
);
ypanel.add(leftbutton2);

centerbutton2=new JButton( " 5 " );
centerbutton2.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
int num;
if(isfirstNumber){
isfirstNumber=!isfirstNumber;
num=(currentNumber*10)+5;
currentNumber=5;
bendal+="5";
bend.setText(bendal);
}else{
num=(currentNumber*10)+5;
bendal+="5";
currentNumber=num;
bend.setText(bendal);
}
}
}
);
ypanel.add(centerbutton2);

rightbutton2=new JButton( " 6 " );
rightbutton2.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
int num;
if(isfirstNumber){
isfirstNumber=!isfirstNumber;
num=(currentNumber*10)+6;
currentNumber=6;
bendal+="6";
bend.setText(bendal);
}else{
num=(currentNumber*10)+6;
bendal+="6";
currentNumber=num;
bend.setText(bendal);
}

}
}
);
ypanel.add(rightbutton2);

Dec3=new FlowLayout();
zpanel=new JPanel();
zpanel.setLayout(Dec3);

leftbutton3=new JButton( " 7 " );
leftbutton3.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
int num;
if(isfirstNumber){
isfirstNumber=!isfirstNumber;
num=(currentNumber*10)+7;
currentNumber=7;
bendal+="7";
bend.setText(bendal);
}else{
num=(currentNumber*10)+7;
bendal+="7";
currentNumber=num;
bend.setText(bendal);
}
}
}
);
zpanel.add(leftbutton3);

centerbutton3=new JButton( " 8 " );
centerbutton3.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
int num;
if(isfirstNumber){
isfirstNumber=!isfirstNumber;
num=(currentNumber*10)+8;
currentNumber=8;
bendal+="8";
bend.setText(bendal);
}else{
num=(currentNumber*10)+8;
bendal+="8";
currentNumber=num;
bend.setText(bendal);
}
}
}
);
zpanel.add(centerbutton3);

rightbutton3=new JButton( " 9 " );
rightbutton3.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
int num;
if(isfirstNumber){
isfirstNumber=!isfirstNumber;
num=(currentNumber*10)+9;
currentNumber=9;
bendal+="9";
bend.setText(bendal);
}else{
num=(currentNumber*10)+9;
bendal+="9";
currentNumber=num;
bend.setText(bendal);
}
}
}
);
zpanel.add(rightbutton3);

Dec4=new FlowLayout();
lpanel=new JPanel();
lpanel.setLayout(Dec4);

leftbutton4=new JButton( " 0 " );
leftbutton4.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
int num;
if(isfirstNumber){
isfirstNumber=!isfirstNumber;
num=(currentNumber*10)+0;
currentNumber=0;
bendal+="0";
bend.setText(bendal);
}else{
num=(currentNumber*10)+0;
bendal+="0";
currentNumber=num;
bend.setText(bendal);
}
}
}
);
lpanel.add(leftbutton4);

centerbutton4=new JButton( " CE " );
centerbutton4.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
int num;
num=(currentNumber*0);
bendal="";
currentNumber=num;
bend.setText(bendal);


}
}
);

lpanel.add(centerbutton4);

rightbutton4=new JButton( " Cvrt" );
rightbutton4.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){

convert(currentNumber);
currentNumber=0;
bendal="";

}
}
);

lpanel.add(rightbutton4);

}
public void convert(int num){
int Number=num;
bendal="";

if(Number>999999999){
bendal="";
bendal="Syntax Limit (Billion) Reached";
}
if(Number==0)
bendal="Syntax Roman Not Exist";

while(Number!=0 && Number<=999999999){

if(Number==1000000){
bendal+="M.";
Number=Number-1000000;
}else if(Number>1000000){
bendal+="M.";
Number=Number-1000000;
}else if(Number>=500000){
if(Number>=900000){
bendal+="C.M.";
Number=Number-900000;
}else{
Number=Number-500000;
bendal+="D.";
}
}
else if(Number>=100000){
if(Number>=400000){
bendal+="C.D.";
Number=Number-400000;
}else{
bendal+="C.";
Number=Number-100000;
}
}
else if(Number>=50000){
if(Number>=90000){
bendal+="X.C.";
Number=Number-90000;
}else{
bendal+="L.";
Number=Number-50000;
}
}
else if(Number>=10000){
if(Number>=40000){
bendal+="X.L.";
Number=Number-40000;
}else{
bendal+="X.";
Number=Number-10000;
}
}
else if(Number>=5000){
if(Number>=9000){
bendal+="MX.";
Number=Number-9000;
}else{
bendal+="V.";
Number=Number-5000;
}
}

else if(Number>=1000){
if(Number>=4000){
bendal+="MV.";
Number=Number-4000;
}
else{
bendal+="M";
Number=Number-1000;
}
}
else if(Number>=500){
if(Number>=900){
bendal+="CM";
Number=Number-900;
}else{
Number=Number-500;
bendal+="D";
}
}
else if(Number>=100){
if(Number>=400){
bendal+="CD";
Number=Number-400;
}else{
Number=Number-100;
bendal+="C";
}
}
else if(Number>=50){
if(Number>=90){
bendal+="XC";
Number=Number-90;
}else{
Number=Number-50;
bendal+="L";
}
}
else if(Number>=10){
if(Number>=40){
bendal+="XL";
Number=Number-40;
}else{
Number=Number-10;
bendal+="X";
}
}
else if(Number>=5){
if(Number>=9){
bendal+="IX";
Number=Number-9;
}else{
Number=Number-5;
bendal+="V";
}
}
else if(Number>=1){
if(Number>=4){
bendal+="IV";
Number=Number-4;
}else{
Number=Number-1;
bendal+="I";
}
}else if(Number==1){
bendal+="I";
Number=Number-1;
}
}
bend.setText(bendal);
}


}

Atom



Powred By : CRAZY24X7 [IT] RESEARCH AND DEVELOPMENT

Registered Office : D 308, 311 3rd Floor, Patna 800001, Dumraon Palace, New Dak Bungalow Road, Patna, Bihar 800001.. Tel : 0612-3220455/66215555 | Corporate Office : Shop No :-09, Madhav Palaza, Motera Stadium, Ahmedabad, Gujarat - 380005 Mob : 7281000365/366, 9905559000