swing中windowiconified怎么js 触发window事件

WindowEvent 类的对象必须实现这个接口。类处理一个组件必须注册。使用addWindowListener()方法,该对象可以被注册。
以下是声明 java.awt.event.WindowListener接口:
public interface WindowListener
extends EventListener
方法 & 描述
void windowActivated(WindowEvent e)&
Invoked when the Window is set to be the active Window.
void windowClosed(WindowEvent e)&
Invoked when a window has been closed as the result of calling dispose on the window.
void windowClosing(WindowEvent e)&
Invoked when the user attempts to close the window from the window's system menu.
void windowDeactivated(WindowEvent e)&
Invoked when a Window is no longer the active Window.
void windowDeiconified(WindowEvent e)&
Invoked when a window is changed from a minimized to a normal state.
void windowIconified(WindowEvent e)&
Invoked when a window is changed from a normal to a minimized state.
void windowOpened(WindowEvent e)&
Invoked the first time a window is made visible.
这个接口从以下接口继承的方法:
java.awt.EventListener
WindowListener 例子
选择使用任何编辑器创建以下java程序在&D:/ & SWING & com & yiibai & gui &
SwingListenerDemo.java
package com.yiibai.gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingListenerDemo {
private JFrame mainFrame;
private JLabel headerLabel;
private JLabel statusLabel;
private JPanel controlPanel;
public SwingListenerDemo(){
prepareGUI();
public static void main(String[] args){
SwingListenerDemo
swingListenerDemo = new SwingListenerDemo();
swingListenerDemo.showWindowListenerDemo();
private void prepareGUI(){
mainFrame = new JFrame(&Java SWING Examples&);
mainFrame.setSize(400,400);
mainFrame.setLayout(new GridLayout(3, 1));
headerLabel = new JLabel(&&,JLabel.CENTER );
statusLabel = new JLabel(&&,JLabel.CENTER);
statusLabel.setSize(350,100);
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
mainFrame.setVisible(true);
private void showWindowListenerDemo(){
headerLabel.setText(&Listener in action: WindowListener&);
JButton okButton = new JButton(&OK&);
aboutFrame = new JFrame();
aboutFrame.setSize(300,200);;
aboutFrame.setTitle(&WindowListener Demo&);
aboutFrame.addWindowListener(new CustomWindowListener());
JPanel panel = new JPanel();
panel.setBackground(Color.white);
JLabel msglabel
= new JLabel(&Welcome to TutorialsPoint SWING Tutorial.&
,JLabel.CENTER);
panel.add(msglabel);
aboutFrame.add(panel);
aboutFrame.setVisible(true);
class CustomWindowListener implements WindowListener {
public void windowOpened(WindowEvent e) {
public void windowClosing(WindowEvent e) {
aboutFrame.dispose();
public void windowClosed(WindowEvent e) {
public void windowIconified(WindowEvent e) {
public void windowDeiconified(WindowEvent e) {
public void windowActivated(WindowEvent e) {
public void windowDeactivated(WindowEvent e) {
编译程序,使用命令提示符。到&D:/ & SWING&然后输出以下命令。
D:SWING&javac comyiibaiguiSwingListenerDemo.java
如果没有错误出现,这意味着编译成功。使用下面的命令来运行程序。
D:SWING&java com.yiibai.gui.SwingListenerDemo
验证下面的输出
加QQ群啦!
JAVA技术QQ群:
MySQL/SQL语句QQ群:
Python QQ群:
大数据开发技术:
易百教程移动端:请扫描本页面底部(右侧)二维码关注微信公众号,或直接手机访问:
上一篇:下一篇:Swing中如何让窗体全屏,总在最前面……
Swing中如何让窗体全屏,总在最前面,没有边框和控制栏,并且不能切换出去,也不能最小化或者移动……
什么时候需要这样BT的窗体呢?就是在做内测软件的时候,发现不得不如此,写一个类,继承自JFrame,然后在构造函数中写如下的代码:
this.setExtendedState(JFrame.MAXIMIZED_BOTH);&//最大化
this.setAlwaysOnTop(true);&&&&//总在最前面
this.setResizable(false);&&&&//不能改变大小
this.setUndecorated(true);&&&&//不要边框
接下来是事件部分,需要关心的事件是windowLostFocus和windowIconified(最小化)
&&& public
void this_windowLostFocus(WindowEvent e) {
this.requestFocus();
this.setLocation(0,0);
&&& public
void this_windowIconified(WindowEvent e) {
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
ok,一个超级无敌的关不掉,移不走,挡不住的窗体就制作完毕了
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。我是java新手。java中点击关闭窗口,然后怎样才能出现提示对话框呢?点击确定才真正退出的那种。麻烦啦-如何在java程序中,当点击一个按钮后,关闭当前窗口,... _星空游戏网
我是java新手。java中点击关闭窗口,然后怎样才能出现提示对话框呢?点击确定才真正退出的那种。麻烦啦
我是java新手。java中点击关闭窗口,然后怎样才能出现提示对话框呢?点击确定才真正退出的那种。麻烦啦
ava中关闭窗口用private class WindowCloser extends WindowAdapter {public void windowClosing(WindowEvent e)
{dispose(),点击取消就不会退出程序; }可是我想点击关闭窗口时会出现“是否确定退出”的对话框,点击确定才退出的那种。请问要怎样弄才能搞定呢/实现接口 class windowListener implements WindowListener{@Override
public void windowClosed(WindowEvent e) {
/// TODO Auto-generated method stub
public void windowOpened(WindowEvent e) {
/&#47,设置关闭模式为DO_NOTHING_ON_CLOSE(就是默认关闭效用减半;/ TODO Auto-generated method stub
public void windowIconified(WindowEvent e) {
&#47.getContentPane().add(exitBtn);import javax.swing.JOptionPpublic class MainFrame extends JFrame {
/&#47,仅触发WindowListener中的windowClosing方法)2 弹对话框;你确定要退出本窗口不?&;/ TODO Auto-generated method stub
public void windowDeiconified(WindowEvent e) {
&#47.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE).实现接口 class exitBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
&#47.4; TODO Auto-generated method stub
public void windowClosing(WindowEvent e) {
//退出按钮 JButton exitB /&#47.awt.pack();
mainFrame.setVisible(true);确认关闭 private void sureExit(){
int result=JOptionPane,确认关闭后;, JOptionP真正执行关闭的语句
thisFrame.dispose(); }
&#47, &Information&quot.JButton,添加JFrame的dispose()代码:import java.awt.event.ActionEimport java.awt.event.ActionListener关键;在关闭时调用“确认关闭”方法
sureExit();
public static void main(String[] args) {
MainFrame mainFrame=new MainFrame().showConfirmDialog(this, &quot, 30;import java.
mainF关键!......
/实现接口 class windowListener implements WindowListener{@Override
public void windowClosed(WindowEvent e) {
/// TODO Auto-generated method stub
public void windowOpened(WindowEvent e) {
/&#47,设置关闭模式为DO_NOTHING_ON_CLOSE(就是默认关闭效用减半;/ TODO Auto-generated method stub
public void windowIconified(WindowEvent e) {
&#47.getContentPane().add(exitBtn);import javax.swing.JOptionPpublic class MainFrame extends JFrame {
/&#47,仅触发WindowListener中的windowClosing方法)2 弹对话框;你确定要退出本窗口不?&;/ TODO Auto-generated method stub
public void windowDeiconified(WindowEvent e) {
&#47.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE).实现接口 class exitBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
&#47.4; TODO Auto-generated method stub
public void windowClosing(WindowEvent e) {
//退出按钮 JButton exitB /&#47.awt.pack();
mainFrame.setVisible(true);确认关闭 private void sureExit(){
int result=JOptionPane,确认关闭后;, JOptionP真正执行关闭的语句
thisFrame.dispose(); }
&#47, &Information&quot.JButton,添加JFrame的dispose()代码:import java.awt.event.ActionEimport java.awt.event.ActionListener关键;在关闭时调用“确认关闭”方法
sureExit();
public static void main(String[] args) {
MainFrame mainFrame=new MainFrame().showConfirmDialog(this, &quot, 30;import java.
mainF关键!......1.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);2推荐2楼的。注意两点
JOptionPane pane = new JOptionPane();
if(pane.showConfirmDialog(null, &是否确定退出??&) == JOptionPane.OK_OPTION)
System.out.println(&dd&);
JAVA单击事件如何关闭当前窗口……
只能用dispose释放当前窗口、比如this.dispose(); 不能用System.exit(...java中点击按钮获取路径字段显示到TextField中 求完整代码 初学者……
1、给按钮注册事件 actionlistener 2、事件触发会调用到actionlistener接...新手学java,问java中class和package的关系……
2中的class可以使用1中的类(当然要具有权限访问),每个class中都可以有一个main方法(函...java 新手 为什么 java类中 要有 static静态方法???……
/** *静态与对象无关 , 先于对象而存在 *类方法: 静态方法 不用创建对象就可以调用的方法 ,...新手,关于java异常的一个小问题……
当然不能写在try、catch、finally任意一个块里,首先,try,catch这两个块不说了,...java中点击一个窗口中的按钮弹出另外一个窗口,关闭弹出窗口时两个窗口都关闭了,怎样做只关闭弹出窗口...……
我猜你可能是在第二个窗口也这样设置了, this.setDefaultCloseOperation(...关于java,如何实现点击按钮切换画布图片,求大神……
一个图片时你知道,现在只是切换的问题? 给按钮添加一个 ActionListener,在它的 act...java如何计算鼠标点击次数。新手求问……
n 要定义成类变量,不能是方法内的变量 。。。。。。。。然后n就可以累加了。别忘了int的最大值,虽...java事件处理button如何单击按钮退出……
监听按钮,当按钮被点击时,就退出。代码如下:jb_button.addMouseListener(n...新手入门学习java语言……
新手入门学习java语言,可以从以下方面学习:  1、掌握静态方法和属性   静态方法和属性用于描述...

我要回帖

更多关于 js 触发window事件 的文章

 

随机推荐