public void changeLAF(int iLAFIndex) { try { // Change LAF if (iLAFIndex >= marrLaf.length) iLAFIndex = marrLaf.length - 1; UIManager.setLookAndFeel( (LookAndFeel) Class.forName(marrLaf[iLAFIndex].getClassName()).newInstance()); // Update UI ((JMenuItem) mvtLAFItem.elementAt(iLAFIndex)).setSelected(true); SwingUtilities.updateComponentTreeUI(this); SwingUtilities.updateComponentTreeUI(mnuMain); WindowManager.updateLookAndField(); // Store config try { Hashtable prt = Global.loadHashtable(Global.FILE_CONFIG); prt.put("LAF", String.valueOf(iLAFIndex)); Global.storeHashtable(prt, Global.FILE_CONFIG); } catch (Exception e) { } } catch (Exception e) { e.printStackTrace(); MessageBox.showMessageDialog(this, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE); } }
/* * Use reflection to make a test compilable on not Mac OS X */ private static void enableFullScreen(Window window) { try { Class fullScreenUtilities = Class.forName("com.apple.eawt.FullScreenUtilities"); Method setWindowCanFullScreen = fullScreenUtilities.getMethod("setWindowCanFullScreen", Window.class, boolean.class); setWindowCanFullScreen.invoke(fullScreenUtilities, window, true); Class fullScreenListener = Class.forName("com.apple.eawt.FullScreenListener"); Object listenerObject = Proxy.newProxyInstance( fullScreenListener.getClassLoader(), new Class[] {fullScreenListener}, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { switch (method.getName()) { case "windowEnteringFullScreen": windowEnteringFullScreen = true; break; case "windowEnteredFullScreen": windowEnteredFullScreen = true; break; } return null; } }); Method addFullScreenListener = fullScreenUtilities.getMethod( "addFullScreenListenerTo", Window.class, fullScreenListener); addFullScreenListener.invoke(fullScreenUtilities, window, listenerObject); } catch (Exception e) { throw new RuntimeException("FullScreen utilities not available", e); } }
void enableLionFS() { try { String version = System.getProperty("os.version"); String[] tokens = version.split("\\."); int major = Integer.parseInt(tokens[0]), minor = 0; if (tokens.length > 1) minor = Integer.parseInt(tokens[1]); if (major < 10 || (major == 10 && minor < 7)) throw new Exception("Operating system version is " + version); Class fsuClass = Class.forName("com.apple.eawt.FullScreenUtilities"); Class argClasses[] = new Class[] {Window.class, Boolean.TYPE}; Method setWindowCanFullScreen = fsuClass.getMethod("setWindowCanFullScreen", argClasses); setWindowCanFullScreen.invoke(fsuClass, this, true); Class fsListenerClass = Class.forName("com.apple.eawt.FullScreenListener"); InvocationHandler fsHandler = new MyInvocationHandler(cc); Object proxy = Proxy.newProxyInstance( fsListenerClass.getClassLoader(), new Class[] {fsListenerClass}, fsHandler); argClasses = new Class[] {Window.class, fsListenerClass}; Method addFullScreenListenerTo = fsuClass.getMethod("addFullScreenListenerTo", argClasses); addFullScreenListenerTo.invoke(fsuClass, this, proxy); canDoLionFS = true; } catch (Exception e) { vlog.debug("Could not enable OS X 10.7+ full-screen mode:"); vlog.debug(" " + e.toString()); } }
@SuppressWarnings({"rawtypes", "unchecked", "unused"}) public static Atom[] getAtomArray(Atom[] ca, List<Group> hetatoms, List<Group> nucs) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { Class structureAlignmentJmol = Class.forName(strucAligJmol); Class c = Class.forName(displayAFP); Method show = c.getMethod("getAtomArray", new Class[] {Atom[].class, List.class, List.class}); Atom[] atoms = (Atom[]) show.invoke(null, ca, hetatoms, nucs); return atoms; }
@SuppressWarnings({"unused"}) public static Structure getAlignedStructure(Atom[] ca1, Atom[] ca2) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { Class<?> structureAlignmentJmol = Class.forName(strucAligJmol); Class<?> c = Class.forName(displayAFP); Method show = c.getMethod("getAlignedStructure", new Class[] {Atom[].class, Atom[].class}); Structure s = (Structure) show.invoke(null, ca1, ca2); return s; }
@SuppressWarnings({"rawtypes", "unchecked"}) public static void showAlignmentImage(AFPChain afpChain, Atom[] ca1, Atom[] ca2, Object jmol) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { Class structureAlignmentJmol = Class.forName(strucAligJmol); Class c = Class.forName(displayAFP); Method show = c.getMethod( "showAlignmentImage", new Class[] {AFPChain.class, Atom[].class, Atom[].class, structureAlignmentJmol}); show.invoke(null, afpChain, ca1, ca2, jmol); }
public DLNAMediaDatabase(String name) { String dir = "database"; dbName = name; File fileDir = new File(dir); if (Platform.isWindows()) { String profileDir = configuration.getProfileDirectory(); url = String.format("jdbc:h2:%s\\%s/%s", profileDir, dir, dbName); fileDir = new File(profileDir, dir); } else { url = Constants.START_URL + dir + "/" + dbName; } dbDir = fileDir.getAbsolutePath(); LOGGER.debug("Using database URL: " + url); LOGGER.info("Using database located at: " + dbDir); try { Class.forName("org.h2.Driver"); } catch (ClassNotFoundException e) { LOGGER.error(null, e); } JdbcDataSource ds = new JdbcDataSource(); ds.setURL(url); ds.setUser("sa"); ds.setPassword(""); cp = JdbcConnectionPool.create(ds); }
public static void createCanvas(String appClass) { AppSettings settings = new AppSettings(true); settings.setWidth(640); settings.setHeight(480); try { Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(appClass); app = clazz.newInstance(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } catch (InstantiationException ex) { ex.printStackTrace(); } catch (IllegalAccessException ex) { ex.printStackTrace(); } app.setPauseOnLostFocus(false); app.setSettings(settings); app.createCanvas(); app.startCanvas(); context = (JmeCanvasContext) app.getContext(); canvas = context.getCanvas(); canvas.setSize(settings.getWidth(), settings.getHeight()); }
/** * Load a class specified by a file- or entry-name * * @param name name of a file or entry * @return class file that was denoted by the name, null if no class or does not contain a main * method */ private Class load(String name) { if (name.endsWith(".class") && name.indexOf("Test") >= 0 && name.indexOf('$') < 0) { String classname = name.substring(0, name.length() - ".class".length()); if (classname.startsWith("/")) { classname = classname.substring(1); } classname = classname.replace('/', '.'); try { final Class<?> cls = Class.forName(classname); cls.getMethod("main", new Class[] {String[].class}); if (!getClass().equals(cls)) { return cls; } } catch (NoClassDefFoundError e) { // class has unresolved dependencies return null; } catch (ClassNotFoundException e) { // class not in classpath return null; } catch (NoSuchMethodException e) { // class does not have a main method return null; } catch (UnsupportedClassVersionError e) { // unsupported version return null; } } return null; }
public void actionPerformed(java.awt.event.ActionEvent evt) { String sql1 = "select a.* FROM ANTENA a WHERE a.ID_antena='" + (newJPanel.jList1.getSelectedIndex() + 1) + "' "; String pom = ""; System.out.println(sql1); try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn; try { conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", user, password); Statement stmt1 = conn.createStatement(); ResultSet rs1 = stmt1.executeQuery(sql1); while (rs1.next()) { NewJPanel.jTextField1.setText(rs1.getString("ID_antena")); NewJPanel.jTextField2.setText(rs1.getString("Producent")); NewJPanel.jTextField3.setText(rs1.getString("Numer_identyfikacyjny")); NewJPanel.jTextField4.setText(rs1.getString("Czestotliwosc")); NewJPanel.jTextField5.setText(rs1.getString("Polaryzacja")); NewJPanel.jTextField6.setText(rs1.getString("Moc")); NewJPanel.jTextField7.setText(rs1.getString("Rodzaj")); } } catch (SQLException e1) { System.out.println("tutaj 1"); e1.printStackTrace(); } } catch (ClassNotFoundException e1) { System.out.println("tutaj 2"); e1.printStackTrace(); } }
/** Checks if the program can run under the JDK it was started with. */ private static boolean checkJdkVersion() { if (!"true".equals(System.getProperty("idea.no.jre.check"))) { try { // try to find a class from tools.jar Class.forName("com.sun.jdi.Field"); } catch (ClassNotFoundException e) { showError( "Error", "'tools.jar' is not in " + ApplicationNamesInfo.getInstance().getProductName() + " classpath.\n" + "Please ensure JAVA_HOME points to JDK rather than JRE."); return false; } } if (!"true".equals(System.getProperty("idea.no.jdk.check"))) { final String version = System.getProperty("java.version"); if (!SystemInfo.isJavaVersionAtLeast("1.6")) { showError( "Java Version Mismatch", "The JDK version is " + version + ".\n" + ApplicationNamesInfo.getInstance().getProductName() + " requires JDK 1.6 or higher."); return false; } } return true; }
/** @since 3.0.5 */ public static void showDBResults(StartupParameters params) { // System.err.println("not implemented full yet"); // We want to do this, but because we don't know if structure-gui.jar is in the classpath we use // reflection to hide the calls UserConfiguration config = UserConfiguration.fromStartupParams(params); String tableClass = "org.biojava.nbio.structure.align.gui.DBResultTable"; try { Class<?> c = Class.forName(tableClass); Object table = c.newInstance(); Method show = c.getMethod("show", new Class[] {File.class, UserConfiguration.class}); show.invoke(table, new File(params.getShowDBresult()), config); } catch (Exception e) { e.printStackTrace(); System.err.println( "Probably structure-gui.jar is not in the classpath, can't show results..."); } // DBResultTable table = new DBResultTable(); // table.show(new File(params.getShowDBresult()),config); }
private static boolean classExists(final ClassLoader classLoader, final String clazzName) { try { return Class.forName(clazzName, false, classLoader) != null; } catch (final Throwable ignored) { } return false; }
private void ListValueChanged( javax.swing.event.ListSelectionEvent evt) { // GEN-FIRST:event_ListValueChanged // TODO add your handling code here: // String part=partno.getText(); try { String sql = "SELECT TYPE,ITEM_NAME,QUANTITY,MRP FROM MOTORS WHERE ITEM_NAME='" + List.getSelectedValue() + "'"; Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", ""); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { partno.setText(rs.getString("TYPE")); name.setText(rs.getString("ITEM_NAME")); qty.setText(rs.getString("QUANTITY")); rate.setText(rs.getString("MRP")); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString()); } } // GEN-LAST:event_ListValueChanged
/** * @return an instanciation of the given content-type class name, or null if class wasn't found */ public static ContentType getContentTypeFromClassName(String contentTypeClassName) { if (contentTypeClassName == null) contentTypeClassName = getAvailableContentTypes()[DEFAULT_CONTENT_TYPE_INDEX]; ContentType ct = null; try { Class clazz = Class.forName(contentTypeClassName); ct = (ContentType) clazz.newInstance(); } catch (ClassNotFoundException cnfex) { if (jpicedt.Log.DEBUG) cnfex.printStackTrace(); JPicEdt.getMDIManager() .showMessageDialog( "The pluggable content-type you asked for (class " + cnfex.getLocalizedMessage() + ") isn't currently installed, using default instead...", Localizer.currentLocalizer().get("msg.LoadingContentTypeClass"), JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { if (jpicedt.Log.DEBUG) ex.printStackTrace(); JPicEdt.getMDIManager() .showMessageDialog( ex.getLocalizedMessage(), Localizer.currentLocalizer().get("msg.LoadingContentTypeClass"), JOptionPane.ERROR_MESSAGE); } return ct; }
private /*synchronized*/ StructureType assignStructureType(String structType) throws VisualizerLoadException { if (debug) System.out.println("In assignStructureType with " + structType); // Handle objects whose constructors require args separately if ((structType.toUpperCase().compareTo("BAR") == 0) || (structType.toUpperCase().compareTo("SCAT") == 0)) return (new BarScat(structType.toUpperCase())); else if ((structType.toUpperCase().compareTo("GRAPH") == 0) || (structType.toUpperCase().compareTo("NETWORK") == 0)) return (new Graph_Network(structType.toUpperCase())); else { // Constructor for object does not require args try { return ((StructureType) ((Class.forName(insure_text_case_correct_for_legacy_scripts(structType))) .newInstance())); } catch (InstantiationException e) { System.out.println(e); throw (new VisualizerLoadException(structType + " is invalid structure type")); } catch (IllegalAccessException e) { System.out.println(e); throw (new VisualizerLoadException(structType + " is invalid structure type")); } catch (ClassNotFoundException e) { System.out.println(e); throw (new VisualizerLoadException(structType + " is invalid structure type")); } } }
private XmlUIElement getXmlUIElementFor(String typeArg) { if (typeToClassMappingProp == null) { setUpMappingsHM(); } String clsName = (String) typeToClassMappingProp.get(typeArg); if ((clsName != null) && !(clsName.equals("*NOTFOUND*")) && !(clsName.equals("*EXCEPTION*"))) { try { Class cls = Class.forName(clsName); return (XmlUIElement) cls.newInstance(); } catch (Throwable th) { typeToClassMappingProp.put(typeArg, "*EXCEPTION*"); showErrorMessage( MessageFormat.format( ProvClientUtils.getString( "{0} occurred when trying to get the XmlUIElement for type : {1}"), new Object[] {th.getClass().getName(), typeArg})); th.printStackTrace(); return null; } } else if (clsName == null) { typeToClassMappingProp.put(typeArg, "*NOTFOUND*"); showErrorMessage( MessageFormat.format( ProvClientUtils.getString( "The type {0} does not have the corresponding XMLUIElement specified in the TypeToUIElementMapping.txt file"), new Object[] {typeArg})); } return null; }
public void actionPerformed(ActionEvent ae) { if (ae.getSource() == b1) { try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "123"); PreparedStatement ps = con.prepareStatement("select * from LoginForm where username=? and password=?"); String UserName = t1.getText(); String Password = jp1.getText(); ps.setString(1, UserName); ps.setString(2, Password); ResultSet rs = ps.executeQuery(); boolean flag = rs.next(); if (flag) { new Main(); f.setVisible(false); } else { JOptionPane.showMessageDialog(null, "Please Enter valid Name And Password"); } } catch (Exception e) { System.out.println("Error:" + e); } } else if (ae.getSource() == b2) { t1.setText(""); jp1.setText(""); } else if (ae.getSource() == b3) { f.setVisible(false); } }
public static FontMetrics getFontMetrics(JComponent c, Graphics g, Font f) { FontMetrics fm = null; if (getJavaVersion() >= 1.6) { try { Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2"); Class classParams[] = {JComponent.class, Graphics.class, Font.class}; Method m = swingUtilities2Class.getMethod("getFontMetrics", classParams); Object methodParams[] = {c, g, f}; fm = (FontMetrics) m.invoke(null, methodParams); } catch (Exception ex) { // Nothing to do } } if (fm == null) { if (g == null) { if (c != null) { g = c.getGraphics(); } } if (g != null) { if (f != null) { fm = g.getFontMetrics(f); } else { fm = g.getFontMetrics(); } } else if (c != null) { if (f != null) { fm = c.getFontMetrics(f); } else { fm = c.getFontMetrics(c.getFont()); } } } return fm; }
public static void drawStringUnderlineCharAt( JComponent c, Graphics g, String text, int underlinedIndex, int x, int y) { Graphics2D g2D = (Graphics2D) g; Object savedRenderingHint = null; if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) { savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2D.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint()); } if (getJavaVersion() >= 1.6) { try { Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2"); Class classParams[] = { JComponent.class, Graphics.class, String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE }; Method m = swingUtilities2Class.getMethod("drawStringUnderlineCharAt", classParams); Object methodParams[] = { c, g, text, new Integer(underlinedIndex), new Integer(x), new Integer(y) }; m.invoke(null, methodParams); } catch (Exception ex) { BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y); } } else if (getJavaVersion() >= 1.4) { BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, underlinedIndex, x, y); } else { BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y); } if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) { g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint); } }
/** Determine whether the current user has Windows administrator privileges. */ public static boolean isWinAdmin() { if (!isWinPlatform()) return false; // for (String group : new com.sun.security.auth.module.NTSystem().getGroupIDs()) { // if (group.equals("S-1-5-32-544")) return true; // "S-1-5-32-544" is a well-known // security identifier in Windows. If the current user has it then he/she/it is an // administrator. // } // return false; try { Class<?> ntsys = Class.forName("com.sun.security.auth.module.NTSystem"); if (ntsys != null) { Object groupObj = SystemUtils.invoke( ntsys.newInstance(), ntsys.getDeclaredMethod("getGroupIDs"), (Object[]) null); if (groupObj instanceof String[]) { for (String group : (String[]) groupObj) { if (group.equals("S-1-5-32-544")) return true; // "S-1-5-32-544" is a well-known security identifier in Windows. If the // current user has it then he/she/it is an administrator. } } } } catch (ReflectiveOperationException e) { System.err.println(e); } return false; }
public void actionPerformed(ActionEvent ae) { String cname = nameF.getText().trim(); int state = conditions[stateC.getSelectedIndex()]; try { if (isSpecialCase(cname)) { handleSpecialCase(cname, state); } else { JComponent comp = (JComponent) Class.forName(cname).newInstance(); ComponentUI cui = UIManager.getUI(comp); cui.installUI(comp); results.setText("Map entries for " + cname + ":\n\n"); if (inputB.isSelected()) { loadInputMap(comp.getInputMap(state), ""); results.append("\n"); } if (actionB.isSelected()) { loadActionMap(comp.getActionMap(), ""); results.append("\n"); } if (bindingB.isSelected()) { loadBindingMap(comp, state); } } } catch (ClassCastException cce) { results.setText(cname + " is not a subclass of JComponent."); } catch (ClassNotFoundException cnfe) { results.setText(cname + " was not found."); } catch (InstantiationException ie) { results.setText(cname + " could not be instantiated."); } catch (Exception e) { results.setText("Exception found:\n" + e); e.printStackTrace(); } }
private void Simpan() { if (btnSave.getText().equals("Edit")) { try { Class.forName(KoneksiDatabase.driver); java.sql.Connection c = DriverManager.getConnection( KoneksiDatabase.database, KoneksiDatabase.user, KoneksiDatabase.pass); Statement s = c.createStatement(); String sql; sql = "update absensi_lembur set tipehari = '"; sql += cmbJenisHari.getSelectedItem() + "', tot_waktu_lembur='"; sql += txtTotalLembur.getText() + "'"; sql += "where kd_absen = '" + txtKodeAbsen.getText() + "'"; s.executeQuery(sql); JOptionPane.showMessageDialog( null, "Data Berhasil Disimpan!!!", "Informasi", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog( null, "Gagal Disimpan, Data Harus Lengkap !!!", "Peringatan", JOptionPane.WARNING_MESSAGE); } } Baru(); }
private void btnDeleteActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnDeleteActionPerformed // TODO add your handling code here: if (txtKodeAbsen.getText().equals("")) { JOptionPane.showMessageDialog( null, "Isi Kode Absen yang Akan dihapus !!!", "Peringatan", JOptionPane.ERROR_MESSAGE); txtKodeAbsen.requestFocus(); } else { try { Class.forName(KoneksiDatabase.driver); java.sql.Connection c = DriverManager.getConnection( KoneksiDatabase.database, KoneksiDatabase.user, KoneksiDatabase.pass); Statement s = c.createStatement(); String sql = "DELETE FROM absensi_lembur where kd_absen ='" + txtKodeAbsen.getText() + "'"; s.executeUpdate(sql); JOptionPane.showMessageDialog(null, "Data Berhasil Dihapus !"); Baru(); } catch (Exception e) { JOptionPane.showMessageDialog( null, "Kemungkinan terjadi kegagalan koneksi", "Warning", JOptionPane.ERROR_MESSAGE); } } } // GEN-LAST:event_btnDeleteActionPerformed
private void Baru() { btnSave.setText("Save"); txtNip.requestFocus(); txtNip.setText(""); try { Class.forName(KoneksiDatabase.driver); java.sql.Connection c = DriverManager.getConnection( KoneksiDatabase.database, KoneksiDatabase.user, KoneksiDatabase.pass); Statement s = c.createStatement(); String sql = "select * from absensi_lembur"; ResultSet rs = s.executeQuery(sql); final String[] headers = { "Kd Absen", "NIP", "Tgl Absen", "Masuk", "Pulang", "Hari", "Tipe Hari", "Terlambat", "Lembur", "Tipe Lembur", "Tot Lembur", "Tunj Makan", "Tunj Transport" }; rs.last(); int n = rs.getRow(); Object[][] data = new Object[n][13]; int p = 0; rs.beforeFirst(); while (rs.next()) { data[p][0] = rs.getString(1); data[p][1] = rs.getString(2); data[p][2] = rs.getString(3); data[p][3] = rs.getString(4); data[p][4] = rs.getString(5); data[p][5] = rs.getString(6); data[p][6] = rs.getString(7); data[p][7] = rs.getString(8); data[p][8] = rs.getString(9); data[p][9] = rs.getString(10); data[p][10] = rs.getString(11); data[p][11] = rs.getString(12); data[p][12] = rs.getString(13); p++; } tblLembur.setModel(new DefaultTableModel(data, headers)); tblLembur.setAlignmentX(CENTER_ALIGNMENT); } catch (Exception e) { JOptionPane.showMessageDialog( null, "Gagal Koneksi, Ada Kesalahan.", "Warning", JOptionPane.WARNING_MESSAGE); } }
public static void invoke(String aClass, String aMethod, Class[] params, Object[] args) throws Exception { Class c = Class.forName(aClass); Constructor constructor = c.getConstructor(params); Method m = c.getDeclaredMethod(aMethod, params); Object i = constructor.newInstance(args); Object r = m.invoke(i, args); }
static { try { Class.forName("com.apple.eawt.FullScreenUtilities"); HAS_FULLSCREEN_UTILITIES = true; } catch (Exception e) { HAS_FULLSCREEN_UTILITIES = false; } }
public void load_DriverJDBC() { try { Class.forName("com.mysql.jdbc.Driver"); status_Proses(true, "Sukses!!!Driver JDBC ditemukan...", 20); } catch (ClassNotFoundException cnfe) { status_Proses(false, "Gagal!!!Driver JDBC tidak ditemukan...", 20); } }
public void connectItems(String query) // PRE: query must be initialized // POST: Updates the list of Items based on the query. { String driver = "org.apache.derby.jdbc.ClientDriver"; // Driver for DB String url = "jdbc:derby://localhost:1527/ShopDataBase"; // Url for DB String user = "******"; // Username for db String pass = "******"; // Password for db Connection myConnection; // Connection obj to db Statement stmt; // Statement to execute a result appon ResultSet results; // A set containing the returned results int rowcount; // Num objects in the resultSet int i; // Index for the array try { // Try connection to db Class.forName(driver).newInstance(); // Create our db driver myConnection = DriverManager.getConnection(url, user, pass); // Initalize our connection stmt = myConnection.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); // Create a new statement results = stmt.executeQuery(query); // Store the results of our query rowcount = 0; if (results.last()) // Go to the last result { rowcount = results.getRow(); results.beforeFirst(); } itemsArray = new Item[rowcount]; i = 0; while (results.next()) // Itterate through the results set { itemsArray[i] = new Item( results.getInt("item_id"), results.getString("item_name"), results.getString("item_type"), results.getInt("price"), results.getInt("owner_id"), results.getString("item_path")); // Creat new Item i++; } results.close(); // Close the ResultSet stmt.close(); // Close the statement myConnection.close(); // Close the connection to db } catch (Exception e) // Cannot connect to db { System.err.println(e.toString()); System.err.println("Error, something went horribly wrong in connectItems!"); } }
/** Sets current LAF. The method doesn't update component hierarchy. */ @Override public void setCurrentLookAndFeel(UIManager.LookAndFeelInfo lookAndFeelInfo) { if (findLaf(lookAndFeelInfo.getClassName()) == null) { LOG.error("unknown LookAndFeel : " + lookAndFeelInfo); return; } // Set L&F if (IdeaLookAndFeelInfo.CLASS_NAME.equals( lookAndFeelInfo.getClassName())) { // that is IDEA default LAF IdeaLaf laf = new IdeaLaf(); MetalLookAndFeel.setCurrentTheme(new IdeaBlueMetalTheme()); try { UIManager.setLookAndFeel(laf); } catch (Exception e) { Messages.showMessageDialog( IdeBundle.message( "error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } } else if (DarculaLookAndFeelInfo.CLASS_NAME.equals(lookAndFeelInfo.getClassName())) { DarculaLaf laf = new DarculaLaf(); try { UIManager.setLookAndFeel(laf); JBColor.setDark(true); IconLoader.setUseDarkIcons(true); } catch (Exception e) { Messages.showMessageDialog( IdeBundle.message( "error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } } else { // non default LAF try { LookAndFeel laf = ((LookAndFeel) Class.forName(lookAndFeelInfo.getClassName()).newInstance()); if (laf instanceof MetalLookAndFeel) { MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); } UIManager.setLookAndFeel(laf); } catch (Exception e) { Messages.showMessageDialog( IdeBundle.message( "error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } } myCurrentLaf = ObjectUtils.chooseNotNull(findLaf(lookAndFeelInfo.getClassName()), lookAndFeelInfo); checkLookAndFeel(lookAndFeelInfo, false); }