1/**
2 * Copyright(C) 1998
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * Adapted by David Nolden, April 19, 2003
11 *
12 * @date : January 1, 1998.
13 * @authorĀ : Salih Yurttas.
14 */
15
16import ui.*;
17import inout.*;
18import sqls.*;
19import javax.swing.*;
20import java.awt.*;
21import java.awt.event.*;
22import java.sql.Connection;
23
24public class RunScriptUI extends Frame
25 implements ActionListener {
26
27 private String[] menuLabel = {"Create",
28 "Delete",
29 "Query"};
30 private int mLabelLength= menuLabel.length;
31 private Connection mycon;
32 private MenuBar mB;
33 private Menu[] m;
34 private DBLogin dbLogin;
35
36 private UIRunScript[] uIRunScript = {new UIRunScript(new SQLScript("Create Tables")),
37 new UIRunScript(new SQLScript("Insert Tuples")),
38 new UIRunScript(new SQLScript("Drop Tables")),
39 new UIRunScript(new SQLScript("Delete Tuples")),
40 new UIRunScript(new SQLScript("Query Database"))};
41
42 public RunScriptUI() {
43 super("RunScriptUI");
44 dbLogin = new DBLogin(this);
45 dbLogin.pack();
46 dbLogin.setLocationRelativeTo(this);
47 dbLogin.setVisible(true);
48 if (dbLogin.fail)
49 System.exit(0);
50 mycon = dbLogin.getCon();
51 try {
52 mB = new MenuBar();
53
54 m = new Menu[mLabelLength];
55
56 for(int i=0; i<mLabelLength; i++) {
57 m[i] = new Menu(menuLabel[i]);
58
59 switch(i) {
60 case 0 : for(int j=0; j<2; j++)
61 uIRunScript[j].addSelfToMenu(m[i]);
62 break;
63 case 1 : for(int j=2; j<4; j++)
64 uIRunScript[j].addSelfToMenu(m[i]);
65 break;
66 case 2 : for(int j=4; j<5; j++)
67 uIRunScript[j].addSelfToMenu(m[i]);
68 break;
69 }
70
71 m[i].addActionListener(this);
72 mB.add(m[i]);
73 }
74
75 setMenuBar(mB);
76
77 addWindowListener(
78 new WindowAdapter() {
79 public void windowClosing(WindowEvent wE) {
80 System.exit(0);
81 }
82 }
83 );
84 }
85 catch(Exception e) {
86 System.out.println(e);
87 }
88 }
89
90 public void actionPerformed(ActionEvent aE) {
91 String arg = aE.getActionCommand();
92 for(int i=0; i<2; i++)
93 if(uIRunScript[i].nameEquals(arg))
94 uIRunScript[i].runScript(this, mycon);
95
96 for(int i=2; i<4; i++)
97 if(uIRunScript[i].nameEquals(arg))
98 uIRunScript[i].runScript(this, mycon);
99
100 for(int i=4; i<5; i++)
101 if(uIRunScript[i].nameEquals(arg))
102 uIRunScript[i].runScript(this, mycon);
103
104 repaint();
105 }
106
107 static public void main(String[] args) {
108 RunScriptUI rSUI = new RunScriptUI();
109 rSUI.setLocationRelativeTo(null);
110 rSUI.setSize(320, 160);
111 rSUI.show();
112 }
113
114}