error in generating appletviewer

Discussion in 'Java' started by RCS, Sep 8, 2003.

  1. RCS

    RCS Guest

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

    }

    }
     
    RCS, Sep 8, 2003
    #1
    1. Advertising

  2. RCS

    Tr0mBoNe- Guest

    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

    (RCS) wrote in message news:<>...
    > 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;
    > }
    > }
    > }
    >
    > }
    >
    > }
     
    Tr0mBoNe-, Sep 12, 2003
    #2
    1. Advertising

  3. 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/tutorial/applet/overview/appletMethods.html


    Jonathan
     
    Jonathan Mcdougall, Sep 13, 2003
    #3
  4. >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/tutorial/applet/index.html


    Jonathan
     
    Jonathan Mcdougall, Sep 13, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Claflin
    Replies:
    0
    Views:
    481
    Steve Claflin
    Sep 3, 2003
  2. Replies:
    7
    Views:
    2,360
    Andrew Thompson
    Dec 16, 2005
  3. D. Patrick
    Replies:
    6
    Views:
    14,908
    Oliver Wong
    Jul 4, 2006
  4. Momo
    Replies:
    4
    Views:
    392
  5. Replies:
    1
    Views:
    552
    Andrew Thompson
    Feb 4, 2007
Loading...

Share This Page