用JAVA设计一个窗口 5
当窗口激活时输出"当前窗口被激活"当窗口最小化时输出"当前窗口被最小化"当窗口关闭时则显示"窗口关闭"我用windowlistener时主程序如下importjava.a...
当窗口激活时 输出"当前窗口被激活" 当窗口最小化时输出"当前窗口被最小化" 当窗口关闭时 则显示"窗口关闭"
我用windowlistener 时 主程序如下
import java.awt.event.*;
public class MonEcouteur implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.out.println("C'est fini...");
System.exit(0);
}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}
import javax.swing.*;
public class MaFenetre extends JFrame
{
public MaFenetre()
{
setBounds(10, 20, 400, 300);
setTitle("Fenetre principale");
MonEcouteur ecouteur = new MonEcouteur();
addWindowListener(ecouteur);
}
}
public class Exercice2
{
public static void main(String[] args)
{
MaFenetre fenetre = new MaFenetre();
fenetre.setVisible(true);
}
}
要怎么修改呢 谢谢高手赐教 展开
我用windowlistener 时 主程序如下
import java.awt.event.*;
public class MonEcouteur implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.out.println("C'est fini...");
System.exit(0);
}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}
import javax.swing.*;
public class MaFenetre extends JFrame
{
public MaFenetre()
{
setBounds(10, 20, 400, 300);
setTitle("Fenetre principale");
MonEcouteur ecouteur = new MonEcouteur();
addWindowListener(ecouteur);
}
}
public class Exercice2
{
public static void main(String[] args)
{
MaFenetre fenetre = new MaFenetre();
fenetre.setVisible(true);
}
}
要怎么修改呢 谢谢高手赐教 展开
1个回答
展开全部
//看看这个程序
//我猜不能判断窗口的最小化,只能判断它是否失去焦点
import java.awt.event.*;
import javax.swing.*;
//定义WindowTest类,继承自JFrame,实现了WindowListener接口
public class WindowTest extends JFrame implements WindowListener
{
//构造方法
public WindowTest()
{
//设置窗体的标题
this.setTitle("窗体事件响应");
//向窗体中添加一个标签作为提示
this.add(new JLabel("当您对窗体进行激活、转为非激活、关闭等动作时,控制台将打印相应的动作描述"));
//注册WindowListener监听器
this.addWindowListener(this);
//设置窗体的位置、大小、可见性及关闭
this.setBounds(200,200,480,150);
this.setVisible(true);
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//与第25行功能相同
}
//实现WindowListener接口中的各个方法,不需要的方法也要给出空实现
public void windowActivated(WindowEvent e)
{
System.out.println("1.窗体被激活");
}
public void windowOpened(WindowEvent e){
System.out.println("2.窗口首次变为可见");
}
public void windowDeactivated(WindowEvent e)
{
System.out.println("3.窗体由激活状态变成非激活状态");
}
public void windowClosing(WindowEvent e)
{
System.out.println("4.窗体关闭,Game over");
System.exit(0);//与第19行功能相同
}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public static void main(String[] args)
{
//创建窗体对象
new WindowTest();
}
}
//我猜不能判断窗口的最小化,只能判断它是否失去焦点
import java.awt.event.*;
import javax.swing.*;
//定义WindowTest类,继承自JFrame,实现了WindowListener接口
public class WindowTest extends JFrame implements WindowListener
{
//构造方法
public WindowTest()
{
//设置窗体的标题
this.setTitle("窗体事件响应");
//向窗体中添加一个标签作为提示
this.add(new JLabel("当您对窗体进行激活、转为非激活、关闭等动作时,控制台将打印相应的动作描述"));
//注册WindowListener监听器
this.addWindowListener(this);
//设置窗体的位置、大小、可见性及关闭
this.setBounds(200,200,480,150);
this.setVisible(true);
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//与第25行功能相同
}
//实现WindowListener接口中的各个方法,不需要的方法也要给出空实现
public void windowActivated(WindowEvent e)
{
System.out.println("1.窗体被激活");
}
public void windowOpened(WindowEvent e){
System.out.println("2.窗口首次变为可见");
}
public void windowDeactivated(WindowEvent e)
{
System.out.println("3.窗体由激活状态变成非激活状态");
}
public void windowClosing(WindowEvent e)
{
System.out.println("4.窗体关闭,Game over");
System.exit(0);//与第19行功能相同
}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public static void main(String[] args)
{
//创建窗体对象
new WindowTest();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询