How can i use this as an applet ?

i have this applet :
import java.applet.*;
import java.io.*;
public class calculator2 extends Applet {
/*<Applet code=calculator2.class width=500 height=500></applet>*/
/*the above comment has to be there for applet view to work. Type in at the promt "appletviewer calculator2.java"*/
public void init() {
int num1,num2,num3,num4,num5,num6,sum;
num1 = num2 = num3 = num4 = num5 = num6 = sum = 0;
/*Program statemants start here*/
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Input Rent");
num1 = Integer.parseInt(br.readLine());
System.out.println("Input Utility bills");
num2 = Integer.parseInt(br.readLine());
System.out.println("Input mobile bills");
num3 = Integer.parseInt(br.readLine());
System.out.println("Input food");
num4 = Integer.parseInt(br.readLine());
System.out.println("Input soialising");
num5 = Integer.parseInt(br.readLine());
System.out.println("Input savings");
num6 = Integer.parseInt(br.readLine());
sum=num1+num2+num3+num4+num5+num6;
System.out.println("Enter your income: ");
int income = Integer.parseInt(br.readLine());
income -= sum;System.out.println(income);
} catch (IOException ioe) {
} catch (NumberFormatException nfe) {
System.out.println("That wasn't a valid number!");
System.out.println("Someone else did my homework for me! ");
but when i run it i still need to write my answers in the comand prompt window not the applet its self,
i know i need to do something like this but i don't know how
add the line import java.awt; Instead of using System.out.println you can
a)Paint the characters using paint
public void paint(Graphics g){
g.drawString(x, y, "" + yourVariableName); //use this for each System.out.println
b)store the variables in a label and add
Label yourName = newLabel("")// do this for each thing you want to print.
yourName.setText("" + yourVariableName); //replace all sytem.out.println with this.
anyone offer any advice ??
thanking you in advance
Anthony

You seem to be asking an awful lot of questions that could be found in any basic Java textbook. Won't make you too popular on here!
This should get you started anyway
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class calculator2 extends Applet implements ActionListener
int total;
Label label1, label2;
TextField text1, text2;
Button clicker;
public void init()
label1 = new Label ("Input Rent");
label2 = new Label ("Input Bills");
text1 = new TextField (5);
text2 = new TextField (5);
clicker = new Button("Calculate");
add(label1);
add(text1);
add(label2);
add(text2);
add(clicker);
clicker.addActionListener(this);
} // end init
public void paint (Graphics g)
g.drawString ("The total is " + total, 50,100);
} // end paint
public void actionPerformed (ActionEvent e)
total = Integer.parseInt(text1.getText()) +Integer.parseInt(text2.getText());
repaint();
} // end actionPerformed
} // end class

Similar Messages

Maybe you are looking for