下面的程序在昨天还正常,今天打开运行却提示错误:如下:
Exception in thread "main" java.lang.NoClassDefFoundError: GUIDeom2(执行时出现的,编译时无错,文件名了GUIDemo2.java)
程序如下:
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class GUIDemo2
{
public static void main(String[] args)
{
//图形界面的屏幕显示部分
JFrame frame=new JFrame("例子");
final JTextField Text=new JTextField("学好JAVA用处大!!!");
JButton Button1 =new JButton("按扭");
JButton Button2 =new JButton("退出");
frame.getContentPane().setLayout(new FlowLayout( ));
frame.getContentPane().add(Text);
frame.getContentPane().add(Button1);
frame.getContentPane().add(Button2);
frame.pack();
frame.setVisible(true);
Text.setEditable(false);
//图形界面的事件处理部分
Button1.addActionListener(new ActionListener() //内隐类
{
public void actionPerformed(ActionEvent e)
{
Text.setText("这是JTextField和JButton的一个示例");
}
});
Button2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent f) //actionPerformed不可更改
{
System.exit(0);
}
});
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}