KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > piratepete > dbpirate > ui > MainWindow


1 package com.piratepete.dbpirate.ui;
2
3 import java.awt.Dimension JavaDoc;
4 import java.awt.Toolkit JavaDoc;
5 import java.awt.event.WindowEvent JavaDoc;
6 import java.net.URL JavaDoc;
7
8 import javax.swing.ImageIcon JavaDoc;
9 import javax.swing.JFrame JavaDoc;
10 import javax.swing.JOptionPane JavaDoc;
11 import javax.swing.UIManager JavaDoc;
12 import java.awt.*;
13
14 /**
15  * MainWindow Class
16  * Copyright (C) 2003 David L. Whitehurst, Jeremy Whitlock<p>
17  *
18  * This program is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU General Public License
20  * as published by the Free Software Foundation; either version 2
21  * of the License, or (at your option) any later version.<p>
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.<p>
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<p>
31  *
32  * <a HREF="http://www.piratepetesoftware.com">piratepetesoftware.com</a><br>
33  * <a HREF="mailto:dlwhitehurst@comcast.net">dlwhitehurst@comcast.net</a>
34  *
35  * @version 1.1.0
36  */

37 public class MainWindow extends JFrame JavaDoc {
38
39     private URL JavaDoc iPath;
40     
41     
42     /** Creates a new instance of MainWindow */
43     public MainWindow(String JavaDoc title)
44     {
45         buildFrame(title);
46     }
47     
48     public void buildFrame(String JavaDoc title)
49     {
50
51         this.setTitle(title);
52         iPath = this.getClass().getResource("/com/piratepete/dbpirate/ui/images/small_pirate.gif");
53         
54         Toolkit JavaDoc theKit = this.getToolkit(); //Used to get Screen Size
55
Dimension JavaDoc wndSize = theKit.getScreenSize(); //Gets screen size
56
ImageIcon JavaDoc icon = new ImageIcon JavaDoc(iPath); //Get's Icon
57

58         this.setBounds(wndSize.width/8, wndSize.height/8, (wndSize.width/8)*6,
59                 (wndSize.height/8)*6); //Sets the default size of the Main Frame
60
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); //Assigns Closing Instructions
61
this.setIconImage(icon.getImage()); //Applies image to JFrame
62

63         
64     }
65     
66     public void setPLAF()
67     {
68         // Set Look-feel
69
try {
70             UIManager.setLookAndFeel(new com.incors.plaf.kunststoff.KunststoffLookAndFeel());
71             //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
72
UIManager.put("Desktop.background", new Color(174,174,222));
73             UIManager.put("Table.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",0,11));
74             UIManager.put("List.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",0,11));
75             UIManager.put("FileChooserUI", "com.sun.java.swing.plaf.windows.WindowsFileChooserUI");
76             UIManager.put("TextArea.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",0,11));
77             UIManager.put("TextField.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",0,11));
78             UIManager.put("TabbedPane.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",1,11));
79             UIManager.put("TitledBorder.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",1,11));
80             UIManager.put("Menu.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",0,11));
81             UIManager.put("MenuItem.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",0,11));
82             UIManager.put("MenuBar.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",0,11));
83             UIManager.put("TableHeader.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",1,10));
84             UIManager.put("Button.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",1,11));
85             UIManager.put("Label.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",1,11));
86             UIManager.put("PopupMenu.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",0,11));
87             UIManager.put("Panel.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",1,11));
88             UIManager.put("Viewport.font", new javax.swing.plaf.FontUIResource JavaDoc("Tahoma",1,11));
89             UIManager.put("Table.selectionBackground", new Color(153,153,255));
90             UIManager.put("TabbedPane.focus", new Color(0,0,255));
91             UIManager.put("TabbedPane.shadow", new Color(153,153,255));
92             UIManager.put("TabbedPane.darkshadow", new Color(200,200,200));
93             UIManager.put("TabbedPane.selected", new Color(174,174,222));
94             UIManager.put("TextArea.selectionBackground", new Color(153,153,255));
95             UIManager.put("TextField.selectionBackground", new Color(153,153,255));
96
97             //UIManager.setLookAndFeel("com.stefankrause.xplookandfeel.XPLookAndFeel");
98
}
99         catch (Exception JavaDoc e)
100         {
101             System.out.println(e);
102         }
103     }
104     
105     public void Maximize()
106     {
107         super.setExtendedState(JFrame.MAXIMIZED_BOTH); //Maximizes the Main Frame
108
}
109     
110     protected void processWindowEvent(WindowEvent JavaDoc e)
111     {
112         if (e.getID() == WindowEvent.WINDOW_CLOSING)
113         {
114             int returnVal = JOptionPane.showConfirmDialog(this, "Would you like to exit?", "Exit DBPirate",
115                     JOptionPane.YES_NO_OPTION);
116             
117             if(returnVal == JOptionPane.YES_OPTION)
118             {
119                 System.exit(0);
120             }
121         }
122         else
123         {
124             super.processWindowEvent(e);
125         }
126     }
127
128     
129 }
130
Popular Tags