My code is fine, it compiles just fine, my teacher looked at it and we cannot figure out how to make the applet run correctly. I am making a GUI that takes your weight and calculates how much you would weigh on a selected planet. When I run it, the applet pops up, but is blank and says "Start applet not initialised". I am using BlueJ. Here is my code:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.text.*;
public class Lab24 extends Applet implements ActionListener, ItemListener
{
private Label lab1;
protected TextField info, result;
private TextField input;
private Button butt;
private Choice planet;
private Font font1,font2,font3,font4;
static double w1,w2;
public void init(){
setBackground(new Color(0,0,199));
setLayout(new GridLayout(3,2,20,50));
font1 = new Font("Courier",Font.PLAIN,15);
font2 = new Font("Monospaced",Font.BOLD,8);
font3 = new Font("TimesNewRoman",Font.PLAIN,12);
font4 = new Font("Serif",Font.ITALIC,18);
info.setText("This program allows you to\ncalculate your weight on\nanother planet!");
info.setEditable(false);
info.setFont(font1);
add(info);
lab1 = new Label();
lab1.setFont(font2);
lab1.setForeground(Color.black);
lab1.setText("Enter your weight(in pounds)!");
add(lab1);
input = new TextField();
input.addActionListener(this);
add(input);
planet.setFont(font3);
planet = new Choice();
planet.setBackground(new Color(107,180,243));
planet.setForeground(Color.black);
planet.add("Choose a planet");
planet.add("Mercury");
planet.add("Venus");
planet.add("Mars");
planet.add("Jupiter");
planet.add("Saturn");
planet.add("Uranus");
planet.add("Neptune");
planet.addItemListener(this);
add(planet);
butt.setFont(font2);
butt = new Button("Calculate");
butt.addActionListener(this);
add(butt);
result.setFont(font4);
result = new TextField();
result.setEditable(false);
result.setForeground(Color.blue);
add(result);
}
public void itemStateChanged(ItemEvent e) {
if(e.getSource()==planet){
switch(planet.getSelectedIndex()){
case 1: w2 = w1 * 0.37;
break;
case 2: w2 = w1 * 0.88;
break;
case 3: w2 = w1 * 0.38;
break;
case 4: w2 = w1 * 2.64;
break;
case 5: w2 = w1 * 1.15;
break;
case 6: w2 = w1 * 1.15;
break;
case 7: w2 = w1 * 1.12;
break;
}
}
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==input){
String s = input.getText();
input.setText(s);
}
if(e.getSource() == butt){
result.setText("You would weigh\n"+w2+" pounds!");
}
}
public void paint(Graphics g){
g.setColor(Color.red);
g.drawOval(10,50,25,25);
}
}