0

我有这个项目需要发布,但不知道哪种方式最好。有人可以帮我吗。

我有一个 Gui 应用程序(Jframe)。在那里,我有一个 Jpanel,其中包含一些动画(实现可运行)。所以在我的主要方法中,我会先调用构造函数,所以一切都显示得很好,然后调用 Runner.start()。(线)

所以基本上 gui 弹出然后动画发生,具体来说,动画只是我的程序的标题滑入。

现在我想把它放在网站上,以便我的学生可以使用。我不想使用 java web start,我希望它充当一个小程序。

那么我要把这个jframe放到我的applet中吗?还是我应该将整个事情从 jframe 转换为 japplet?这个小程序需要实现Runnable吗?

让我烦恼的是 Japplet 没有 main 方法,那么我怎样才能指定我的 Jpanel 何时可以执行它的动画呢?我希望动画在所有内容都加载到屏幕上之后发生,而不是之前。

我想把它作为 init() 方法的最后一条语句?如果我错了,请纠正我。

谢谢,

4

2 回答 2

3

我有一个 Gui 应用程序(Jframe)。..我想把这个放在网站上,以便我的学生可以使用。

虽然可以将框架转换为小程序,但更好的选择是使用Java Web Start从链接启动框架。

于 2012-11-08T23:51:51.910 回答
2

你可以同时做:

主界面

import java.awt.BorderLayout;
import javax.swing.*;
public class MainGui extends JPanel {
    public MainGui() {
        this(null);
    } 
    public MainGui(MyJApplet applet) {
        this.applet = applet;
        if (!isApplet()) {
            frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        } else
            frame = null;
        setLayout(new BorderLayout());
        // setPreferredSize(new Dimension(640, 480));
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                MainGui.this.run();
            }
        });
    }
    String title() {
        return "Title";
    }
    public void addContent() {
        add(new JLabel("add content! top"));
    }
    void run() {
        if (isApplet()) addContent();
        else {
            frame.setTitle(title());
            frame.getContentPane().add(this, BorderLayout.CENTER);
            addContent();
            frame.pack();
            System.out.println(getSize());
            frame.setVisible(true);
        }
    }
    boolean isApplet() {
        return applet != null;
    }
    public static void main(String[] args) {
        new MainGui(null);
    }
    protected final JFrame frame;
    protected final MyJApplet applet;
    private static final long serialVersionUID = 1;
}

MyJApplet

import java.awt.BorderLayout;
import javax.swing.JApplet;
public class MyJApplet extends JApplet {
    public void start() {

    }
    public void init() {
        getContentPane().setLayout(new BorderLayout());
        addContent();
    }
    public void addContent() {
        getContentPane().add(new MainGui(this), BorderLayout.CENTER);
    }
    public static void main(String[] args) {
        new MainGui(null);
    }
    private static final long serialVersionUID = 1;
}
于 2012-11-09T00:14:37.307 回答