有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

web应用程序Java小程序启动错误

我已经创建了一个小Java小程序,用于为公司网站运行。我目前正在使用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文件的标签是正确的,并且。类文件是正确的。当页面打开时,我收到消息“Error.Click for Details”,但当我单击“X”时,页面冻结,没有显示任何错误详细信息

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

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) 个答案

  1. # 1 楼答案

    您的JApplet位于(非常规命名的)package OrderForm中,但您的^{}标记并不反映这一点