Howdy!,
Just wanna share my codes generated for Java Applet (JAVA Programming language) which converts Numbers into Roman Numerals...
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class NumberstoRoman extends Applet implements ActionListener
{
Label line1 = new Label ("_________________________________________________");
Label title = new Label (" ROMAN NUMERAL IDENTIFIER ");
Label line2 = new Label ("_________________________________________________");
Label enter1 = new Label("Enter Number [1-3000]: ");
Button b1 = new Button(" Compute ");
Button b2 = new Button(" Clear ");
Font big = new Font ("Verdana", Font.BOLD,22);
Font rodsoft = new Font ("Arial", Font.ITALIC,10);
Label spcr1 = new Label (" ");
Label result = new Label ("The Roman Numerals are : ");
Label rod1 = new Label ("Developed by:");
Label rod2 = new Label ("rodsoft:---> http://successum.blogspot.com");
TextField number = new TextField(8);
public void init()
{
title.setFont(big);
rod2.setFont(rodsoft);
add(line1);
add(title);
add(line2);
add(enter1);
add(number);
add(b1);
add(b2);
add(result);
add(spcr1);
add(rod1);
add(rod2);
number.requestFocus();
number.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void start()
{
number.setText("");
result.setText("The Roman Numerals are: ");
invalidate();
validate();
}
public void actionPerformed(ActionEvent e)
{
String romn = "";
int x = Integer.parseInt(number.getText());
{
if (x>3000)
{
result.setText("The Roman Numerals are: out of range!:");
}
}
{
if (e.getSource()==b1)
{
while (x > 3000)
{
romn += "out of range!:";
x -= 3000;
}
while (x >= 1000)
{
romn += "M";
x -= 1000;
}
while (x >= 900)
{
romn += "CM";
x -= 900;
}
while (x >= 500)
{
romn += "D";
x -= 500;
}
while (x >= 400)
{
romn += "CD";
x -= 400;
}
while (x >= 100)
{
romn += "C";
x -= 100;
}
while (x >= 90)
{
romn += "XC";
x -= 90;
}
while (x >= 50)
{
romn += "L";
x -= 50;
}
while (x >= 40)
{
romn += "XL";
x -= 40;
}
while (x >= 10)
{
romn += "X";
x -= 10;
}
while (x >= 9)
{
romn += "IX";
x -= 9;
}
while (x >= 5)
{
romn += "V";
x -= 5;
}
while (x >= 4)
{
romn += "IV";
x -= 4;
}
while (x >= 1)
{
romn += "I";
x -= 1;
}
result.setText("The Roman Numerals are : "+romn);
}
else if (e.getSource()==b2)
{
number.setText("");
result.setText("The Roman Numerals are : ");
}
}
}
}
//This is only an applet...so you must create html to call on the applet to execute.
AMP or PWA? Why not AMP + PWA!
6 years ago
0 comments:
Post a Comment