JApplet is not working properly...
Hi there...
I am having a problem with my applet. Here is the code:
package click;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class click1 extends JApplet implements MouseListener{
JPanel jp;
JButton b;
StringBuffer buffer;
String message;
public void init(){
jp = new JPanel();
jp.setBackground(Color.white);
b = new JButton("click");
b.addMouseListener(this);
jp.add(b);
getContentPane().add(jp, BorderLayout.WEST);
buffer = new StringBuffer();
}
public void paint(Graphics g){
g.drawString(buffer.toString(), 80, 30);
}
public void mouseClicked(MouseEvent arg0) {
buffer.append("Click");
repaint();
}
the problem is, when I start the applet, it appears as a blank white applet and the button does not appear untill I move my mouse over it. Also when i add this applet to a html page it appears as a box with red cross in the upper left corner. Any Ideas?
regards
[1122 byte] By [
Raieda] at [2007-11-27 9:32:45]

In your system tray find the java icon, right click and select "Open Console". Then you should see any error messages.
Your basic problem is probably that you both add children and override the paint method. The default paint method is responsible for drawing children. You could call super.paint() in your paint method, but better to override paintComponent().
This is what the consol shows:
java.lang.NoClassDefFoundError: click1 (wrong name: click/click1)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
but I still didn't get it :S
Raieda at 2007-7-12 22:51:48 >
