error in generating appletviewer

R

RCS

I am having trouble viewing my results. My JAVA code below compiles,
but when I write out my HTML file and generate appletviewer, I am
getting a window that is blank but I receive a message at the bottom
of the blank applet saying:

Start:applet not initialized

HTML code:

<HTML>
<BODY>
<P>
<APPLET CODE = "HelloWorld.class" width="200" height="200">
<PARAM NAME = CODE VALUE = "JButtons4.class">
<PARAM NAME = CODEBASE VALUE = "applets">
<PARAM NAME ="type" Value = "application/x-java-applet;version=1.4.2">
</APPLET>
</P>
</BODY>
</HTML>



Java code:

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


public class JButtons4 extends JFrame{

private JButton phonekeys[];
private String KEYS[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9",
"*", "0", "+"};
private int counter = 0;
private String numbers[];
private int i;
private JLabel label;
private JPanel content;
private JPanel content3;

public static void main(String[] args)
{
new JButtons();
}


public void init()
{

JPanel content = new JPanel();
JPanel content2 = new JPanel();
Container content3 = getContentPane();

label = new JLabel();

phonekeys = new JButton[ KEYS.length ];

content2.setLayout( new GridLayout(4, 3) );

ButtonHandler handler = new ButtonHandler();

for( int i = 0 ; i < 12 ; i++ )
{
phonekeys = new JButton( KEYS );
content2.add( phonekeys );
phonekeys.addActionListener( handler );
}

content3.add(content2, BorderLayout.SOUTH);
content3.add(content, BorderLayout.NORTH);

pack();
setVisible(true);

}

private class ButtonHandler implements ActionListener
{
public void actionPerformed( ActionEvent e )
{
for( i = 0; i < phonekeys.length; i++ )
{
if( e.getSource() == phonekeys )
{
label.setText( KEYS );
content.add(label);
break;
}
}
}

}

}
 
T

Tr0mBoNe-

Your design is sound for a strictly UI program, but your browser is
getting confused when it comes to what it has to do. You must eiter go
totally applet (JApplet) or totally awt. Also, your browser needs a
few things that the program does not need to run. First, the init().
thats there. thats good, but you also need a public void start(). this
tells that browser that its time to go, and to execute whats in the
init.

i hope that this gets you on the right track.

andrew
 
J

Jonathan Mcdougall

I am having trouble viewing my results. My JAVA code below compiles,
but when I write out my HTML file and generate appletviewer, I am
getting a window that is blank but I receive a message at the bottom
of the blank applet saying:

Start:applet not initialized

HTML code:

<HTML>
<BODY>
<P>
<APPLET CODE = "HelloWorld.class" width="200" height="200">
<PARAM NAME = CODE VALUE = "JButtons4.class">
<PARAM NAME = CODEBASE VALUE = "applets">
<PARAM NAME ="type" Value = "application/x-java-applet;version=1.4.2">
</APPLET>
</P>
</BODY>
</HTML>

What is HelloWorld.class? The CODE and CODEBASE parameters should go
*in* the APPLET tag, except if they are real parameters which you use
in your code. What`s more, I don't think it is legal to have
parameters with these names, but I may be wrong.

<applet code="HelloWorld.class" width=200 height=200
codebase="applets">

Are you sure your classes are in ./applets (that's what CODEBASE is
for).
Java code:

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


public class JButtons4 extends JFrame{

Applets must derive from java.awt.Applet or javax.swing.JApplet.
JFrames are for applications.

public static void main(String[] args)
{
new JButtons();

What is JButtons? Did you mean JButtons4?

Applets do not have a main() function, they override Applet or JApplet
functions.


Please have a look to the java tutorial :

http://java.sun.com/docs/books/tutorial/applet/index.html


Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top