问题描述
我有一个游戏应用程序,我将使用该标签在网络浏览器中运行该应用程序.这个程序有一个 JFrame,它显示了几个选项卡,允许在整个程序中导航.当我在本地运行程序时,它会正常工作,显示 JFrame 并完整工作.但是,当我将它上传到主机并访问它的链接时,JFrame 不会显示..
I have a game application that I will be running in a web browser using the tag.This program has a JFrame, which displays a couple of tabs allowing navigation throughout the program.When I run the program locally it will work fine, displaying the JFrame and working in entirety.However when I upload it to the host and visit it's link the JFrame will not display..
我已经搜索了大约 3 个小时,根本无法为我的情况提供正确的关键字.我所能得到的结果是 JFrame 根本没有出现在本地或网络应用程序中.
I have searched about 3 hours and simply must not be able to provide the correct keywords for my siutation.All I can get in results is the JFrame not appearing at all, locally or web app.
这是我从同一个 .jar 在本地运行客户端时的样子:
This is how the client looks when I run it locally from the same .jar:
这是客户端在网络浏览器中的外观(尝试过 IE、FF 和 Chrome):
This is how the client looks in a web browser (tried IE, FF and Chrome):
Applet.java:
Applet.java:
public class Client extends RSApplet {
public static void main(String args[]) {
try {
instance = new Client();
new UserInterface(args);
} catch(Exception e) {
e.printStackTrace();
}
}
}
GUI.java
public class GUI extends Applet implements ActionListener, WindowListener, FocusListener {
public UserInterface(String args[]) {
try {
/* ------------------------------------------------------------------------ */
/* Metal */
/* UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); */
/* System Look */
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
/* ------------------------------------------------------------------------ */
initGUI();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void initGUI() {
try {
JFrame.setDefaultLookAndFeelDecorated(true);
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
frame = new JFrame(frameTitle);
frame.setLayout(new BorderLayout());
Image icon = Toolkit.getDefaultToolkit().getImage(iconDir);
frame.setIconImage(icon);
gamePanel = new JPanel();
gamePanel.setLayout(new BorderLayout());
gamePanel.add(this);
gamePanel.setPreferredSize(new Dimension(850, 600));
frame.getContentPane().add(gamePanel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (loggedIn == false) {
System.exit(0);
} else {
if (showMessage("Are you sure you want to close the game?") == true) {
System.exit(0);
} else return;
}
}
});
initMenuBar();
frame.pack();
frame.setVisible(true);
frame.setResizable(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public void initMenuBar() {
menuBar = new JMenuBar();
/** File **/
fileMenu = new JMenu("File");
String[] fileMenuItems = {
"Quit"
};
menuBar.add(fileMenu);
/** Quick Links **/
linksMenu = new JMenu("Quick Links");
String[] linksMenuItems = {
"Home", "News", "Donate"
};
menuBar.add(linksMenu);
frame.getContentPane().add(menuBar, BorderLayout.NORTH);
}
}
推荐答案
您是否尝试将应用程序放在网页上,我的意思是作为 Web 应用程序运行.如果是,那么您需要 Applet 或 JApplet 而不是框架.一个框架可以正常工作,但是如果您要将其添加到网站,则需要将其设为小程序.请使用以下链接..
Are you trying to put the application on a web page, i mean to run as a web application. If yes then you want an Applet or JApplet and not a frame. A frame works normally but for you to add it to a website then you need to make it an applet. Make use of the links below..
se6 的 JApplet 类 - http://download.oracle.com/javase/6/docs/api/javax/swing/JApplet.htmlJApplet/Applet 教程 -- http://download.oracle.com/javase/tutorial/uiswing/components/applet.html
JApplet class for se6- http://download.oracle.com/javase/6/docs/api/javax/swing/JApplet.htmlJApplet/Applet tutorial -- http://download.oracle.com/javase/tutorial/uiswing/components/applet.html
祝你好运
这篇关于为什么我的 JFrame 没有出现在基于 Web 的 Java 应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!