//:  checkboxes.javaimport javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class CheckBoxes extends JApplet {
  private JTextArea t = new JTextArea("JTextArea",6,15);
  private JCheckBox
    cb1 = new JCheckBox("Check Box 1"),
    cb2 = new JCheckBox("Check Box 2"),
    cb3 = new JCheckBox("Check Box 3");
    public void init() {
    cb1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        trace("1",cb1);
      }
    });
    cb2.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        trace("2",cb2);
      }
    });
    cb3.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        trace("3",cb3);
      }
    });    
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(new JScrollPane(t));
    cp.add(cb1);
    cp.add(cb2);
    cp.add(cb3);
  }
  private void trace(String b,JCheckBox cb) {
    if(cb.isSelected())
      t.append("Box "+b+" Set\n");
    else 
      t.append("Box "+b+" cleared\n");
  }
  public static void main(String[] args) {
    Console.run(new CheckBoxes(),200,200);
  }
}/*-----------------------------------------------------------------------------
  编译后出现错误:
D:\java\c14\c565>javac checkboxes.java
checkboxes.java:43: cannot find symbol
symbol  : variable Console
location: class CheckBoxes
    Console.run(new CheckBoxes(),200,200);
    ^
1 error
--请问这是什么原因?如果把下面句子删了,在IE上又可以打开
  public static void main(String[] args) {
    Console.run(new CheckBoxes(),200,200);
  }
------------------------------------------------------------------------------*/

解决方案 »

  1.   

    但是下面的程序可以运行啊!
    //: Box1.javaimport javax.swing.*;
    import java.awt.*;public class Box1 extends JApplet {
      public void init() {
        Box bv = Box.createVerticalBox();
        for(int i=0; i<5; i++)
          bv.add(new JButton("bv"+i));    Box bh = Box.createHorizontalBox();
        for(int i=0; i<5; i++)
          bh.add(new JButton("bh"+i));
        Container cp = getContentPane();
        cp.add(BorderLayout.EAST,bv);
        cp.add(BorderLayout.SOUTH,bh);
      }
      public static void main(String[] args) {
        Console.run(new Box1(),450,200);
      }