Java Applet错误启动

时间:2011-04-12 18:11:38

标签: java web-applications applet

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

<!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”时,页面会冻结,并且不会向我显示任何错误详细信息。

使用Eclipse导出JAR文件,我确信我已经包含了所有必要的文件进行编译(因为它与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"

1 个答案:

答案 0 :(得分:1)

您的JApplet位于(非常规名称)package OrderForm,但您的<applet>代码并未反映此内容。