Wrote my first java applet for a coding class I'm taking. keeps saying "Start: Applet not Intilized" I realize there is probably more issues in here, but I can't find them when the applet won't run. can anyone find my error?
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class danielDrinkMachine extends Applet
{
private Panel mainPanel;
private Panel buttons1;
private Panel buttons2;
private Panel screen;
private BufferedImage logo;
private TextField money;
private Label screenText;
private Label titleText;
private Button cola;
private Button lemonLimeSoda;
private Button rootBeer;
private Button grapeSoda;
private Button bottledWater;
private Button formattingButton;
private double currentMoney;
private int colaCount = 20;
private int llCount = 20;
private int rbCount = 20;
private int grapeCount = 20;
private int waterCount = 20;
private String format ="$#,##0.00";
private DecimalFormat outFormat =new DecimalFormat(format);
private final int width = 500;
private final int height = 500;
public void init()
{
screenText =new Label();
setSize(WIDTH, HEIGHT);
buildPanel();
add(mainPanel);
setVisible(true);
}
private void buildPanel()
{
Label titleText = new Label("ALL DAY's VENDING MACHINES");
money =new TextField();
money.setEditable(true);
Label screenText = new Label("Welcome! Drinks cost $0.75 each!");
cola =new Button("Cola");
lemonLimeSoda =new Button("Lemon Lime");
grapeSoda =new Button("Grape Soda");
rootBeer =new Button("Root Beer");
bottledWater =new Button("Water");
formattingButton =new Button("(Sold Out)");
cola.addActionListener(new iAmTheListener());
lemonLimeSoda.addActionListener(new iAmTheListener());
grapeSoda.addActionListener(new iAmTheListener());
rootBeer.addActionListener(new iAmTheListener());
bottledWater.addActionListener(new iAmTheListener());
formattingButton.addActionListener(new iAmTheListener());
mainPanel.add(titleText, BorderLayout.PAGE_START);
mainPanel.add(buttons1, BorderLayout.LINE_START);
mainPanel.add(buttons2, BorderLayout.LINE_END);
mainPanel.add(screen, BorderLayout.LINE_END);
screen.setLayout(new GridLayout(1,2));
screen.add(screenText);
screen.add(money);
buttons1.setLayout(new GridLayout(1,3));
buttons1.add(cola);
buttons1.add(lemonLimeSoda);
buttons1.add(grapeSoda);
buttons2.setLayout(new GridLayout(1,3));
buttons2.add(rootBeer);
buttons2.add(bottledWater);
buttons2.add(formattingButton);
}
private class iAmTheListener implements ActionListener
{
public void actionPerformed(ActionEvent buttonPress)
{
String moMoney=money.getText();
currentMoney =Double.parseDouble(moMoney);
if(currentMoney < 0.75)
{
int count = 0;
if(count == 0)
{
JOptionPane.showMessageDialog(null,"Drinks are $0.75 each. Enter more money");
count++;
}
if(count == 1)
{
JOptionPane.showMessageDialog(null,"Seriously, its not even real money.");
count++;
}
if(count == 2)
{
JOptionPane.showMessageDialog(null,"Is this a joke? Its not funny.");
count++;
}
if(count == 3)
{
JOptionPane.showMessageDialog(null,"Just type put a '1' in the money blank, please.");
count ++;
}
if(count >= 4)
{
JOptionPane.showMessageDialog(null,"Haha! It's always funnier the " + count + "th time!");
count++;
}
}
else if(currentMoney >= 0.75)
{
if(buttonPress.getSource() == cola)
{
if(colaCount == 0)
screenText.setText("Sold out");
else if(colaCount != 0)
{
currentMoney -= 0.75;
screenText.setText(outFormat.format(currentMoney));
currentMoney = 0.0;
colaCount--;
}
else;
}
else if(buttonPress.getSource() ==lemonLimeSoda)
{
if(llCount ==0)
{
screenText.setText("Sold out");
}
else if(llCount !=0)
{
currentMoney -= 0.75;
screenText.setText(outFormat.format(currentMoney));
currentMoney =0.0;
llCount--;
}
else;
}
else if(buttonPress.getSource() ==grapeSoda)
{
if(grapeCount ==0)
{
screenText.setText("Sold out");
}
else if(grapeCount !=0)
{
currentMoney -= 0.75;
screenText.setText(outFormat.format(currentMoney));
currentMoney =0.0;
grapeCount--;
}
else;
}
else if(buttonPress.getSource() ==rootBeer)
{
if(rbCount ==0)
{
screenText.setText("Sold out of Root Beer");
}
else if(rbCount !=0)
{
currentMoney -= 0.75;
screenText.setText(outFormat.format(currentMoney));
currentMoney =0.0;
rbCount--;
}
else;
}
else if(buttonPress.getSource() ==bottledWater)
{
if(waterCount ==0)
{
screenText.setText("Sold out");
}
else if(waterCount !=0)
{
currentMoney -= 0.75;
screenText.setText(outFormat.format(currentMoney));
currentMoney =0.0;
waterCount--;
}
else;
}
else;
}
}
}
}