Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/loihl/sqltool/AdHocQuery.java


1   package com.loihl.sqltool;
2   
3   import java.awt.event.ActionListener;
4   import java.awt.event.ActionEvent;
5   import java.awt.event.WindowAdapter;
6   import java.awt.event.WindowEvent;
7   import javax.swing.JFrame;          
8   import javax.swing.JMenuBar;
9   import javax.swing.JMenu;
10  import javax.swing.JMenuItem;
11  
12  /**
13   * Class AdHocQuery
14   * @author Robert J. Loihl
15   * @version 0.5.0
16   */
17  public class AdHocQuery extends WindowAdapter implements ActionListener{
18  //Member Variables
19      //Menu & MenuItem variables
20      private JFrame    mainFrame;
21      private JMenuBar  mainMenuBar;
22      private JMenu     fileMenu;
23      private JMenuItem exitMenuItem;
24      private JMenu     queryMenu;
25      private JMenuItem executeMenuItem;
26      private JMenuItem clearMenuItem;
27      private JMenuItem setConnMenuItem;
28      private JMenu     helpMenu;
29      private JMenuItem aboutMenuItem;
30      
31      /**
32       * @clientCardinality 1
33       * @supplierCardinality 1
34       * @label Manages 
35       */
36      private AdHocQueryPanel  queryPanel;
37      //
38  //Member Methods
39      /** 
40       * Method: 
41       * Description: 
42       */
43  //    public void methodName(){
44  //    }
45  
46      /** 
47       * Method: AdHocQuery
48       * Description: constructor for AdHocQuery class
49       */
50      public AdHocQuery(){
51          super();
52          init();
53      }
54      /** 
55       * Method: init
56       * Description: 
57       */
58      public void init(){
59          mainFrame = new JFrame("AdHoc Query Tool");
60          queryPanel = new AdHocQueryPanel();
61          mainMenuBar = new JMenuBar();
62  
63          fileMenu = new JMenu("File");
64          exitMenuItem = fileMenu.add("Exit");
65          
66  
67          queryMenu = new JMenu("Query");
68          executeMenuItem = queryMenu.add("Execute");
69          clearMenuItem = queryMenu.add("Clear");
70          setConnMenuItem = queryMenu.add("Set Connection");
71  
72          helpMenu = new JMenu("Help");
73          aboutMenuItem = helpMenu.add("About");
74          
75          mainMenuBar.add(fileMenu);
76          mainMenuBar.add(queryMenu);
77          mainMenuBar.add(helpMenu);
78          
79          mainFrame.setJMenuBar(mainMenuBar);
80          mainFrame.getContentPane().add(queryPanel);
81          mainFrame.setSize(500,300);
82          mainFrame.setVisible(true);
83          
84          //set up Event Connections
85          exitMenuItem.addActionListener(this);
86          executeMenuItem.addActionListener(this);
87          clearMenuItem.addActionListener(this);
88          setConnMenuItem.addActionListener(this);
89          aboutMenuItem.addActionListener(this);
90          mainFrame.addWindowListener(this);
91      }
92      
93      /** 
94       * Method: actionPerformed
95       * Description: event handler for ActionEvents
96       * @param ae ActionEvent
97       */
98      public void actionPerformed(ActionEvent ae){
99          if (ae.getSource() == exitMenuItem){
100             //hide frame
101             mainFrame.setVisible(false);
102             System.exit(0);
103         }            
104         if (ae.getSource() == executeMenuItem){
105             //execute  the query
106             queryPanel.executeCurrentQueryText();
107             return;
108         }
109         if (ae.getSource() == clearMenuItem){
110             //clear the text from the query text area
111             queryPanel.clearCurrentQueryText();
112             return;
113         }
114         if (ae.getSource() == setConnMenuItem){
115             //estblish the database connection
116             queryPanel.setCurrentQueryConnection();
117             return;
118         }
119         if (ae.getSource() == aboutMenuItem){
120             //open an about dialog
121             return;
122         }
123     }
124 
125     /** 
126      * Method: windowClosing
127      * Description: Window event handler for main window
128      * @param we WindowEvent
129      */
130     public void windowClosing(WindowEvent we){
131         //hide frame
132         mainFrame.setVisible(false);
133         System.exit(0);
134     }
135 
136     /** 
137      * Method: getMainFrame
138      * Description: returns the main JFrame object
139      */
140     public  JFrame getMainFrame(){
141         return mainFrame;
142     }
143 
144     /** 
145      * Method: main
146      * Description: instantiate the AdHocQuery class 
147      * @param args[] Array of String of command line parameters
148      */
149     public static void main(String [] args){
150         //create instance of AdHocQuery
151         AdHocQuery ahq = new AdHocQuery();
152     }
153 }