我有这个项目,我需要发布,但不知道哪种方式将是最好的。谁能帮帮我。
我有一个Gui应用程序(Jframe)。在那里我有一个包含一些动画的Jpanel (implement runnable)。所以在我的main方法中,我会先调用构造函数,这样一切都会很好地显示,然后再调用Runner.start()。(线程)
所以基本上图形用户界面弹出,然后动画发生,具体地说,动画只是我的程序的标题,幻灯片。
现在我想把这个放到网站上,这样我的学生就可以使用了。我不想使用java web start,我想让它充当applet。
那么我应该把这个jframe放到我的applet中吗?或者我应该把整个东西从jframe转换成japplet?这个小程序需要实现Runnable吗?
让我头疼的是Japplet没有main方法,那么我如何指定我的Jpanel何时可以执行它的动画呢?我希望动画发生在一切都加载到屏幕上之后,而不是之前。
我想把它作为init()方法的最后一条语句?如果我错了,请纠正我。
谢谢,
发布于 2012-11-09 07:51:52
我有一个 Gui 应用程序(Jframe)。 ..我想把这个放在网站上,以便我的学生可以使用。
虽然可以将框架转换为小程序,但更好的选择是使用Java Web Start从链接启动框架。
发布于 2012-11-09 08:14:37
你可以同时做:
主界面
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;
}https://stackoverflow.com/questions/13298380
复制相似问题