日期:2014-05-20  浏览次数:20739 次

请问java中怎么监听用鼠标点击最大化窗口事件啊?还有用鼠标拖动改变窗口大小事件?
补充:就是用鼠标放到窗口的右下角,当鼠标指针变成双箭头的时候。

------解决方案--------------------
监听窗口状态变化(包括最大化)实现WindowStateListener
改变组件大小用继承ComponentAdapter
示例:
import javax.swing.*;
import java.awt.event.*;

public class TestFrame {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
frame.addComponentListener(new TestComponentAdapter());
frame.addWindowStateListener(new TestWindowStatedListener());
frame.setVisible(true);
}
}

class TestComponentAdapter extends ComponentAdapter {
public void componentResized(ComponentEvent event) {
System.out.println(event.getSource());
}
}

class TestWindowStatedListener implements WindowStateListener {
public void windowStateChanged(WindowEvent event) {
System.out.println(event.getSource());
}
}