请教窗口事件中的void windowIconified(windowEvent e)方法是干什么用的?

ashui11 2003-10-15 08:45:48
谢谢
...全文
407 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
imagex 2003-10-15
  • 打赏
  • 举报
回复
windowActivated(WindowEvent e) 窗口得到焦点时触发
windowClosed(WindowEvent e) 窗口关闭之后触发
windowClosing(WindowEvent e) 窗口关闭时触发
windowDeactivated(WindowEvent e) 窗口失去焦点时触发
windowOpened(WindowEvent e) 窗口打开之后触发
windowDeiconified(WindowEvent e) 楼上
windowIconified(WindowEvent e) 楼上

quanch 2003-10-15
  • 打赏
  • 举报
回复
窗口最小化时触发的事件。
LoveRose 2003-10-15
  • 打赏
  • 举报
回复
Invoked when a window is changed from a normal to a minimized state. For many platforms, a minimized window is displayed as the icon specified in the window's iconImage property.
6.2.4 事件适配器 适配器类实现一个对应的所有接口,只是方法为空。 public abstract class WindowAdapter implements WindowListener { public void windowOpened(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowClosing(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} } 表6.1 Listener接口与对应的适配器(Adapter)类 接口名称 适配器名称 ComponentListener ComponentAdapter ContainerListener ContainerAdapter FocusListener FocusAdapter KeyListener KeyAdapter MouseListener MouseAdapter MouseMotionListener MouseMotionAdapter WindowListener WindowAdapter (7)鼠标运动事件 鼠标运动事件发生在鼠标移过某个组件时。 任何组件都可以产生这些事件,通过接口 MouseMotionListener 实现。 该接口有两个方法: mouseDragged(MouseEvent) mouseMove(MouseEvent) MouseMotionListener 没有自己的事件类型,替代它的是 MouseEvent 。 被用在 MouseEvent 对象上的方法它都可以使用: getClickCount( ) 返回鼠标被单击次数(整数) getPoint( ) 返回鼠标被单击位置的 x ,y 坐标 getX( ) 返回 x 位置 getY( ) 返回 y 位置 (8)窗口事件WindowEvent窗口事件发生在用户打开或关闭一个诸如 Frame 或 Window窗口时。任何组件都可以产生这些事件,为了支持它们,类必须实现接口:WindowListener。 接口 WindowListener 有七个方法windowActivated(WindowEvent) 窗口被激活 windowClosed (WindowEvent) 窗口已关闭 windowClosing (WindowEvent) 窗口正在关闭 windowDeactivated (WindowEvent) 窗口失效 windowDeiconified (WindowEvent) 窗口正常化时 windowIconified (WindowEvent) 窗口最小化时 windowOpened (WindowEvent) 窗口被打开 (5)键盘事件(KeyEvent) 发生在键盘上的某个键被按下时。 类为了能够处理这些事件必须实现接口 KeyListener 。 每个产生一个键盘事件的组件上要调用方法 addKeyListener( ) 在接口 KeyListener 有三个方法: public void keyPressed(KeyEvent evt) { //…… } public void keyReleased(KeyEvent evt) { //…… } public void keyTyped(KeyEvent evt) { //…… } 在 KeyEvent 对象上可以使用的方法: getKeyChar( ) 返回与事件相关的键盘字符的 Unicode 码 . . . . . . . . . . . . . .
开发工具:MyEclipse     将下面的图片添加到MyEclipse的src文件夹下,第一幅图片名1.gif,第二幅图片名4.gif =================================================================================== import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FirstFrame extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; JDialog jd; JButton jb; ImageIcon a; //插入图片 JLabel jl,jl1,jl2; SecondFrame jf2; public FirstFrame(){ Container wc=this.getContentPane(); wc.setLayout(null); a=new ImageIcon("src/1.gif"); //插入图片 jb=new JButton(a); jb.setBounds(45,45,410,160); jb.addActionListener(this); wc.add(jb); jl=new JLabel("点击上面的动感水果人,进入少林水果六人阵!"); jl.setBounds(120,230,280,20); jl.setForeground(Color.BLUE); wc.add(jl); jl1=new JLabel("这是一个具有挑战的窗口游戏,相信你会玩得很开心!"); jl1.setBounds(100,300, 320, 20); jl1.setForeground(Color.RED); wc.add(jl1); jl2=new JLabel("让我们开始挑战吧!"); jl2.setBounds(200,320,130, 20); jl2.setForeground(Color.RED); wc.add(jl2); this.setTitle("蛋疼游戏 1.0版"); this.setUndecorated(true); this.setSize(500, 400); this.setLocationRelativeTo(null); //让窗口 this.setVisible(true); this.setDefaultCloseOperation(EXIT_ON_CLOSE); } @Override public void actionPerformed(ActionEvent e){ jf2=new SecondFrame(); jf2.windows2(); jf2.Realize(); this.setVisible(false); } } //第一个窗体 =================================================================================== import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SecondFrame extends JFrame implements ActionListener,WindowListener { JLabel jl; JButton jb; ThirdFrame jf3; private static final long serialVersionUID = 2L; public void windows2(){ this.setUndecorated(true); // 去掉窗口的装饰 this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); // 设置这个只有关闭按钮,禁止最大化按钮,同时还能实现最大化。 this.setTitle("第一关"); this.setSize(500, 400); this.setVisible(true); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.addWindowListener(this); } public void Realize(){ Container wc=this.getContentPane(); wc.setLayout(null); jl=new JLabel("这是第一关想办法找到第二关的入口"); jl.setBounds(130, 90, 500, 50); jl.setForeground(Color.BLUE); wc.add(jl); jb=new JButton("第二关入口"); jb.setBounds(300, 500, 100, 30); jb.setForeground(Color.BLUE); jb.addActionListener(this); wc.add(jb); } public void actionPerformed(ActionEvent e) { jf3=new ThirdFrame(); jf3.windows3(); jf3.Realize(); this.setVisible(false); } @Override public void windowActivated(WindowEvent e) {} @Override public void windowClosed(WindowEvent e) {} @Override public void windowClosing(WindowEvent e) { JOptionPane.showMessageDialog(null, " 修行不够!!闯关失败!!!", "失败!!!", 2); } @Override public void windowDeactivated(WindowEvent e) {} @Override public void windowDeiconified(WindowEvent e) {} @Override public void windowIconified(WindowEvent e) {} @Override public void windowOpened(WindowEvent e) {} } //第二个窗体 ............................
import java.awt.*; import java.awt.event.*; import java.applet.*; import java.net.*; import java.io.*; public class SR_Slider extends Frame implements ActionListener, WindowListener, Runnable { public static void main(String Pagli[]) { new SR_Slider(); } Thread time; //new thread File fl; URL dir; MediaTracker mt; //here you can use an array Image p1, p2, p3, p4, p5, p6, p7; About ab; //instance of About class Panel bottom; AudioClip b_n, rfs; Toolkit tk; Dimension dim; Button back, next, refresh, auto, abt, ext; Color sky; Font f; int count, x; public SR_Slider() { setTitle("SR-Slider 1.0"); setLayout(new BorderLayout()); bottom = new Panel(); time = new Thread(this); sky = new Color(0,140,255); //color - skyblue f = new Font("Courier",Font.BOLD,16); count = 0; x = 0; mt=new MediaTracker(this); try { //getting all images and add them to the MediaTracker p1 = Toolkit.getDefaultToolkit().getImage("Image/p1.jpg"); mt.addImage(p1, 0); p2 = Toolkit.getDefaultToolkit().getImage("Image/p2.jpg"); mt.addImage(p2, 1); p3 = Toolkit.getDefaultToolkit().getImage("Image/p3.jpg"); mt.addImage(p3, 2); p4 = Toolkit.getDefaultToolkit().getImage("Image/p4.jpg"); mt.addImage(p4, 3); p5 = Toolkit.getDefaultToolkit().getImage("Image/p5.jpg"); mt.addImage(p5, 4); p6 = Toolkit.getDefaultToolkit().getImage("Image/p6.jpg"); mt.addImage(p6, 5); p7 = Toolkit.getDefaultToolkit().getImage("Image/p7.jpg"); mt.addImage(p7, 6); fl = new File("user.dir"); dir = fl.toURL(); b_n = Applet.newAudioClip(new URL(dir, "Sound/bk_nxt.au")); rfs = Applet.newAudioClip(new URL(dir, "Sound/rfsh.au")); } catch(MalformedURLException e) { //do nothing! } //designing back button back=new Button("Back"); back.setFont(f); back.setBackground(sky); back.setForeground(Color.white); //designing next button next=new Button("Next"); next.setFont(f); next.setBackground(sky); next.setForeground(Color.white); //designing refresh button refresh=new Button("Reset"); refresh.setFont(f); refresh.setBackground(sky); refresh.setForeground(Color.white); //designing auto button auto=new Button("SlideShow"); auto.setFont(f); auto.setBackground(sky); auto.setForeground(Color.white); //designing abt button abt=new Button("About"); abt.setFont(f); abt.setBackground(sky); abt.setForeground(Color.white); //designing ext button ext=new Button("Exit"); ext.setFont(f); ext.setBackground(sky); ext.setForeground(Color.white); //adding ActionListener to all buttons back.addActionListener(this); next.addActionListener(this); refresh.addActionListener(this); auto.addActionListener(this); abt.addActionListener(this); ext.addActionListener(this); //adding all components to the Frame bottom.add(back); bottom.add(next); bottom.add(refresh); bottom.add(auto); bottom.add(abt); bottom.add(ext); add(bottom, BorderLayout.SOUTH); addWindowListener(this); tk = this.getToolkit(); dim = tk.getScreenSize(); //getting the current screen resolution setBounds(dim.width/6, dim.height/6, 540, 420); setResizable(false); setVisible(true); } public void paint(Graphics g) { if(count < 1) g.drawImage(p1, 0, 0, this); if(count == 1) g.drawImage(p2, 0, 0, this); if(count == 2) g.drawImage(p3, 0, 0, this); if(count == 3) g.drawImage(p4, 0, 0, this); if(count == 4) g.drawImage(p5, 0, 0, this); if(count == 5) g.drawImage(p6, 0, 0, this); if(count == 6) g.drawImage(p7, 0, 0, this); } public void update(Graphics g) { paint(g); } public void actionPerformed(ActionEvent ae) { if(ae.getSource() == ext) { dispose(); setVisible(false); System.exit(0); } if(ae.getSource() == next) { b_n.play(); if(count < 7) { count++; repaint(); } } if(ae.getSource() == back) { b_n.play(); if(count == 0) count=0; if(count > 0) { count--; repaint(); } } if(ae.getSource() == refresh) { rfs.play(); time.suspend(); //suspends the thread count=0; repaint(); } if(ae.getSource() == auto) { b_n.play(); if(x < 1) { time.start(); x++; } else { time.resume(); //resumes the thread } } if(ae.getSource() == abt) { ab = new About(); } } public void run() { try { for(int i=1;i>0;i++) { b_n.play(); time.sleep(3000); count++; if(count > 6) { time.suspend(); //suspends the thread count = 0; } repaint(); } } catch(InterruptedException e) { //do nothing! } } //handling window events public void windowClosing(WindowEvent we) { dispose(); setVisible(false); System.exit(0); } public void windowClosed(WindowEvent we) { //do nothing! } public void windowOpened(WindowEvent we) { //do nothing! } public void windowActivated(WindowEvent we) { //do nothing! } public void windowDeactivated(WindowEvent we) { //do nothing! } public void windowIconified(WindowEvent we) { //do nothing! } public void windowDeiconified(WindowEvent we) { //do nothing! } class About extends Frame implements WindowListener { Font f, f2; private About() { setTitle("About"); setLayout(new FlowLayout()); f = new Font("Verdana", Font.BOLD, 20); f2 = new Font("Verdana", Font.PLAIN, 12); addWindowListener(this); tk = this.getToolkit(); dim = tk.getScreenSize(); //getting the current screen resolution setBounds(dim.width/4, dim.height/4, 300, 190); setResizable(false); setVisible(true); } public void paint(Graphics g) { g.setColor(Color.red); g.setFont(f); g.drawString("SR-Slider 1.0", 10, 60); g.setColor(Color.black); g.setFont(f2); g.drawString("Author: 雪碧的朋友", 10, 90); g.drawString("email:jing_feng70@163.com", 10, 110); g.drawString("谢谢使用", 10, 130); g.drawString("(C) ShuvoRim Pvt. Ltd.", 10, 150); g.drawString("All rights reserved.", 10, 170); } //handling window events public void windowClosing(WindowEvent we) { dispose(); setVisible(false); } public void windowClosed(WindowEvent we) { //do nothing! } public void windowOpened(WindowEvent we) { //do nothing! } public void windowActivated(WindowEvent we) { //do nothing! } public void windowDeactivated(WindowEvent we) { //do nothing! } public void windowIconified(WindowEvent we) { //do nothing! } public void windowDeiconified(WindowEvent we) { //do nothing! } } }

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧