/Users/lyon/j4p/src/gui/ClosableJFrame.java
|
1 package gui;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.WindowAdapter;
6 import java.awt.event.WindowEvent;
7
8 public class ClosableJFrame extends JFrame {
9 public ClosableJFrame() {
10 this("");
11 }
12
13 public ClosableJFrame(String title) {
14 super(title);
15 setBackground(Color.white);
16 addWindowListener(
17 new ClosingWindowAdapter());
18 }
19
20 public void addMouseController(gui.mouse.MouseController mc) {
21 addMouseMotionListener(mc);
22 addMouseListener(mc);
23 }
24
25 public static void main(String args[]) {
26 ClosableJFrame cf = new ClosableJFrame("ClosableJFrame");
27 cf.setSize(200, 200);
28 cf.setVisible(true);
29
30 }
31
32
33 private class ClosingWindowAdapter extends WindowAdapter {
34 public void windowClosing(WindowEvent e) {
35 setVisible(false);
36 dispose();
37 }
38 }
39 }