求java6通过窗口监听器实现关闭窗口操作的代码
初学,在看java教学视频,视频里用的java1.4,我安装的是java6.里面有一段代码他能运行出来,我就出一推错。这是为什么?importjava.awt.*;imp...
初学,在看java教学视频,视频里用的java1.4, 我安装的是java6. 里面有一段代码他能运行出来,我就出一推错。这是为什么?
import java.awt.*;
import java.awt.event.*;
public class MyFrame {
public static void main(String[] args)
{
Frame f = new Frame("教务管理系统");
f.setSize(600, 400);
f.setLocation(200,200);
f.setBackground(Color.CYAN);
f.addWindowListener(MyWindowListener());
f.setVisible(true);
}
public MyWindowListener implements WindowListener{
public void windowActivated(WindowEvent e)
{ }
void windowClosed(WindowEvent e)
{ }
void windowClosing(WindowEvent e)
{ System.exit(0); }
void windowDeactivated(WindowEvent e)
{ }
void windowDeiconified(WindowEvent e)
{ }
void windowIconified(WindowEvent e)
{ }
void windowOpened(WindowEvent e)
{ }
} 展开
import java.awt.*;
import java.awt.event.*;
public class MyFrame {
public static void main(String[] args)
{
Frame f = new Frame("教务管理系统");
f.setSize(600, 400);
f.setLocation(200,200);
f.setBackground(Color.CYAN);
f.addWindowListener(MyWindowListener());
f.setVisible(true);
}
public MyWindowListener implements WindowListener{
public void windowActivated(WindowEvent e)
{ }
void windowClosed(WindowEvent e)
{ }
void windowClosing(WindowEvent e)
{ System.exit(0); }
void windowDeactivated(WindowEvent e)
{ }
void windowDeiconified(WindowEvent e)
{ }
void windowIconified(WindowEvent e)
{ }
void windowOpened(WindowEvent e)
{ }
} 展开
展开全部
改了一下,你自己看吧
public class MyFrame {
public static void main(String[] args) {
Frame f = new Frame("教务管理系统");
f.setSize(600, 400);
f.setLocation(200, 200);
f.setBackground(Color.CYAN);
f.addWindowListener(new MyWindowListener());
f.setVisible(true);
}
}
class MyWindowListener
implements WindowListener {
public void windowActivated(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
}
public class MyFrame {
public static void main(String[] args) {
Frame f = new Frame("教务管理系统");
f.setSize(600, 400);
f.setLocation(200, 200);
f.setBackground(Color.CYAN);
f.addWindowListener(new MyWindowListener());
f.setVisible(true);
}
}
class MyWindowListener
implements WindowListener {
public void windowActivated(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.awt.*;
import java.awt.event.*;
public class MyFrame {
public static void main(String[] args)
{
Frame f = new Frame("教务管理系统");
f.setSize(600, 400);
f.setLocation(200,200);
f.setBackground(Color.CYAN);
f.addWindowListener(new MyWindowListener()); //这里要有一个new 关键字
f.setVisible(true);
}
}
class MyWindowListener implements WindowListener{ //鉴于这是一个自己定义的类,所以前面要有class关键字
public void windowActivated(WindowEvent e)
{ }
public void windowClosed(WindowEvent e) //这下面的几个方法要都加上public修饰符
{ }
public void windowClosing(WindowEvent e)
{ System.exit(0); }
public void windowDeactivated(WindowEvent e)
{ }
public void windowDeiconified(WindowEvent e)
{ }
public void windowIconified(WindowEvent e)
{ }
public void windowOpened(WindowEvent e)
{ }
}
import java.awt.event.*;
public class MyFrame {
public static void main(String[] args)
{
Frame f = new Frame("教务管理系统");
f.setSize(600, 400);
f.setLocation(200,200);
f.setBackground(Color.CYAN);
f.addWindowListener(new MyWindowListener()); //这里要有一个new 关键字
f.setVisible(true);
}
}
class MyWindowListener implements WindowListener{ //鉴于这是一个自己定义的类,所以前面要有class关键字
public void windowActivated(WindowEvent e)
{ }
public void windowClosed(WindowEvent e) //这下面的几个方法要都加上public修饰符
{ }
public void windowClosing(WindowEvent e)
{ System.exit(0); }
public void windowDeactivated(WindowEvent e)
{ }
public void windowDeiconified(WindowEvent e)
{ }
public void windowIconified(WindowEvent e)
{ }
public void windowOpened(WindowEvent e)
{ }
}
追问
谢谢 顺便问一下eclipse如何自动生成Windowlistener这段代码?视频教程上用的JBuilder,是用快捷键生成的,eclipse应该也可以把?
追答
可以的,你这样写: class MyWindowListener implements window 然后按下alt + /
就会出来提示,你选择WindowListener,选择完毕后接口中的抽象方法就会自动生成了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询