1. package javanige;
  2.  
  3. import java.awt.Insets;
  4. import java.awt.event.WindowEvent;
  5. import java.awt.event.WindowListener;
  6.  
  7. import javax.swing.JFrame;
  8.  
  9. public class Window extends JFrame implements WindowListener{
  10.  
  11. public Window( String title, int wight, int height ){
  12. super("タイトル");
  13.  
  14. //ウィンドウの描画
  15. this.setVisible( true );
  16.  
  17. //ウィンドウの右上の×ボタンをクリックすると終了する
  18. this.setDefaultCloseOperation( EXIT_ON_CLOSE );
  19.  
  20. //ウィンドウの大きさ変更禁止
  21. this.setResizable( false );
  22.  
  23. //ウィンドウの配置位置を中央へ(null);
  24. this.setLocationRelativeTo( null );
  25.  
  26. //ウィンドウの大きさ変更禁止
  27. this.setResizable( false );
  28.  
  29. //ウィンドウの外淵の大きさ取得
  30. Insets in = this.getInsets();
  31.  
  32. //ウィンドウサイズの設定
  33. int w = wight + in.right + in.left;
  34. int h = height + in.top + in.bottom;
  35. this.setSize( w, h );
  36.  
  37. this.addWindowListener( this );
  38.  
  39. }
  40.  
  41.   //アクティブになったとき
  42. public void windowActivated(WindowEvent e) {
  43. System.out.println("Activated");
  44. }
  45. //ウィンドウが終了した時
  46. public void windowClosed(WindowEvent e) {
  47. System.out.println("Closed");
  48. }
  49. //アクティブじゃなくなった時
  50. public void windowDeactivated(WindowEvent e) {
  51. System.out.println("Deactivated");
  52. }
  53. //アイコン化から復帰した時
  54. public void windowDeiconified(WindowEvent e) {
  55. System.out.println("Deiconified");
  56. }
  57. //アイコン化された時
  58. public void windowIconified(WindowEvent e) {
  59. System.out.println("Iconified");
  60. }
  61. //ウィンドウが起動した時
  62. public void windowOpened(WindowEvent e) {
  63. System.out.println("Opened");
  64. }
  65. //ウィンドウが終了した時
  66. public void windowClosing(WindowEvent windowevent) {
  67. System.out.println("Closing");
  68. }
  69. }

タグ:

+ タグ編集
  • タグ:
最終更新:2012年01月08日 04:50