Ok, I did search on this site and found nothing that really helps with my issue. I am doing assignment - JPartyPlanner - I have the applet complete, it compiles and shows in IE great, BUT when I add the image code it still compiles but I get nothing showing at all so I have done something wrong in the image area. Here is my code - your help is greatly appreciated.
// JPartyPlanner.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JPartyPlanner extends JApplet implements ActionListener
{
JLabel label1 = new JLabel("Event Handlers Incorporated");
JLabel label2 = new JLabel(" PartyPlanner ");
Font font = new Font("Ariel", Font.ITALIC, 36);
JLabel guestsLabel = new JLabel("How many guests will be attending?");
JTextField guestsField = new JTextField("",9);
JTextField int2 = new JTextField("",9);
JButton button1 = new JButton("Calculate per guest");
JButton button2 =new JButton("Calculate total cost");
FlowLayout flow = new FlowLayout();
Container con = getContentPane();
JLabel answer = new JLabel("");
int[] range = {24, 49, 99, 199, 499, 999};
int[] price = {27, 25, 22, 19, 17, 14, 11};
private ImageIcon image = new ImageIcon("birthday.jpg");
private int width , heigth;
Container picture = getContentPane();
int x = 30;
int y = 30;
public void init()
{
con.setLayout(flow);
label1.setFont(font);
label2.setFont(font);
answer.setFont(font);
width = image.getIconWidth();
con.add(label1);
con.add(label2);
con.add(guestsLabel);
con.add(guestsField);
con.add(button1);
con.add(button2);
button1.addActionListener(this);
button2.addActionListener(this);
button1.requestFocus();
con.add(answer);
}
public void paint(Graphics g)
{
super.paint(g);
g.drawString("Luxurious", x, y);
g.drawImage(image.getImage(), x, y + 20, width, heigth, this);
}
public void stop()
{
guestsField.setText("");
}
public void actionPerformed(ActionEvent e)
{
String guestsString = guestsField.getText();
int guests = Integer.parseInt(guestsString);
int x, pr, sub = range.length;
String message;
for(x =0; x < range.length; ++x)
if(guests <= range[x])
{
sub = x;
x = range.length;
}
pr = price[sub];
Object o = e.getSource();
if(o == button1)
message = "Per person cost is $" + pr +".00";
else
message = "Event cost is $" + (pr * guests) + ".00";
answer.setText(message);
}
}