954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Applet won't display in Exlporer

I have completed my applet code and it compiles fine - when I try to open it in explorer I get my welcome message but the applet does not fully open - all I get is the little box with the red X in top left corner. Help!
Here is code for both:

Applet:

import java.awt.event.*;
import java.applet.Applet;
import javax.swing.*;
import java.awt.*;
import java.awt.*;

public class JPartyPlanner extends JApplet implements ActionListener
{
JLabel companyName = new JLabel("Give A Hand Event Planning");
Font bigFont = new Font("Teen", Font.BOLD, 30);
JLabel firstLabel = new JLabel ("How many people will be attending?");
JTextField answer = new JTextField(10);
JButton calcButton1 = new JButton("Calculate per person");
JButton calcButton2 = new JButton("Calculate event cost");
JLabel perPersonResult = new JLabel(" ");
JLabel totalResult = new JLabel(" ");
FlowLayout flow = new FlowLayout();
ImageIcon image = new ImageIcon("birthday.jpeg");
private int width, height;
int y = 300;
int x = 300;

public void init()
{
Container con = getContentPane();
con.setLayout(new FlowLayout());
companyName.setFont(bigFont);
con.setBackground(Color.ORANGE);
con.add(companyName);
con.add(firstLabel);
con.add(answer);
con.add(calcButton1);
con.add(calcButton2);
calcButton1.addActionListener(this);
calcButton2.addActionListener(this);
con.add(perPersonResult);
con.add(totalResult);

height = image.getIconHeight();

}

public void paint(Graphics g)

{
super.paint(g);
g.drawString("IT'S PARTY TIME!", x, y);
g.drawImage(image.getImage(), x, y + 20,width, height, this);
}

public void start()
{
perPersonResult.setText("Per person Cost is ");
totalResult.setText("Event cost is ");
repaint();
}

public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();

{
String response = answer.getText ();
int[] guestLimit = {0, 25, 50, 100, 200, 500, 1000};
int[] ratePerGuest = {27, 25, 22, 19, 17, 14, 11};
int guests = Integer.parseInt(response);
int individualFee = 0, eventFee = 0;
int x = 0, a = 0;

for(x = 6; x >= 0; --x)
if(guests >= guestLimit[x])
{
individualFee = ratePerGuest[x];
eventFee = guests * individualFee;
x = 0;
}

perPersonResult.setText("Per person cost is $" + individualFee);
totalResult.setText("Event cost is $" + eventFee);


}
}

}


HTML file:

Welcome!

kdgeiger
Newbie Poster
11 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

seems you need

con.setVisible(true);


I usually work with frames, and after creating and adding controls/layout, you have to use setVisible, but i googled container and it does inherit setVisible from java.awt.component.

Mike

adams161
Posting Whiz in Training
281 posts since May 2008
Reputation Points: 31
Solved Threads: 27
 

Is there an error message in the browser's Java console?
Please copy and paste it here.
How are you executing the applet? Locally from a disk file or from a server?

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

Thanks Guys but I figured it out - it was an issue with Vista works fine in 07.

kdgeiger
Newbie Poster
11 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: