1

我今天写了这样的代码:

import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import net.miginfocom.swing.MigLayout;

@SuppressWarnings("serial")
public class mainClass extends JApplet {

    public void init() {
        //Execute a job on the event-dispatching thread; creating this applet's GUI.
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {

                    try {

                        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

                        JPanel czat = new JPanel();

                        setLayout(new MigLayout());

                        JPanel panel3 = new JPanel();
                        panel3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Gry"));

                        add(panel3, "height 200:75%:10000, width 200:75%:10000");

                        JPanel panel1 = new JPanel();
                        panel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Gracze"));

                        add(panel1, "height 200:75%:10000, width 50:25%:10000, wrap");

                        JPanel panel2 = new JPanel();
                        panel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Czat"));

                        add(czat, "height 50:25%:10000, width 100%, span");

                        setVisible(true); // important


                    } catch (Exception e) {
                        e.printStackTrace();
                    }


                }
            });
        } catch (Exception e) {
            System.err.println("createGUI didn't complete successfully");
        }
    }
}

谁能告诉,为什么它在 Applet 查看器中工作,而不是在浏览器中工作?在我使用 MigLayout 之前正在工作。我使用的html代码是:

<html>
<applet alt = "Aplikacja klienta" code = 'mainClass' archive = 'applet.jar', width=500, height=500 />
</html>

我在各个地方寻找,但我找不到解决方案。

提前致谢, 马尔辛

4

1 回答 1

2

请尝试使用此版本的 HTML,确保将“nn”与正在使用的 MigLayout 的版本号交换。

<html>
<body>
<applet
    alt="Aplikacja klienta"
    code='mainClass'
    archive='applet.jar, miglayout-n.n-swing.jar, miglayout-n.n.jar'
    width=500
    height=500 >
</applet>
</body>
</html>

不要害怕使用验证服务检查 HTML 。那个 HTML 在很多方面都是无效的,以至于我数不清了!

作为另一个提示,确保将 Java 控制台配置为在加载小程序时打开。这对于小程序开发至关重要。在 Java 控制面板的最后一个选项卡下配置它。

于 2012-03-14T20:31:01.837 回答