Professional Documents
Culture Documents
Shawn C. Stalder
From_Base.java
Objectives:
1) Convert from any base chosen by the user to base 10
*/
// imports
import javax.swing.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.text.*;
// Fonts
private Font Arial;
private Font Norm;
// set objects
txt_num = new TextField();
txt_base = new TextField();
btn_con = new Button("Convert");
btn_clear = new Button("Clear");
txa_result = new TextArea();
// position objects
txt_num.setBounds(10, 40, 120, 40);
txt_base.setBounds(140, 40, 50, 40);
btn_con.setBounds(10, 90, 120, 40);
btn_clear.setBounds(140, 90, 120, 40);
txa_result.setBounds(10, 140, 400, 60);
// initialize font
Arial = new Font("Arial", Font.PLAIN, 28);
Norm = new Font("Arial", Font.BOLD, 18);
setFont(Arial);
}
if(source == btn_con)
{
// variables
String input;
int base;
int size;
int temp1;
int ans;
// get size
input = txt_num.getText();
input = input.trim();
size = input.length();
System.out.println(input);
System.out.println(size);
do
{
temp = (temp * base) + num[i];
System.out.println(temp);
i++;
}while(i < size);
return temp;
}