Why won't my applet show?

I don't see whats wrong with this code. It looks fine, but the applet on the website doesn't show the gui at all

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.net.*;

import javax.swing.*;

publicclass Clientextends JAppletimplements ActionListener

{

publicvoid init()

{

setContentPane(new Client());

}

publicstatic JMenuBar menuBar =new JMenuBar();

publicstatic JMenu file =new JMenu("File");

publicstatic JMenuItem home =new JMenuItem("Main Page");

publicstatic JPanel panel =new JPanel(new BorderLayout());

publicstatic JLabel intro =new JLabel("Welcome.");

public Client(){

setLayout(new BorderLayout());

setJMenuBar(menuBar);

menuBar.add(file);

file.add(home);

home.addActionListener(this);

setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));

panel.add(intro);

}

publicvoid actionPerformed(ActionEvent e){

Object s = e.getSource();

if(s == home){

intro.setText("Once again, welcome!");

}

}

}

[2720 byte] By [JToolTipa] at [2007-11-27 9:47:55]
# 1

What do you see ? Do you see something different if you view the applet using the programme $SDK_home\bin\AppletViewer.exe

Do you get any errors in the JVM plugin console ?

What HTML code are you using to display the applet ?

<!--some browsers require you use an object tag to invoke a JRE plugin-->

<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"

width="800" height="450" name="ap">

<PARAM NAME="code" VALUE="Client.class">

<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2">

<PARAM NAME="scriptable" VALUE="true">

No JDK 1.2 support for APPLET!!

</OBJECT>

Bamkin

bamkin-ov-lestaa at 2007-7-13 0:01:03 > top of Java-index,Desktop,Core GUI APIs...
# 2

Your code was throwing an error at runtime: java.awt.AWTError: BoxLayout can't be shared

It seems like a bug:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6235079

Works now:

Hope ive helped.

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.net.*;

import javax.swing.*;

public class Client extends JApplet implements ActionListener

{

Dimension size=new Dimension(300,300);

public void init()

{

setContentPane(new Client());

}

public static JMenuBar menuBar = new JMenuBar();

public static JMenu file = new JMenu("File");

public static JMenuItem home = new JMenuItem("Main Page");

public static JPanel panel2 = new JPanel(new BorderLayout());

public static JLabel intro = new JLabel("Welcome.");

public Client() {

setJMenuBar(menuBar);

menuBar.add(file);

file.add(home);

home.addActionListener(this);

getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.PAGE_AXIS));

panel2.setPreferredSize(size);

panel2.setMaximumSize(panel2.getPreferredSize());

add(panel2);

panel2.setSize(300,300);

panel2.add(intro);

panel2.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

Object s = e.getSource();

if(s == home) {

intro.setText("Once again, welcome!");

}

}

}

Message was edited by:

Jbg

Jbga at 2007-7-13 0:01:03 > top of Java-index,Desktop,Core GUI APIs...
# 3
Well spotted Jbg.I'd go with that solution:-)
bamkin-ov-lestaa at 2007-7-13 0:01:03 > top of Java-index,Desktop,Core GUI APIs...
# 4
Hehe thanks, google did most of the work:)
Jbga at 2007-7-13 0:01:03 > top of Java-index,Desktop,Core GUI APIs...