Java Applet 启动时出错

发布于 2024-11-01 00:54:09 字数 10367 浏览 0 评论 0原文

我创建了一个小型 Java Applet 来为公司网站运行。我目前正在使用 Eclipse 进行开发,并且在尝试从相应的网页启动应用程序时遇到了问题。我的员工已将正确的 .JAR 文件与页面本身的 HTML 文件放在一起,并使用以下代码调用小程序:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<applet code=OrderForm.class name=OrderForm archive=OrderForm.jar
    width=700 height=1100 >
    <param name="bgcolor" value="ffffff">
    <param name="fontcolor" value="000000">
    Your browser is not Java enabled.
</applet>



</body>
</html>

所有这些对我来说似乎都是正确的,JAR 文件已正确标记,并且 .class 文件是正确的。当页面打开时,我收到消息“错误。单击查看详细信息”,但是当我单击“X”时,页面冻结并且不显示任何错误详细信息。

JAR 文件是使用 Eclipse 导出的,我确信我已经包含了所有需要编译的文件(因为它可以与 Eclipse 中的 Java Applet Viewer 完美编译)。这是下面的小程序,它只是我创建的一个测试小程序,因为我在尝试在公司网站上运行更大的小程序时收到了一些过去的错误,所以这涵盖了小程序本身的基本功能,谢谢。

package OrderForm;

import javax.swing.JPanel;
import javax.swing.JApplet;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.SwingUtilities;

import java.awt.Rectangle;
import java.lang.reflect.InvocationTargetException;

import javax.swing.JButton;

@SuppressWarnings("serial")
public class OrderForm extends JApplet {

    private JPanel mainPanel = null;  //  @jve:decl-index=0:visual-constraint="10,10"
    private JLabel titleLabel = null;
    private JLabel customerInfoLabel = null;
    private JLabel distributorLabel = null;
    private JLabel customerNameLabel = null;
    private JLabel existingCustomerLabel = null;
    private JLabel industryLabel = null;
    private JLabel emailAddressLabel = null;
    private JButton testing = null;
    private JTextField text_customerName = null;
    private JTextField text_emailAddress = null;
    private JComboBox distributors = null;
    private JComboBox industries = null;
    private JCheckBox check_existingCustomer = null;
    /**
     * This is the xxx default constructor
     */
    public OrderForm() {
        super();
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    public void init() {
        try 
        {
            SwingUtilities.invokeAndWait(new Runnable()
            {
                public void run()
                {
                    setSize(645, 373);
                    setContentPane(getJContentPane());
                }
            });
        }
        catch (InterruptedException e) { e.printStackTrace(); } 
        catch (InvocationTargetException e) { e.printStackTrace(); }
    }

    /**
     * This method initializes mainPanel
     * 
     * @return javax.swing.JPanel
     */
    private JPanel getJContentPane() {
        if (mainPanel == null) {
            emailAddressLabel = new JLabel();
            emailAddressLabel.setBounds(new Rectangle(164, 226, 137, 16));
            emailAddressLabel.setText("Email Address:");
            industryLabel = new JLabel();
            industryLabel.setBounds(new Rectangle(165, 196, 136, 16));
            industryLabel.setText("Industry:");
            existingCustomerLabel = new JLabel();
            existingCustomerLabel.setBounds(new Rectangle(165, 165, 136, 16));
            existingCustomerLabel.setText("Existing Customer?:");
            customerNameLabel = new JLabel();
            customerNameLabel.setBounds(new Rectangle(166, 134, 135, 16));
            customerNameLabel.setText("Customer Name:");
            distributorLabel = new JLabel();
            distributorLabel.setBounds(new Rectangle(165, 105, 136, 16));
            distributorLabel.setText("Distributor:");
            customerInfoLabel = new JLabel();
            customerInfoLabel.setBounds(new Rectangle(30, 60, 166, 31));
            customerInfoLabel.setText("Customer Information");
            titleLabel = new JLabel();
            titleLabel.setBounds(new Rectangle(180, 15, 286, 40));
            titleLabel.setText("Order Form");
            mainPanel = new JPanel();
            mainPanel.setSize(new Dimension(624, 1055));
            mainPanel.setLayout(null);
            mainPanel.setBackground(Color.white);
            mainPanel.add(titleLabel, null);
            mainPanel.add(customerInfoLabel, null);
            mainPanel.add(distributorLabel, null);
            mainPanel.add(customerNameLabel, null);
            mainPanel.add(existingCustomerLabel, null);
            mainPanel.add(industryLabel, null);
            mainPanel.add(emailAddressLabel, null);
            mainPanel.add(getTesting(), null);
            mainPanel.add(getText_customerName(), null);
            mainPanel.add(getText_emailAddress(), null);
            mainPanel.add(getDistributors(), null);
            mainPanel.add(getIndustries(), null);
            mainPanel.add(getCheck_existingCustomer(), null);
        }
        return mainPanel;
    }

    /**
     * This method initializes testing  
     *  
     * @return javax.swing.JButton  
     */
    private JButton getTesting() {
        if (testing == null) {
            testing = new JButton();
            testing.setBounds(new Rectangle(225, 285, 181, 61));
            testing.setText("TEST");
            testing.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    String distSelected = (String) distributors.getSelectedItem();
                    String industrySelected = (String) industries.getSelectedItem();

                    if(distSelected.equals("            "))
                        JOptionPane.showMessageDialog(null, "No Distributor Selected.", "Error", JOptionPane.INFORMATION_MESSAGE);
                    else if(industrySelected.equals("            "))
                        JOptionPane.showMessageDialog(null, "No Industry Selected.", "Error", JOptionPane.INFORMATION_MESSAGE);
                    else if(text_customerName.getText().length() == 0)
                        JOptionPane.showMessageDialog(null, "No Name Entered.", "Error", JOptionPane.INFORMATION_MESSAGE);
                    else if(text_emailAddress.getText().length() == 0)
                        JOptionPane.showMessageDialog(null, "No Email Entered.", "Error", JOptionPane.INFORMATION_MESSAGE);
                    else
                        JOptionPane.showMessageDialog(null, "Data Entered Successfully", "Success", JOptionPane.INFORMATION_MESSAGE);



                }
            });
        }
        return testing;
    }

    /**
     * This method initializes text_customerName    
     *  
     * @return javax.swing.JTextField   
     */
    private JTextField getText_customerName() {
        if (text_customerName == null) {
            text_customerName = new JTextField();
            text_customerName.setBounds(new Rectangle(300, 135, 121, 16));
        }
        return text_customerName;
    }

    /**
     * This method initializes text_emailAddress    
     *  
     * @return javax.swing.JTextField   
     */
    private JTextField getText_emailAddress() {
        if (text_emailAddress == null) {
            text_emailAddress = new JTextField();
            text_emailAddress.setBounds(new Rectangle(300, 225, 121, 16));
        }
        return text_emailAddress;
    }

    /**
     * This method initializes distributors 
     *  
     * @return javax.swing.JComboBox    
     */
    private JComboBox getDistributors() {
        if (distributors == null) {
            distributors = new JComboBox();
            distributors.setBounds(new Rectangle(300, 105, 121, 16));

            String[] distributorList = getDistributorList();

            for(String d:distributorList)
                distributors.addItem(d);
        }
        return distributors;
    }

    /**
     * Initialize the list of distributors for the drop-down list
     * @return String[] containing the names of all distributors
     */
    private String[] getDistributorList()
    {
        String[] distributors = 
        {       
                "            ",
                "a1envirotech", "Beun-De Ronde B.V.", "Biolab A/S", "BRS", "Camlab Ltd.", "DKSH Australia Pty Ltd.", "DKSH New Zealand Ltd.",
                "DKSH - Malaysia", "DKSH - Philippines", "DKSH - Singapore", "DKSH - Vietnam", "E&C Technology Co., Ltd.", "FKV s.r.l.",
                "G&W Marketing", "LICA United Technology Ltd.", "Mandel Scientific Company Inc.", "Mansci (Aaron Gotway)", "Mansci (Chris Copeland)",
                "Mansci (Jake Bolotin)", "Mansci (Matt Grey)", "Mansci (Wes Floyd)", "Serlabo", "Southern Systems Ltd.", "TM - Autolab",
                "Wirsam Scientific"
        };
        return distributors;
    }

    /**
     * This method initializes industries   
     *  
     * @return javax.swing.JComboBox    
     */
    private JComboBox getIndustries() {
        if (industries == null) {
            industries = new JComboBox();
            industries.setBounds(new Rectangle(300, 195, 121, 16));

            String[] industryList = getIndustryList();
            for(String i:industryList)
                industries.addItem(i);
        }
        return industries;
    }

    /**
     * Initialize the list of industries for the drop-down list
     */
    private String[] getIndustryList()
    {
        String[] industries = 
        {
                "            ", "Commercial Lab", "Environmental", "Food / Wine", "Government", "Marine Lab", 
                "Other", "Petro Chemical", "Power Generation", "Pulp & Paper", "University"
        };
        return industries;
    }

    /**
     * This method initializes check_existingCustomer   
     *  
     * @return javax.swing.JCheckBox    
     */
    private JCheckBox getCheck_existingCustomer() {
        if (check_existingCustomer == null) {
            check_existingCustomer = new JCheckBox();
            check_existingCustomer.setBounds(new Rectangle(300, 165, 31, 16));
        }
        return check_existingCustomer;
    }

}  //  @jve:decl-index=0:visual-constraint="10,10"

I've created a small Java Applet to run for a company website. I'm currently using Eclipse for development and I've run into problems while trying to launch the application from the appropriate web page. My employee has placed the correct .JAR file in with the HTML file of the page itself, and is calling the applet with the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<applet code=OrderForm.class name=OrderForm archive=OrderForm.jar
    width=700 height=1100 >
    <param name="bgcolor" value="ffffff">
    <param name="fontcolor" value="000000">
    Your browser is not Java enabled.
</applet>



</body>
</html>

All this seems correct to me, the JAR file is correctly labeled, and the .class file is correct. When the page opens, I get the message "Error. Click for Details", but when I click the 'X', the page freezes and doesn't show me any error details.

The JAR file was exported using Eclipse and I'm sure that I've included all the necessary files to compile (as it compiles perfectly with the Java Applet Viewer in Eclipse). Here's the applet below, it's simply a testing applet I created because of some past errors I was receiving when trying to run a larger applet on the company website, so this covers the basic functionality of the applet itself, thanks.

package OrderForm;

import javax.swing.JPanel;
import javax.swing.JApplet;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.SwingUtilities;

import java.awt.Rectangle;
import java.lang.reflect.InvocationTargetException;

import javax.swing.JButton;

@SuppressWarnings("serial")
public class OrderForm extends JApplet {

    private JPanel mainPanel = null;  //  @jve:decl-index=0:visual-constraint="10,10"
    private JLabel titleLabel = null;
    private JLabel customerInfoLabel = null;
    private JLabel distributorLabel = null;
    private JLabel customerNameLabel = null;
    private JLabel existingCustomerLabel = null;
    private JLabel industryLabel = null;
    private JLabel emailAddressLabel = null;
    private JButton testing = null;
    private JTextField text_customerName = null;
    private JTextField text_emailAddress = null;
    private JComboBox distributors = null;
    private JComboBox industries = null;
    private JCheckBox check_existingCustomer = null;
    /**
     * This is the xxx default constructor
     */
    public OrderForm() {
        super();
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    public void init() {
        try 
        {
            SwingUtilities.invokeAndWait(new Runnable()
            {
                public void run()
                {
                    setSize(645, 373);
                    setContentPane(getJContentPane());
                }
            });
        }
        catch (InterruptedException e) { e.printStackTrace(); } 
        catch (InvocationTargetException e) { e.printStackTrace(); }
    }

    /**
     * This method initializes mainPanel
     * 
     * @return javax.swing.JPanel
     */
    private JPanel getJContentPane() {
        if (mainPanel == null) {
            emailAddressLabel = new JLabel();
            emailAddressLabel.setBounds(new Rectangle(164, 226, 137, 16));
            emailAddressLabel.setText("Email Address:");
            industryLabel = new JLabel();
            industryLabel.setBounds(new Rectangle(165, 196, 136, 16));
            industryLabel.setText("Industry:");
            existingCustomerLabel = new JLabel();
            existingCustomerLabel.setBounds(new Rectangle(165, 165, 136, 16));
            existingCustomerLabel.setText("Existing Customer?:");
            customerNameLabel = new JLabel();
            customerNameLabel.setBounds(new Rectangle(166, 134, 135, 16));
            customerNameLabel.setText("Customer Name:");
            distributorLabel = new JLabel();
            distributorLabel.setBounds(new Rectangle(165, 105, 136, 16));
            distributorLabel.setText("Distributor:");
            customerInfoLabel = new JLabel();
            customerInfoLabel.setBounds(new Rectangle(30, 60, 166, 31));
            customerInfoLabel.setText("Customer Information");
            titleLabel = new JLabel();
            titleLabel.setBounds(new Rectangle(180, 15, 286, 40));
            titleLabel.setText("Order Form");
            mainPanel = new JPanel();
            mainPanel.setSize(new Dimension(624, 1055));
            mainPanel.setLayout(null);
            mainPanel.setBackground(Color.white);
            mainPanel.add(titleLabel, null);
            mainPanel.add(customerInfoLabel, null);
            mainPanel.add(distributorLabel, null);
            mainPanel.add(customerNameLabel, null);
            mainPanel.add(existingCustomerLabel, null);
            mainPanel.add(industryLabel, null);
            mainPanel.add(emailAddressLabel, null);
            mainPanel.add(getTesting(), null);
            mainPanel.add(getText_customerName(), null);
            mainPanel.add(getText_emailAddress(), null);
            mainPanel.add(getDistributors(), null);
            mainPanel.add(getIndustries(), null);
            mainPanel.add(getCheck_existingCustomer(), null);
        }
        return mainPanel;
    }

    /**
     * This method initializes testing  
     *  
     * @return javax.swing.JButton  
     */
    private JButton getTesting() {
        if (testing == null) {
            testing = new JButton();
            testing.setBounds(new Rectangle(225, 285, 181, 61));
            testing.setText("TEST");
            testing.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    String distSelected = (String) distributors.getSelectedItem();
                    String industrySelected = (String) industries.getSelectedItem();

                    if(distSelected.equals("            "))
                        JOptionPane.showMessageDialog(null, "No Distributor Selected.", "Error", JOptionPane.INFORMATION_MESSAGE);
                    else if(industrySelected.equals("            "))
                        JOptionPane.showMessageDialog(null, "No Industry Selected.", "Error", JOptionPane.INFORMATION_MESSAGE);
                    else if(text_customerName.getText().length() == 0)
                        JOptionPane.showMessageDialog(null, "No Name Entered.", "Error", JOptionPane.INFORMATION_MESSAGE);
                    else if(text_emailAddress.getText().length() == 0)
                        JOptionPane.showMessageDialog(null, "No Email Entered.", "Error", JOptionPane.INFORMATION_MESSAGE);
                    else
                        JOptionPane.showMessageDialog(null, "Data Entered Successfully", "Success", JOptionPane.INFORMATION_MESSAGE);



                }
            });
        }
        return testing;
    }

    /**
     * This method initializes text_customerName    
     *  
     * @return javax.swing.JTextField   
     */
    private JTextField getText_customerName() {
        if (text_customerName == null) {
            text_customerName = new JTextField();
            text_customerName.setBounds(new Rectangle(300, 135, 121, 16));
        }
        return text_customerName;
    }

    /**
     * This method initializes text_emailAddress    
     *  
     * @return javax.swing.JTextField   
     */
    private JTextField getText_emailAddress() {
        if (text_emailAddress == null) {
            text_emailAddress = new JTextField();
            text_emailAddress.setBounds(new Rectangle(300, 225, 121, 16));
        }
        return text_emailAddress;
    }

    /**
     * This method initializes distributors 
     *  
     * @return javax.swing.JComboBox    
     */
    private JComboBox getDistributors() {
        if (distributors == null) {
            distributors = new JComboBox();
            distributors.setBounds(new Rectangle(300, 105, 121, 16));

            String[] distributorList = getDistributorList();

            for(String d:distributorList)
                distributors.addItem(d);
        }
        return distributors;
    }

    /**
     * Initialize the list of distributors for the drop-down list
     * @return String[] containing the names of all distributors
     */
    private String[] getDistributorList()
    {
        String[] distributors = 
        {       
                "            ",
                "a1envirotech", "Beun-De Ronde B.V.", "Biolab A/S", "BRS", "Camlab Ltd.", "DKSH Australia Pty Ltd.", "DKSH New Zealand Ltd.",
                "DKSH - Malaysia", "DKSH - Philippines", "DKSH - Singapore", "DKSH - Vietnam", "E&C Technology Co., Ltd.", "FKV s.r.l.",
                "G&W Marketing", "LICA United Technology Ltd.", "Mandel Scientific Company Inc.", "Mansci (Aaron Gotway)", "Mansci (Chris Copeland)",
                "Mansci (Jake Bolotin)", "Mansci (Matt Grey)", "Mansci (Wes Floyd)", "Serlabo", "Southern Systems Ltd.", "TM - Autolab",
                "Wirsam Scientific"
        };
        return distributors;
    }

    /**
     * This method initializes industries   
     *  
     * @return javax.swing.JComboBox    
     */
    private JComboBox getIndustries() {
        if (industries == null) {
            industries = new JComboBox();
            industries.setBounds(new Rectangle(300, 195, 121, 16));

            String[] industryList = getIndustryList();
            for(String i:industryList)
                industries.addItem(i);
        }
        return industries;
    }

    /**
     * Initialize the list of industries for the drop-down list
     */
    private String[] getIndustryList()
    {
        String[] industries = 
        {
                "            ", "Commercial Lab", "Environmental", "Food / Wine", "Government", "Marine Lab", 
                "Other", "Petro Chemical", "Power Generation", "Pulp & Paper", "University"
        };
        return industries;
    }

    /**
     * This method initializes check_existingCustomer   
     *  
     * @return javax.swing.JCheckBox    
     */
    private JCheckBox getCheck_existingCustomer() {
        if (check_existingCustomer == null) {
            check_existingCustomer = new JCheckBox();
            check_existingCustomer.setBounds(new Rectangle(300, 165, 31, 16));
        }
        return check_existingCustomer;
    }

}  //  @jve:decl-index=0:visual-constraint="10,10"

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

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

发布评论

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

评论(1

等风来 2024-11-08 00:54:09

您的 JApplet 位于(非常规命名的)OrderForm 包 中,但是您的 标记未反映这一点。

Your JApplet is in the (unconventionally named) package OrderForm, but your <applet> tag does not reflect this.

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