/** * Attach a DataSet to the graph. By attaching the data set the class can draw the data through * its paint method. */ public void attachDataSet(DataSet d) { if (d != null) { dataset.addElement(d); d.g2d = this; } }
/** * register keystrokes here which are for the WHEN_IN_FOCUSED_WINDOW case. Other types of * keystrokes will be handled by walking the hierarchy That simplifies some potentially hairy * stuff. */ public void registerKeyStroke(KeyStroke k, JComponent c) { Container topContainer = getTopAncestor(c); if (topContainer == null) { return; } Hashtable keyMap = containerMap.get(topContainer); if (keyMap == null) { // lazy evaluate one keyMap = registerNewTopContainer(topContainer); } Object tmp = keyMap.get(k); if (tmp == null) { keyMap.put(k, c); } else if (tmp instanceof Vector) { // if there's a Vector there then add to it. Vector v = (Vector) tmp; if (!v.contains(c)) { // only add if this keystroke isn't registered for this component v.addElement(c); } } else if (tmp instanceof JComponent) { // if a JComponent is there then remove it and replace it with a vector // Then add the old compoennt and the new compoent to the vector // then insert the vector in the table if (tmp != c) { // this means this is already registered for this component, no need to dup Vector<JComponent> v = new Vector<JComponent>(); v.addElement((JComponent) tmp); v.addElement(c); keyMap.put(k, v); } } else { System.out.println("Unexpected condition in registerKeyStroke"); Thread.dumpStack(); } componentKeyStrokeMap.put(new ComponentKeyStrokePair(c, k), topContainer); // Check for EmbeddedFrame case, they know how to process accelerators even // when focus is not in Java if (topContainer instanceof EmbeddedFrame) { ((EmbeddedFrame) topContainer).registerAccelerator(k); } }
/** * Attach a previously created Axis. Only Axes that have been attached will be drawn * * @param the Axis to attach. */ public void attachAxis(Axis a) { if (a == null) return; try { axis.addElement(a); a.g2d = this; } catch (Exception e) { System.out.println("Failed to attach Axis"); e.printStackTrace(); } }
/** * Load and Attach a DataSet from an array. The method loads the data into a DataSet class and * attaches the class to the graph for plotting. * * <p>The data is assumed to be stored in the form x,y,x,y,x,y.... A local copy of the data is * made. * * @param data The data to be loaded in the form x,y,x,y,... * @param n The number of (x,y) data points. This means that the minimum length of the data array * is 2*n. * @return The DataSet constructed containing the data read. */ public DataSet loadDataSet(double data[], int n) { DataSet d; try { d = new DataSet(data, n); dataset.addElement(d); d.g2d = this; } catch (Exception e) { System.out.println("Failed to load Data set "); e.printStackTrace(); return null; } return d; }
/** * Create and attach an Axis to the graph. The position of the axis is one of Axis.TOP, * Axis.BOTTOM, Axis.LEFT or Axis.RIGHT. * * @param position Position of the axis in the drawing window. */ public Axis createAxis(int position) { Axis a; try { a = new Axis(position); a.g2d = this; axis.addElement(a); } catch (Exception e) { System.out.println("Failed to create Axis"); e.printStackTrace(); return null; } return a; }
public void registerMenuBar(JMenuBar mb) { Container top = getTopAncestor(mb); if (top == null) { return; } Hashtable keyMap = containerMap.get(top); if (keyMap == null) { // lazy evaluate one keyMap = registerNewTopContainer(top); } // use the menubar class as the key Vector menuBars = (Vector) keyMap.get(JMenuBar.class); if (menuBars == null) { // if we don't have a list of menubars, // then make one. menuBars = new Vector(); keyMap.put(JMenuBar.class, menuBars); } if (!menuBars.contains(mb)) { menuBars.addElement(mb); } }
/** Method declaration */ private void refreshTree() { tTree.removeAll(); try { int color_table = Color.yellow.getRGB(); int color_column = Color.orange.getRGB(); int color_index = Color.red.getRGB(); tTree.addRow("", dMeta.getURL(), "-", 0); String usertables[] = {"TABLE"}; ResultSet result = dMeta.getTables(null, null, null, usertables); Vector tables = new Vector(); // sqlbob@users Added remarks. Vector remarks = new Vector(); while (result.next()) { tables.addElement(result.getString(3)); remarks.addElement(result.getString(5)); } result.close(); for (int i = 0; i < tables.size(); i++) { String name = (String) tables.elementAt(i); String key = "tab-" + name + "-"; tTree.addRow(key, name, "+", color_table); // sqlbob@users Added remarks. String remark = (String) remarks.elementAt(i); if ((remark != null) && !remark.trim().equals("")) { tTree.addRow(key + "r", " " + remark); } ResultSet col = dMeta.getColumns(null, null, name, null); while (col.next()) { String c = col.getString(4); String k1 = key + "col-" + c + "-"; tTree.addRow(k1, c, "+", color_column); String type = col.getString(6); tTree.addRow(k1 + "t", "Type: " + type); boolean nullable = col.getInt(11) != DatabaseMetaData.columnNoNulls; tTree.addRow(k1 + "n", "Nullable: " + nullable); } col.close(); tTree.addRow(key + "ind", "Indices", "+", 0); ResultSet ind = dMeta.getIndexInfo(null, null, name, false, false); String oldiname = null; while (ind.next()) { boolean nonunique = ind.getBoolean(4); String iname = ind.getString(6); String k2 = key + "ind-" + iname + "-"; if ((oldiname == null || !oldiname.equals(iname))) { tTree.addRow(k2, iname, "+", color_index); tTree.addRow(k2 + "u", "Unique: " + !nonunique); oldiname = iname; } String c = ind.getString(9); tTree.addRow(k2 + "c-" + c + "-", c); } ind.close(); } tTree.addRow("p", "Properties", "+", 0); tTree.addRow("pu", "User: "******"pr", "ReadOnly: " + cConn.isReadOnly()); tTree.addRow("pa", "AutoCommit: " + cConn.getAutoCommit()); tTree.addRow("pd", "Driver: " + dMeta.getDriverName()); tTree.addRow("pp", "Product: " + dMeta.getDatabaseProductName()); tTree.addRow("pv", "Version: " + dMeta.getDatabaseProductVersion()); } catch (SQLException e) { tTree.addRow("", "Error getting metadata:", "-", 0); tTree.addRow("-", e.getMessage()); tTree.addRow("-", e.getSQLState()); } tTree.update(); }
public void actionPerformed(ActionEvent e) { String a, b, c, f, g, h, j, k, l, m, n, o, p, tol = ""; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:db2"); stm = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); } catch (Exception error) { System.out.println(error); } if (e.getSource() == student) { name = "Student"; cl.show(pnc, "cstu"); try { rs = stm.executeQuery("Select * from Student"); rs.next(); t1.setText(rs.getString(1)); t2.setText(rs.getString(2)); t3.setText(rs.getString(3)); t4.setText(rs.getString(4)); t5.setText(rs.getString(5)); t6.setText(rs.getString(6)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == teacher) { name = "Teacher"; cl.show(pnc, "ctea"); try { rs = stm.executeQuery("Select * from Teacher"); rs.next(); t11.setText(rs.getString(1)); t12.setText(rs.getString(2)); t13.setText(rs.getString(3)); t14.setText(rs.getString(4)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == course) { name = "Course"; cl.show(pnc, "ccou"); try { rs = stm.executeQuery("Select * from Course"); rs.next(); t7.setText(rs.getString(1)); t8.setText(rs.getString(2)); t9.setText(rs.getString(3)); t0.setText(rs.getString(4)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == result) { name = "Result"; cl.show(pnc, "cres"); try { rs = stm.executeQuery("Select * from Result"); rs.next(); t15.setText(rs.getString(1)); t16.setText(rs.getString(2)); t17.setText(rs.getString(3)); t18.setText(rs.getString(4)); t19.setText(rs.getString(5)); t20.setText(rs.getString(6)); t21.setText(rs.getString(7)); t22.setText(rs.getString(8)); t23.setText(rs.getString(9)); t24.setText(rs.getString(10)); t25.setText(rs.getString(11)); t26.setText(rs.getString(12)); t27.setText(rs.getString(13)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b6) { Vector cols = new Vector(); Vector rows = new Vector(); if (z == 1) { String sql = "Select * from " + co; try { rs = stm.executeQuery(sql); meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) cols.addElement(meta.getColumnName(i)); while (rs.next()) { Vector currow = new Vector(); for (int i = 1; i <= meta.getColumnCount(); i++) currow.addElement(rs.getString(i)); rows.addElement(currow); } } catch (Exception ex) { System.out.print(ex); } tb = new JTable(rows, cols); js = new JScrollPane(tb); pne2.remove(js); pne2.add(blk, "bb"); cl2.show(pne2, "bb"); pne2.add(js, "jjs"); cl2.show(pne2, "jjs"); pne2.remove(blk); z = 0; } } if (e.getSource() == b1) // **** ADD BUTTON ****// { if (name == "Student") { a = t1.getText(); b = t2.getText(); c = t3.getText(); f = t4.getText(); g = t5.getText(); h = t6.getText(); tol = "Insert into Student values ('" + a + "','" + b + "','" + c + "','" + f + "','" + g + "','" + h + "')"; } if (name == "Teacher") { a = t11.getText(); b = t12.getText(); c = t13.getText(); f = t14.getText(); tol = "Insert into Teacher values ('" + a + "','" + b + "','" + c + "','" + f + "')"; } if (name == "Course") { a = t7.getText(); b = t8.getText(); c = t9.getText(); f = t0.getText(); tol = "Insert into Course values ('" + a + "','" + b + "','" + c + "','" + f + "')"; } if (name == "Result") { a = t15.getText(); b = t16.getText(); c = t17.getText(); f = t18.getText(); g = t19.getText(); h = t20.getText(); j = t21.getText(); k = t22.getText(); l = t23.getText(); m = t24.getText(); n = t25.getText(); o = t26.getText(); p = t27.getText(); tol = "Insert into Result values ('" + a + "','" + b + "','" + c + "','" + f + "','" + g + "','" + h + "','" + j + "','" + k + "','" + l + "','" + m + "','" + n + "','" + o + "','" + p + "')"; } try { stm.executeUpdate(tol); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b2) // **** DELETE BUTTON ****// { if (name == "Student") { b = t2.getText(); tol = "Delete from Student where Id = '" + b + "'"; } if (name == "Teacher") { b = t12.getText(); tol = "Delete from Teacher where Id = '" + b + "'"; } if (name == "Course") { b = t8.getText(); tol = "Delete from Course where Id = '" + b + "'"; } if (name == "Result") { b = t16.getText(); tol = "Delete from Result where Code = '" + b + "'"; } try { stm.executeUpdate(tol); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b3) // **** UPDATE BUTTON ****// { if (name == "Student") { a = t1.getText(); b = t2.getText(); c = t3.getText(); f = t4.getText(); g = t5.getText(); h = t6.getText(); tol = "Update Student set Name = '" + a + "', ID = '" + b + "', Dept = '" + c + "', CGPA = '" + f + "', Address = '" + g + "', Cell = '" + h + "' where ID = '" + b + "'"; } if (name == "Teacher") { a = t11.getText(); b = t12.getText(); c = t13.getText(); f = t14.getText(); tol = "Update Teacher set Name = '" + a + "', ID = '" + b + "', Dept = '" + c + "', Course = '" + f + "' where ID = '" + b + "'"; } if (name == "Course") { a = t7.getText(); b = t8.getText(); c = t9.getText(); f = t0.getText(); tol = "Update Course set Name = '" + a + "', Code = '" + b + "', Credit = '" + c + "', Prerecusite = '" + f + "' where Code = '" + b + "'"; } if (name == "Result") { a = t15.getText(); b = t16.getText(); c = t17.getText(); f = t18.getText(); g = t19.getText(); h = t20.getText(); j = t21.getText(); k = t22.getText(); l = t23.getText(); m = t24.getText(); n = t25.getText(); o = t26.getText(); p = t27.getText(); tol = "Update Result set Course = '" + a + "', Code = '" + b + "', Credit = '" + c + "', A = '" + f + "', B+ = '" + g + "', B = '" + h + "', C+ = '" + j + "', C = '" + k + "', D+ = '" + l + "', D = '" + m + "', F = '" + n + "', I = '" + o + "', W = '" + p + "' where Code = '" + b + "'"; // JOptionPane.showMessageDialog(null,tol,null,JOptionPane.PLAIN_MESSAGE); // tol = "Update Result set Course = '"+a+"', Code = '"+b+"', Credit = '"+c+"' where Code = // '"+b+"'"; } try { stm.executeUpdate(tol); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b4) // **** NEXT BUTTON ****// { if (name == "Student") { try { if (rs.next()) { t1.setText(rs.getString(1)); t2.setText(rs.getString(2)); t3.setText(rs.getString(3)); t4.setText(rs.getString(4)); t5.setText(rs.getString(5)); t6.setText(rs.getString(6)); } } catch (Exception error) { System.out.println(error); } } if (name == "Teacher") { try { if (rs.next()) { t11.setText(rs.getString(1)); t12.setText(rs.getString(2)); t13.setText(rs.getString(3)); t14.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Course") { try { if (rs.next()) { t7.setText(rs.getString(1)); t8.setText(rs.getString(2)); t9.setText(rs.getString(3)); t0.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Result") { try { if (rs.next()) { t15.setText(rs.getString(1)); t16.setText(rs.getString(2)); t17.setText(rs.getString(3)); t18.setText(rs.getString(4)); t19.setText(rs.getString(5)); t20.setText(rs.getString(6)); t21.setText(rs.getString(7)); t22.setText(rs.getString(8)); t23.setText(rs.getString(9)); t24.setText(rs.getString(10)); t25.setText(rs.getString(11)); t26.setText(rs.getString(12)); t27.setText(rs.getString(13)); } } catch (Exception error) { System.out.println(error); } } } if (e.getSource() == b5) // **** PREVIOUS BUTTON ****// { if (name == "Student") { try { if (rs.previous()) { t1.setText(rs.getString(1)); t2.setText(rs.getString(2)); t3.setText(rs.getString(3)); t4.setText(rs.getString(4)); t5.setText(rs.getString(5)); t6.setText(rs.getString(6)); } } catch (Exception error) { System.out.println(error); } } if (name == "Teacher") { try { if (rs.previous()) { t11.setText(rs.getString(1)); t12.setText(rs.getString(2)); t13.setText(rs.getString(3)); t14.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Course") { try { if (rs.previous()) { t7.setText(rs.getString(1)); t8.setText(rs.getString(2)); t9.setText(rs.getString(3)); t0.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Result") { try { if (rs.previous()) { t15.setText(rs.getString(1)); t16.setText(rs.getString(2)); t17.setText(rs.getString(3)); t18.setText(rs.getString(4)); t19.setText(rs.getString(5)); t20.setText(rs.getString(6)); t21.setText(rs.getString(7)); t22.setText(rs.getString(8)); t23.setText(rs.getString(9)); t24.setText(rs.getString(10)); t25.setText(rs.getString(11)); t26.setText(rs.getString(12)); t27.setText(rs.getString(13)); } } catch (Exception error) { System.out.println(error); } } } }