Here is my code.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class dollarsAndCentsApplet extends Applet implements ActionListener
{
// declare variables
Image logo; // declare an Image object
String totalPennies;
int total, dollars, cents;
// construct components
Label programLabel = new Label("Welcome to Dollars and Cents!");
Label pennieLabel = new Label("Enter the total number of pennies you have: ");
TextField pennieField = new TextField(10);
Button calcButton = new Button("Calculate");
Label outputLabel = new Label(
"Click Calculate to turn your pennies into dollars and cents.");
public void init()
{
setForeground(Color.red);
add(programLabel);
add(pennieLabel);
add(pennieField);
add(calcButton);
calcButton.addActionListener(this);
add(outputLabel);
logo = getImage(getDocumentBase(), "logo.gif");
}
public void actionPreformed(java.awt.event.ActionEvent e)
{
total = Integer.parseInt(pennieField.getText());
dollars = total / 100;
cents = total % 100;
outputLabel.setText("You have" + dollars + "and" + cents + "Cents.");
}
public void paint(Graphics g)
{
g.drawImage(logo,125,160,this);
}
}
I have searched google, and have not really found any explanations that fit.
Any help would be appreciated. Thanks!

New Topic/Question
Reply



MultiQuote






|