当前位置: 技术问答>java相关
我的程序为什么不能正常退出?
来源: 互联网 发布时间:2015-04-13
本文导语: 源程序如下: import javax.swing.*; import java.awt.event.*; class FirstFrame extends JFrame { public FirstFrame() { setTitle("I love you"); setSize(600,400); addWindowListener(new WindowAdapter() { public void WindowClosing(WindowEvent e) { Syst...
源程序如下:
import javax.swing.*;
import java.awt.event.*;
class FirstFrame extends JFrame
{
public FirstFrame()
{
setTitle("I love you");
setSize(600,400);
addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
public class FirstTest
{
public static void main(String [] args)
{
JFrame frame=new FirstFrame();
frame.show();
}
}
望指点小弟!
import javax.swing.*;
import java.awt.event.*;
class FirstFrame extends JFrame
{
public FirstFrame()
{
setTitle("I love you");
setSize(600,400);
addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
public class FirstTest
{
public static void main(String [] args)
{
JFrame frame=new FirstFrame();
frame.show();
}
}
望指点小弟!
|
WindowClosing
改成
windowClosing
改成
windowClosing
|
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
|
你的WindowClosing()写错了,第一个w应该小写。记住:所以函数的第一个字母要小写,你自己开发程序时最好也遵循这一规则,因为这是java推荐的编码方法。