簡體   English   中英

Java Applet無法正確顯示

[英]Java applet not showing correctly

我做了一個Java Applet。

<applet code=gui.clientGUI.MyApplet.class 
        archive="QTminer.jar"
        width=400 height=200>
</applet>

我的罐子看起來像這樣:

在此處輸入圖片說明

這是我的簡單代碼:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;

public class MyApplet extends JApplet {

    public void init() {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    initUI();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void initUI() {
        getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

        JButton btnStartApplication = new JButton("Start Application");
        btnStartApplication.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                SS oi = new SS();
                oi.setVisible(true);
            }
        });
        getContentPane().add(btnStartApplication);
    }
}

class SS extends JWindow {

    private JLabel lblNewLabel;
    private JLabel label;

    public SS() {
    setBounds(new Rectangle(0, 0, 883, 590));
    setLocationRelativeTo(null);
    getContentPane().setLayout(null);

    lblNewLabel = new JLabel("Welcome", SwingConstants.CENTER);
    lblNewLabel.setForeground(Color.RED);
    lblNewLabel.setFont(new Font("Segoe UI", Font.BOLD | Font.ITALIC, 24));
    lblNewLabel.setBounds(0, 313, 883, 41);
    getContentPane().add(lblNewLabel);

    label = new JLabel(new ImageIcon(getClass().getResource("/gui/resources/Qtminer_background.jpg")));

    label.setBounds(0, 0, 883, 592);
    getContentPane().add(label);

    setVisible(true);
}
}

我的問題是,在eclipse中運行時,一切正常,但是在瀏覽器中運行時,我在圖像圖標的負載上得到了NullPointerException:

label.setIcon(new ImageIcon(getClass().getResource("/gui/resources/Qtminer_background.jpg")));

我的操作系統拒絕訪問本地文件jar。

在真實的Web服務器上測試applet使其正常工作。

解決了!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM