473,382 Members | 1,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

My applet is saying it is not initialized and I was wondering why

Hi I was wondering why this program has an Applet come up and it says it is not initializedher it is

This program use an applet. The program chooses the number to be guessed by
selecting a random integerin the range 1 to 1000. The applet will have a label
called Guess a number between 1 and 1000 next to a JTextfield.The player will
type in the guess and then if the guess is wrong the computer will show to
high or to low in the showStatus bar and then theuser will be able to continue
guessing until the user guesses the right one.when tha happens this will show
up in the showStatus bar(Congratulations. You guessed the number!)
*/

//java packages
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import java.util.Random;


public class Guess1Applet extends JApplet implements ActionListener {

int number,//computers number
num;// users number converted to int

JLabel num1label;// label on the applet

JTextField num1field; // the users guess

// Set up Applet's GUI
public void init ()
{
// obtain content pane and set its layout to flowlayout and creates the label
Container container =getContentPane();
container.setLayout( new FlowLayout() );
num1label = new JLabel();


//creates the label and the text for the label and textfield
num1label.setText( "Guess a number between 1 and 1000:");
container.add( num1label );
num1field = new JTextField( 5 );
container.add( num1field );

//registers the applet as num1field and num2field actionlistener
num1field.addActionListener( this );

// randomly generates a number between 1 and 1000
Random random = new Random();
number = random.nextInt(1000);

//convert the users guess to int
num = Integer.parseInt( num1field.getText());

}//END method init

public void actionPerformed ( ActionEvent e )
{

while ( num != number)
{
int number = 1 + (int)(Math.random() * 1000);
if ( num == number )
showStatus( "Congratulations. You guessed the number!");
else if ( num > number )
showStatus( "to high");
else if ( num < number )
showStatus( "to low");



// obtain content pane and set its layout to flowlayout and creates the label
Container container =getContentPane();
container.setLayout( new FlowLayout() );
num1label = new JLabel();


//creates the label and the text for the label and textfield
num1label.setText( "Guess a number between 1 and 1000:");
container.add( num1label );
num1field = new JTextField( 5 );
container.add( num1field );

//registers the applet as num1field and num2field actionlistener
num1field.addActionListener( this );

// randomly generates a number between 1 and 1000
Random random = new Random();
number = random.nextInt(1000);

//convert the users guess to int
num = Integer.parseInt( num1field.getText());



}//end while

}//end actionperformed

}//end class Guess1Applet


here is the html


<html>
<applet code="GuessApplet.class" width = 450 height= 350>
</applet Started>
</html>

any suggestions thanks for the help
Feb 28 '07 #1
0 1116

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Laura | last post by:
Hello, Newbie question: Does anyone know how to dynamically set the screen width in an applet? I have an applet that creates a horizontal bar menu on a webpage, and I would like the width to be...
3
by: Daniel Pope | last post by:
Hello Everybody, I'm preparing for doing a daunting task: to access Out look Microsoft Outlook Express(regardles the operating system and Outlook version) from a Java applet (after the client...
1
by: Wayne's World | last post by:
hi everyone, i have a big problem, writing a image from my applet to my apache webserver. i tried three way's of writing that file. every way was described in forums to solve this problem, but...
2
by: David Haga | last post by:
How can I query an applet from Javascript to determine when it is running? I need to start a second applet but only when I know the first applet is completely loaded, initialized and executing.
2
by: Dag Sunde | last post by:
I have the following code fragment in one of my pages: if (typeof document.getElementById('myApplet').getTableAsSDV != 'undefined') { rowBuffer =...
0
by: ankur | last post by:
WHEN I RUN THIS WEB APPLICATION ON Tomcat5.5.9 SERVER MY HttpChatApplet sccessfully Loaded from ChatDispatch but running on some another PC HttpChatApplet not loaded my Coad ...
2
by: Richard Maher | last post by:
Hi, Recently on the web I came across documentation discussing Data Source Objects (DSO) in relation to browser and html functionality (in particular the ability to declare a Java applet as a...
1
by: speedygonzalez | last post by:
Hi all! I've a pretty naive problem with my applet which is as follows..... // Wordlist for GRE High Frequency Words import java.awt.*; import java.applet.*;
2
JustRun
by: JustRun | last post by:
Hi, I'm new to Java "I loved it" and i'm stuck with a Chart Applet i'm trying to give the pie chart its values from my database. Actually the database class works when i tested it in main method...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.