Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > error in generating appletviewer

Reply
Thread Tools

error in generating appletviewer

 
 
RCS
Guest
Posts: n/a
 
      09-08-2003
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[i] = new JButton( KEYS[i] );
content2.add( phonekeys[i] );
phonekeys[i].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[i] )
{
label.setText( KEYS[i] );
content.add(label);
break;
}
}
}

}

}
 
Reply With Quote
 
 
 
 
Tr0mBoNe-
Guest
Posts: n/a
 
      09-12-2003
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

http://www.velocityreviews.com/forums/(E-Mail Removed) (RCS) wrote in message news:<(E-Mail Removed). com>...
> 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[i] = new JButton( KEYS[i] );
> content2.add( phonekeys[i] );
> phonekeys[i].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[i] )
> {
> label.setText( KEYS[i] );
> content.add(label);
> break;
> }
> }
> }
>
> }
>
> }

 
Reply With Quote
 
 
 
 
Jonathan Mcdougall
Guest
Posts: n/a
 
      09-12-2003
Do not top-post. Rearranged.

>> 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


<snip>

>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.


Tbat's plain wrong. See

http://java.sun.com/docs/books/tutor...etMethods.html


Jonathan
 
Reply With Quote
 
Jonathan Mcdougall
Guest
Posts: n/a
 
      09-13-2003
>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.

<snip>

>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/tutor...let/index.html


Jonathan

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening instruments with appletviewer vs. browser Momo Java 4 11-02-2011 10:34 AM
Problems with an Applet that works from appletviewer 418928@cepsz.unizar.es Java 1 02-04-2007 04:52 PM
Where do I download AppletViewer.EXE ? D. Patrick Java 6 07-04-2006 09:54 PM
Applet Problems - Works in appletviewer but not ie michael.rygh@gmail.com Java 7 12-16-2005 09:11 AM
Re: Strange Appletviewer/HTML difference problem... (please help) Steve Claflin Java 0 09-03-2003 03:46 AM



Advertisments