这段程序为什么在JBuilder可以运行,在DOS下编译不可以呢。
程序代码:
import java.awt.*; import java.awt.event.*; public class Button { public static void main(String args[]) { MyButton but=new MyButton("窗口"); } } class MyButton extends Frame implements ActionListener { Button button1,button2,button3; MyButton(String s) { this.setTitle("Button"); setLayout(new FlowLayout()); button1=new Button("红色"); button2=new Button("绿色"); button3=new Button("黄色"); add(button1); add(button2); add(button3); button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this); setBounds(100,100,300,200); setVisible(true); validate(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==button1) { this.setBackground(Color.red); } if(e.getSource()==button2) { this.setBackground(Color.green); } if(e.getSource()==button3) { this.setBackground(Color.yellow); } } }装的都是JDK1.6