JApplet问题说明找不到类,找不到类异常

时间:2015-03-02 20:59:00

标签: java japplet jcreator

我遇到的问题是给我一条错误消息,并且出现了一个空白小程序。错误消息显示load:class Myapp.class not found and java.lang.ClassNotFoundException,然后是一行代表@和其他一些行话。

如果我运行尝试将程序作为Jcreator applet运行,就像我预期的那样我得到了先前声明的错误,如果我在应用程序中运行它,它只是给我主要的方法错误。

这是我的计划:

package MyPack;

import javax.swing.*;
import java.awt.event.*;
public class Myapp extends JApplet implements ItemListener{



 JButton jbtnOne;
 JButton jbtnTwo;
 JLabel jlab;
 JComboBox comboBox;
 JComboBox comboBox_1;
 JCheckBox chckbxPizza;
 JCheckBox chckbxBurger;
 JCheckBox chckbxSalad;
 JLabel label_3;
 private JTextField textField;
 private JTextField textField_1;
 private JTextField textField_2;
 JTextArea txtrCommentsForSpecial;
 JTextArea txtrCommentsForSpecial_2;
 JTextArea txtrCommentsForSpecial_1;
 JInternalFrame internalFrame;
public Myapp() {
}



  public void init() {
      setSize(700,640);
     // setVisible(true);
    try {
      SwingUtilities.invokeAndWait(new Runnable () {
        public void run() {
          guiInit(); // initialize the GUI
        }
      });
    } catch(Exception exc) {
      System.out.println("Can't create because of "+ exc);
    }
  }

  // Called second, after init().  Also called
  // whenever the applet is restarted.
  public void start() {
    // Not used by this applet.
  }

  // Called when the applet is stopped.
  public void stop() {
    // Not used by this applet.
  }

  // Called when applet is terminated.  This is
  // the last method executed.
  public void destroy() {
    // Not used by this applet.
  }

  // Setup and initialize the GUI.
  private void guiInit() {
    // Create two buttons and a label.
    //  setLayout(null);
      String a[] = { "Chiken Tikka", "Fajita", "Vegetable"};
      comboBox = new JComboBox(a);
      comboBox.setBounds(115, 103, 100, 20);
      comboBox.addItemListener(this);
      getContentPane().add(comboBox);

      String b[] = { "small", "medium","large","extra large"};
      comboBox_1 = new JComboBox(b);
     // comboBox_1.addItemListener(this);
     // comboBox_1.setEnabled(false);
      getContentPane().add(comboBox_1);
      comboBox_1.setBounds(290, 103, 140, 20);
     // setSize(300, 300);
    getContentPane().setLayout(null);
    JLabel lblSelectMenu = new JLabel("Select Menu");
    lblSelectMenu.setForeground(new Color(72, 61, 139));
    lblSelectMenu.setFont(new Font("Segoe Script", Font.BOLD, 16));
    lblSelectMenu.setBounds(58, 10, 107, 34);
    getContentPane().add(lblSelectMenu);

    chckbxPizza = new JCheckBox("Pizza");
    chckbxPizza.setBounds(37, 64, 97, 23);
    getContentPane().add(chckbxPizza);

    JLabel lblFlavour = new JLabel("flavour");
    lblFlavour.setBounds(60, 103, 45, 20);
    getContentPane().add(lblFlavour);

    JLabel lblSize = new JLabel("size");
    lblSize.setBounds(253, 103, 45, 20);
    getContentPane().add(lblSize);

    JLabel lblQty = new JLabel("Qty");
    lblQty.setBounds(451, 103, 35, 20);
    getContentPane().add(lblQty);

    textField = new JTextField();
    textField.setBounds(485, 103, 86, 20);
    getContentPane().add(textField);
    textField.setColumns(10);

    JLabel lblComments = new JLabel("comments");
    lblComments.setBounds(139, 154, 76, 20);
    getContentPane().add(lblComments);

     txtrCommentsForSpecial = new JTextArea();
    txtrCommentsForSpecial.setForeground(new Color(220, 220, 220));
    txtrCommentsForSpecial.setText("comments for special features");
    txtrCommentsForSpecial.setBounds(210, 154, 268, 61);
    getContentPane().add(txtrCommentsForSpecial);

    chckbxBurger = new JCheckBox("Burger");
    chckbxBurger.setBounds(37, 236, 97, 23);
    getContentPane().add(chckbxBurger);

    JLabel label = new JLabel("flavour");
    label.setBounds(60, 286, 45, 20);
    getContentPane().add(label);

    String c[] = { "Fish", "Vegetable", "Chicken"};
    JComboBox comboBox_2 = new JComboBox(c);
    comboBox_2.setBounds(115, 286, 100, 20);
    getContentPane().add(comboBox_2);

    JLabel label_1 = new JLabel("size");
    label_1.setBounds(253, 286, 45, 20);
    getContentPane().add(label_1);

    JComboBox comboBox_3 = new JComboBox(b);
    comboBox_3.setBounds(290, 286, 110, 20);
    getContentPane().add(comboBox_3);

    JLabel label_2 = new JLabel("Qty");
    label_2.setBounds(451, 286, 35, 20);
    getContentPane().add(label_2);

    textField_1 = new JTextField();
    textField_1.setBounds(485, 286, 86, 20);
    getContentPane().add(textField_1);
    textField_1.setColumns(10);

    label_3     = new JLabel("comments");
    label_3.setBounds(139, 340, 76, 20);
    getContentPane().add(label_3);

     txtrCommentsForSpecial_1 = new JTextArea();
    txtrCommentsForSpecial_1.setForeground(new Color(220, 220, 220));
    txtrCommentsForSpecial_1.setText("comments for special features");
    txtrCommentsForSpecial_1.setBounds(210, 340, 268, 61);
    getContentPane().add(txtrCommentsForSpecial_1);

  chckbxSalad = new JCheckBox("Soft Drink");
    chckbxSalad.setBounds(37, 424, 97, 23);
    getContentPane().add(chckbxSalad);

    JLabel label_4 = new JLabel("flavour");
    label_4.setBounds(60, 475, 45, 20);
    getContentPane().add(label_4);

    String f[] = { "Pepsi", "Coca Cola", "Sprite","7up"};
    JComboBox comboBox_4 = new JComboBox(f);
    comboBox_4.setBounds(115, 475, 86, 20);
    getContentPane().add(comboBox_4);

    JLabel label_5 = new JLabel("size");
    label_5.setBounds(253, 475, 45, 20);
    getContentPane().add(label_5);

    JComboBox comboBox_5 = new JComboBox(b);
    comboBox_5.setBounds(290, 475, 110, 20);
    getContentPane().add(comboBox_5);

    JLabel label_6 = new JLabel("Qty");
    label_6.setBounds(451, 475, 35, 20);
    getContentPane().add(label_6);

    textField_2 = new JTextField();
    textField_2.setBounds(485, 475, 86, 20);
    getContentPane().add(textField_2);
    textField_2.setColumns(10);

    JLabel label_7 = new JLabel("comments");
    label_7.setBounds(139, 546, 76, 20);
    getContentPane().add(label_7);

    txtrCommentsForSpecial_2 = new JTextArea();
    txtrCommentsForSpecial_2.setForeground(new Color(220, 220, 220));
    txtrCommentsForSpecial_2.setText("comments for special features");
    txtrCommentsForSpecial_2.setBounds(210, 546, 268, 61);
    getContentPane().add(txtrCommentsForSpecial_2);

    JButton btnNewButton = new JButton("Ok");
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
              internalFrame = new JInternalFrame("Order Details");
             internalFrame.setBounds(100, 80, 450, 300);
             internalFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             internalFrame.getContentPane().setLayout(null);
             internalFrame.setVisible(true);
                JTextArea textArea = new JTextArea();
                textArea.setBounds(67, 52, 270, 149);
                internalFrame.getContentPane().add(textArea);

                JButton btnOk = new JButton("Ok");
                btnOk.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        internalFrame.setVisible(false);
                    }
                });
                btnOk.setBounds(164, 212, 89, 23);
                internalFrame.getContentPane().add(btnOk);

                JLabel lblOrderYouPlaced = new JLabel("Order You Placed");
                lblOrderYouPlaced.setBounds(67, 26, 98, 14);
                internalFrame.getContentPane().add(lblOrderYouPlaced);

                getContentPane().add(internalFrame);

        }
    });
    btnNewButton.setBounds(162, 616, 89, 23);
    getContentPane().add(btnNewButton);

    JButton btnNewButton_1 = new JButton("Reset");
    btnNewButton_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textField.setText("");
            textField_1.setText("");
            textField_2.setText("");
            chckbxPizza.setText("");
              chckbxBurger.setText("");
              chckbxSalad.setText("");
              txtrCommentsForSpecial.setText("");
              txtrCommentsForSpecial_2.setText("");
              txtrCommentsForSpecial_1.setText("");
        }
    });
    btnNewButton_1.setBounds(279, 616, 89, 23);
    getContentPane().add(btnNewButton_1);

    JButton btnNewButton_2 = new JButton("Cancel");
    btnNewButton_2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    btnNewButton_2.setBounds(389, 616, 89, 23);
    getContentPane().add(btnNewButton_2);

  }
  public void itemStateChanged(ItemEvent e) {
      String b[] = { "Chikken Tikka", "Fajita" };
      String c[] = { "Fish", "Vegetable", "Chicken"};
      String d[] = { "Russian Salad", "Fruit Salad", "Beans Salad"};
      String f[] = { "Pepsi", "Coca Cola", "Sprite","7up"};

      if (e.getSource() == comboBox) {
              if (comboBox.getSelectedItem().equals("Select")) {
                      comboBox_1.setEnabled(false);
              } else if (comboBox.getSelectedItem().equals("Pizza")) {
                  comboBox_1.setEnabled(true);
                  comboBox_1.removeAllItems();
                      for (int i = 0; i < b.length; i++) {
                          comboBox_1.addItem(b[i]);
                      }
              } else if (comboBox.getSelectedItem().equals("Burger")) {
                  comboBox_1.setEnabled(true);
                  comboBox_1.removeAllItems();
                      for (int i = 0; i < c.length; i++) {
                          comboBox_1.removeItem(c[i]);
                          comboBox_1.addItem(c[i]);
                      }
              } else if (comboBox.getSelectedItem().equals("Salad")) {
                  comboBox_1.setEnabled(true);
                  comboBox_1.removeAllItems();
                      for (int i = 0; i < d.length; i++) {
                          comboBox_1.addItem(d[i]);
                      }
              }else if (comboBox.getSelectedItem().equals("Soft Drink")) {
                  comboBox_1.setEnabled(true);
                  comboBox_1.removeAllItems();
                      for (int i = 0; i < f.length; i++) {
                          comboBox_1.addItem(f[i]);
                      }
      }


}

  }
}

1 个答案:

答案 0 :(得分:0)

使用大写字母(例如

)编写itemListener
 public class Myapp extends JApplet implements ItemListener{

并导入所有这些包:

 import java.awt.Color;
 import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;

 import javax.swing.JApplet;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
 import javax.swing.JFrame;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JTextArea;
 import javax.swing.JTextField;
 import javax.swing.SwingUtilities;