简体   繁体   中英

Java.lang.reflect.InvocationTargetException JApplet/HTML

Ok so this is my first applet, I tried many times to bypass this Exception. Any sort of help would be really appreciated! Thank you!

Here is my code:

package Application;

import java.applet.*;
import java.awt.*;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JPanel;

public class FirstApplet extends JApplet
{
    private JPanel jpnlMain = new JPanel(new BorderLayout());
    private JPanel jpnlBoutton = new JPanel(new GridLayout(5,5));
    private JPanel jpnlLogo = new JSplash(this);
    private GenericRoundedButton[] jbtnAllo = new GenericRoundedButton[10];

    public void init(){
        super.init();
        this.add(jpnlMain);
        for(int i =0;i<jbtnAllo.length;i++){
            jbtnAllo[i] = new GenericRoundedButton();
            jpnlBoutton.add(jbtnAllo[i]);
        }       
        jpnlMain.add(jpnlBoutton,"North");
        jpnlMain.add(jpnlLogo,"Center");
    }
}

And here is My HTML Code:

<html>
    <title>The ImageDemo applet</title>
    <hr>
        <applet code="Application.FirstApplet.class" width="400" height="400">
    </applet>
    <hr>
</html>

This code (an SSCCE that is very close to your code) loads without showing any exceptions. I can conclude from that, that the problem lies in the parts of the code you chose not to include.

// <applet code=FirstApplet width=400 height=400></applet>
import java.awt.*;
import javax.swing.*;

public class FirstApplet extends JApplet
{
    private JPanel jpnlMain = new JPanel(new BorderLayout());
    private JPanel jpnlBoutton = new JPanel(new GridLayout(5,5));
    private JPanel jpnlLogo = new JPanel();
    private JButton[] jbtnAllo = new JButton[10];

    public void init(){
        super.init();
        this.add(jpnlMain);
        for(int i =0;i<jbtnAllo.length;i++){
            jbtnAllo[i] = new JButton();
            jpnlBoutton.add(jbtnAllo[i]);
        }
        jpnlMain.add(jpnlBoutton,"North");
        jpnlMain.add(jpnlLogo,"Center");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM