浏览器不显示完整的 JApplet

发布于 2024-12-23 14:37:11 字数 4384 浏览 1 评论 0原文

测试时 Eclipse 中显示的内容如下: Eclipse applet runner

当我将其作为小程序启动时,这就是 Firefox/Chrome 浏览器中显示的内容: Running in Firefox/Chrome browser

HTML 代码:

<APPLET code='GUI.MainMenu.class' archive = 'Finance.jar'width="800" height="623"></APPLET>

在 java 中,主菜单下方的所有内容(顶部的库、调度程序和其他按钮)位于 ContentPane 变量 (JPanel) 中。当小程序加载时,首先加载显示这些表等的 Library(扩展 JPanel)类。

所以看起来浏览器无法访问该 Library.class,但在 jar 中它就在它的位置。有什么想法吗?

PS MainMenu.class(主类)在GUI包中,但Library.class在GUI.Library包

SSCCE中: 主

public MainMenu() {
    super();
    initGUI();
}

private void initGUI() {
    try {
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setSize(windowWidth, windowHeight + menuHeight);
        this.setPreferredSize(new java.awt.Dimension(windowWidth, windowHeight + menuHeight));
        this.setMinimumSize(new java.awt.Dimension(800, 623));
        {
            MenuPane = new JPanel();
            AnchorLayout MenuPaneLayout = new AnchorLayout();
            MenuPane.setLayout(MenuPaneLayout);
            getContentPane().add(MenuPane, BorderLayout.NORTH);
            MenuPane.setPreferredSize(new java.awt.Dimension(windowWidth, menuHeight));
            MenuPane.setMinimumSize(new java.awt.Dimension(windowWidth, menuHeight));
            {
                MLibrary = new JButton();
                MenuPane.add(MLibrary, new AnchorConstraint(0, 0, 0, 0, AnchorConstraint.ANCHOR_ABS, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_ABS, AnchorConstraint.ANCHOR_ABS));
                MLibrary.setText("Library");
                MLibrary.setPreferredSize(buttonSize);
                MLibrary.addActionListener(this);
                MLibrary.getModel().setPressed(true);
            }
            {
            //adds other main menu buttons by anchor..
            }
        }
        {
            renewContentPane(new Library());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
private void renewContentPane(JPanel pane) {
    if (ContentPane != null) {
        getContentPane().remove(ContentPane);
    }
    ContentPane = pane;
    getContentPane().add(ContentPane, BorderLayout.SOUTH);
    getContentPane().validate();
}

类库类:

public Library() {
    super();
    initGUI();
}

private void initGUI() {
    try {
        GridBagLayout thisLayout = new GridBagLayout();
        setPreferredSize(new Dimension(800, 600));
        thisLayout.rowWeights = new double[] {0.0, 0.0, 0.1};
        thisLayout.rowHeights = new int[] {35, 529, 7};
        thisLayout.columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.1};
        thisLayout.columnWidths = new int[] {85, 85, 85, 85, 85, 7};
        this.setLayout(thisLayout);
        {
        //adds account label and buttons
        }
        {//table of transactions
            tableTrans = new JTable(new LibraryTableModel());
            JScrollPane tableScroll = new JScrollPane(tableTrans);
            this.add(tableScroll, new GridBagConstraints(2, 0, 4, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
            tableScroll.setPreferredSize(new Dimension(610, 545));//630x565
            //tableTrans.setDefaultRenderer(Class.forName( "java.lang.String" ), new LibraryTableCellRenderer());
            tableTrans.getColumnModel().getColumn(0).setMaxWidth(15);
            tableTrans.getColumnModel().getColumn(4).setCellRenderer(new NumberFormatRenderer());
            //tableTrans.getColumnModel().getColumn(0).setMaxWidth(15);
        }
        {//table of accounts
            tableAccounts = new JTable(new AccountsTableModel());
            JScrollPane accTableScroll = new JScrollPane(tableAccounts);
            this.add(accTableScroll, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
            tableAccounts.setTableHeader(null);
            //tableAccounts.setShowGrid(false);
            tableAccounts.getColumnModel().getColumn(0).setMaxWidth(25);
            tableAccounts.setRowHeight(25);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

This what shows up in Eclipse when testing:
Eclipse applet runner

And this is what show up in Firefox/Chrome browser, when I launch it as applet:
Running in Firefox/Chrome browser

HTML code:

<APPLET code='GUI.MainMenu.class' archive = 'Finance.jar'width="800" height="623"></APPLET>

In java, everything below main menu (Library, Scheduler and other buttons on top) is in ContentPane variable (JPanel). When applet loads, first loads Library (extends JPanel) class which shows those tables and etc.

So it looks like browser can't reach that Library.class, but in jar it is in its place. Have any ideas?

P.S. MainMenu.class (main class) is in GUI package, but Library.class is in GUI.Library package

SSCCE:
Main class

public MainMenu() {
    super();
    initGUI();
}

private void initGUI() {
    try {
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setSize(windowWidth, windowHeight + menuHeight);
        this.setPreferredSize(new java.awt.Dimension(windowWidth, windowHeight + menuHeight));
        this.setMinimumSize(new java.awt.Dimension(800, 623));
        {
            MenuPane = new JPanel();
            AnchorLayout MenuPaneLayout = new AnchorLayout();
            MenuPane.setLayout(MenuPaneLayout);
            getContentPane().add(MenuPane, BorderLayout.NORTH);
            MenuPane.setPreferredSize(new java.awt.Dimension(windowWidth, menuHeight));
            MenuPane.setMinimumSize(new java.awt.Dimension(windowWidth, menuHeight));
            {
                MLibrary = new JButton();
                MenuPane.add(MLibrary, new AnchorConstraint(0, 0, 0, 0, AnchorConstraint.ANCHOR_ABS, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_ABS, AnchorConstraint.ANCHOR_ABS));
                MLibrary.setText("Library");
                MLibrary.setPreferredSize(buttonSize);
                MLibrary.addActionListener(this);
                MLibrary.getModel().setPressed(true);
            }
            {
            //adds other main menu buttons by anchor..
            }
        }
        {
            renewContentPane(new Library());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
private void renewContentPane(JPanel pane) {
    if (ContentPane != null) {
        getContentPane().remove(ContentPane);
    }
    ContentPane = pane;
    getContentPane().add(ContentPane, BorderLayout.SOUTH);
    getContentPane().validate();
}

Library class:

public Library() {
    super();
    initGUI();
}

private void initGUI() {
    try {
        GridBagLayout thisLayout = new GridBagLayout();
        setPreferredSize(new Dimension(800, 600));
        thisLayout.rowWeights = new double[] {0.0, 0.0, 0.1};
        thisLayout.rowHeights = new int[] {35, 529, 7};
        thisLayout.columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.1};
        thisLayout.columnWidths = new int[] {85, 85, 85, 85, 85, 7};
        this.setLayout(thisLayout);
        {
        //adds account label and buttons
        }
        {//table of transactions
            tableTrans = new JTable(new LibraryTableModel());
            JScrollPane tableScroll = new JScrollPane(tableTrans);
            this.add(tableScroll, new GridBagConstraints(2, 0, 4, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
            tableScroll.setPreferredSize(new Dimension(610, 545));//630x565
            //tableTrans.setDefaultRenderer(Class.forName( "java.lang.String" ), new LibraryTableCellRenderer());
            tableTrans.getColumnModel().getColumn(0).setMaxWidth(15);
            tableTrans.getColumnModel().getColumn(4).setCellRenderer(new NumberFormatRenderer());
            //tableTrans.getColumnModel().getColumn(0).setMaxWidth(15);
        }
        {//table of accounts
            tableAccounts = new JTable(new AccountsTableModel());
            JScrollPane accTableScroll = new JScrollPane(tableAccounts);
            this.add(accTableScroll, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
            tableAccounts.setTableHeader(null);
            //tableAccounts.setShowGrid(false);
            tableAccounts.getColumnModel().getColumn(0).setMaxWidth(25);
            tableAccounts.setRowHeight(25);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫儰鉨ミ守葔 2024-12-30 14:37:11
<APPLET code='GUI.MainMenu.class' archive = 'Finance.jar'width="800" height="623">
</APPLET>

jar'width 之后似乎缺少一个空格。

<APPLET code='GUI.MainMenu.class' archive = 'Finance.jar'width="800" height="623">
</APPLET>

There seems a space to be missing after jar' and width.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文