为什么没有出现在基于Java的应用程序的Web JFrame的我? [英] Why is my JFrame not appearing in a web based Java app?

查看:554
本文介绍了为什么没有出现在基于Java的应用程序的Web JFrame的我?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我会在Web浏览器中使用标签上运行的游戏应用。
这个程序有一个JFrame,它显示了几个标签,允许在整个程序的导航。
当我在本地运行该程序将做工精细,显示在JFrame,并在全部工作。
然而,当我把它上传到主机和访问它的链接的JFrame将不显示。

我已搜查约3小时,只是必须不能为我siutation提供正确的关键字。
我可以在结果得到的是在JFrame根本不显示,本地​​或Web应用程序。

这是客户的样子,当我从同样的.jar本地运行:

这是客户端的外观在Web浏览器(IE尝试,FF和铬):

Applet.java:

 公共类客户端延伸RSApplet {    公共静态无效的主要(字符串ARGS []){
        尝试{
            例如=新客户();
            新的UserInterface(参数);
        }赶上(例外五){
            e.printStackTrace();
        }
    }}

GUI.java

 公共类GUI扩展的Applet实现的ActionListener,WindowListener的,{的FocusListener    公众的UserInterface(字符串ARGS []){
        尝试{
        / * ------------------------------------------------ ------------------------ * /
        / *金属* /
        / * UIManager.setLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel中); * /
        / *系统看* /
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        / * ------------------------------------------------ ------------------------ * /
            initGUI();
        }赶上(例外前){
            ex.printStackTrace();
        }
    }    公共无效initGUI(){
        尝试{
            JFrame.setDefaultLookAndFeelDecorated(真);
            JPopupMenu.setDefaultLightWeightPopupEnabled(假);
            帧=新的JFrame(frameTitle);
            frame.setLayout(新的BorderLayout());
            图片图标= Toolkit.getDefaultToolkit()的getImage(iconDir)。
            frame.setIconImage(图标);
            的GamePanel =新JPanel();
            gamePanel.setLayout(新的BorderLayout());
            gamePanel.add(本);
            gamePanel.set preferredSize(新尺寸(850,600));
            frame.getContentPane()加(的GamePanel,BorderLayout.CENTER)。
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            frame.addWindowListener(新WindowAdapter的(){
                公共无效的windowClosing(WindowEvent五){
                    如果(==的loggedIn假){
                        System.exit(0);
                    }其他{
                        如果(showMessage(你确定要关闭游戏?)==真){
                            System.exit(0);
                        }否则返回;
                    }
                }
            });
            initMenuBar();
            frame.pack();
            frame.setVisible(真);
            frame.setResizable(真);
        }赶上(例外五){
            e.printStackTrace();
        }
    }    公共无效initMenuBar(){
        菜单栏=新的JMenuBar();
        / **文件** /
        fileMenu =新JMenu,(文件);
        的String [] = fileMenuItems {
            放弃
        };
        menuBar.add(fileMenu);
        /** 快速链接 **/
        linksMenu =新JMenu,(快速链接);
        的String [] = linksMenuItems {
            家,新闻,捐赠
        };
        menuBar.add(linksMenu);
        frame.getContentPane()加(菜单栏,BorderLayout.NORTH)。
    }}


解决方案

您试图把应用程序在网页上,我的意思是作为Web应用程序运行。如果是的话那么你想要一个applet或JApplet的,而不是一个框架。帧正常工作,但你将它添加到一个网站,那么你需要使它成为一个小程序。使用下面的链接。

对于JApplet的类的http://下载.oracle.com / JavaSE的/ 6 /文档/ API /使用javax /秋千/ JApplet.html
JApplet的/ Applet的教程 - http://download.oracle.com/javase /tutorial/uiswing/components/applet.html

好运

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..

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.

This is how the client looks when I run it locally from the same .jar:

This is how the client looks in a web browser (tried IE, FF and Chrome):

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);
    }

}

解决方案

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..

JApplet class for se6- http://download.oracle.com/javase/6/docs/api/javax/swing/JApplet.html JApplet/Applet tutorial -- http://download.oracle.com/javase/tutorial/uiswing/components/applet.html

Good Luck

这篇关于为什么没有出现在基于Java的应用程序的Web JFrame的我?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆