简体   繁体   中英

Java Applet Error Launching

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"

您的JApplet位于(以非常规方式命名的) package OrderForm ,但是您的<applet>标记不反映这一点。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM