是你的判断有问题吧,没判断当前窗体是否是最大化,不知道理解的对不对。
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class MouseDemo extends JFrame {
private static final long serialVersionUID = 1L;
boolean IS_MAXIMIZED = false;
public MouseDemo() {
super("DoubleClick Demo");
this.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
if (IS_MAXIMIZED) {
setExtendedState(JFrame.NORMAL);
IS_MAXIMIZED = false;
} else {
setExtendedState(JFrame.MAXIMIZED_BOTH);
IS_MAXIMIZED = true;
}
}
}
});
this.setSize(new Dimension(200, 150));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]) {
new MouseDemo().setVisible(true);
}
}