/** Creates new form CallForm */ public Controller() { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { logger.log(java.util.logging.Level.SEVERE, ex.getMessage(), ex); } initComponents(); this.setVisible(true); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); this.addWindowListener( new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { if (cancelButton.isEnabled()) { setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); System.exit(0); } } }); }
private Observer<Observable> getMaritalStatusChangeObserver() { try { return (Observer<Observable>) getMaritalStatusChangeObserverClass().newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { LOGGER.error(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); } }
public static Plugin get(String name) { try { Class<?> klass = Class.forName("plugins." + name + "Plugin"); Plugin plugin = (Plugin) klass.newInstance(); return plugin; } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { e.printStackTrace(); return null; } }
/** * Instancie les classes correspondants aux agents participant à la partie en cours. <i>Note :</i> * on pourrait utiliser un pool contenant tous les threads gérant les agents. Cependant, on ne * saurait pas quel thread est assigné à quel agent. En cas de blocage par un agent (ex. boucle * infini), c'est un autre agent qui pourrait en faire les frais. Pour cette raison, on sépare les * threads : 1 par executor, avec 1 executor propre à chaque agent. * * @param players Joueurs de la partie en cours. */ @SuppressWarnings("unchecked") private void initAgents(Player players[]) { agents = new Agent[players.length]; futures = (Future<Direction>[]) new Future[players.length]; executors = new ExecutorService[players.length]; elapsedTimes = new long[players.length]; for (int i = 0; i < players.length; i++) { Player player = players[i]; Agent agent = null; ExecutorService executor = null; Profile profile = player.profile; String agentName = profile.agent; if (player.local && agentName != null) { try { // on charge la classe String packageName = AGENTS_PACKAGE + "." + agentName; String classQualifiedName = packageName + "." + AGENT_MAIN_CLASS; Class<?> tempClass = Class.forName(classQualifiedName); if (!Agent.class.isAssignableFrom(tempClass)) throw new ClassCastException(classQualifiedName); // on l'instancie agent = (Agent) tempClass.getConstructor(Integer.class).newInstance(new Integer(i)); final String aName = i + ". " + player.profile.userName + " " + "(src=" + agentName + ")"; // on crée l'exécuteur associé executor = Executors.newSingleThreadExecutor( new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread result = new Thread(r); result.setName(aName); result.setPriority(Thread.MIN_PRIORITY); return result; } }); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { e.printStackTrace(); } } agents[i] = agent; executors[i] = executor; futures[i] = null; elapsedTimes[i] = 0; } }
@SuppressWarnings({"unchecked", "deprecation"}) public static <E extends Entity> EntityManager<E> getDao(Class<E> clazz) { String name = "Dao" + clazz.getSimpleName(); String pakage = "br.ueg.openodonto.persistencia.dao"; try { Class<EntityManager<E>> c = (Class<EntityManager<E>>) Class.forName(pakage + "." + name); return c.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { e.printStackTrace(); } return null; }
/** Create the frame. */ public Frame() { setIconImage( Toolkit.getDefaultToolkit() .getImage( Frame.class.getResource("/nl/compra/CompraSiteMapperGUI/Resources/compra.png"))); setTitle("Compra Sitemap Generator"); setResizable(false); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { // TODO Auto-generated catch block e.printStackTrace(); } setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 668, 455); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); getContentPane().setLayout(null); contentPane.setLayout(null); JLabel lblUrl = new JLabel("URL:"); lblUrl.setBounds(6, 11, 28, 16); getContentPane().add(lblUrl); textFieldURL = new JTextField(); textFieldURL.setHorizontalAlignment(SwingConstants.LEFT); textFieldURL.setBounds(32, 5, 499, 28); textFieldURL.setToolTipText("Enter a URL for the crawler to crawl"); getContentPane().add(textFieldURL); textFieldURL.setColumns(10); JButton btnCrawl = new JButton("Crawl"); btnCrawl.setBounds(541, 5, 108, 28); btnCrawl.setAction(action); getContentPane().add(btnCrawl); JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setBounds(6, 39, 643, 373); getContentPane().add(scrollPane_1); textAreaLog = new JTextArea(); scrollPane_1.setViewportView(textAreaLog); textAreaLog.setDropMode(DropMode.INSERT); textAreaLog.setTabSize(4); }
/** * A utility function that layers on top of the LookAndFeel's isSupportedLookAndFeel() method. * Returns true if the LookAndFeel is supported. Returns false if the LookAndFeel is not supported * and/or if there is any kind of error checking if the LookAndFeel is supported. * * <p>The Look and Feel menu will use this method to determine whether the various Look and Feel * options should be active or inactive. * * @param laf name of look and feel to search for * @return true if found */ @SuppressWarnings("rawtypes") private static boolean isLookAndFeelAvailable(final String laf) { try { Class lnfClass = Class.forName(laf); LookAndFeel newLAF = (LookAndFeel) lnfClass.newInstance(); return newLAF.isSupportedLookAndFeel(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // If ANYTHING bad happens, return false Logger.getLogger(ThemeManager.class.getName()).log(Level.FINEST, e.getLocalizedMessage(), e); return false; } }
private static void setTheme(final String theme) { try { Class<?> themeClass = Class.forName(theme); MetalTheme themeObject = (MetalTheme) themeClass.newInstance(); MetalLookAndFeel.setCurrentTheme(themeObject); } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) { Logger.getLogger(ThemeManager.class.getName()) .log( Level.SEVERE, "Could not install theme: {0}\n{1}", new Object[] {theme, e.toString()}); } }
public static void createAndShowGUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } JFrame frame = new JFrame("@title@"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(new MainPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
static { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); Enumeration keys = UIManager.getDefaults().keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value instanceof Font) { Font f = (Font) value; UIManager.put(key, f.deriveFont(Font.BOLD, f.getSize() * 1.2f)); } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { e.printStackTrace(); } localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); defaultScreenDevice = localGraphicsEnvironment.getDefaultScreenDevice(); displayMode = defaultScreenDevice.getDisplayMode(); for (GraphicsDevice device : localGraphicsEnvironment.getScreenDevices()) { System.out.println(device.toString()); } reloadFonts(); Config.addConfigChangeListener( new String[] { "font1_file", "font1_size", "font2_file", "font2_size", }, new ConfigChangeListener() { @Override public void configChanged(ConfigChangeEvent e) { reloadFonts(); MainFrame.getInstance().repaint(); ProgramWindow.getInstance().repaint(); } }); instance = new MainFrame(); }
/** * Create the GUI and show it. For thread safety, this method should be invoked from the event * dispatch thread. */ private static void createAndShowGUI() { ExceptionReporting.registerExceptionReporter(); // Added to handle possible JDK 1.6 bug (thanks to Makoto Yui and the BaseX // guys). UIManager.getInstalledLookAndFeels(); // Refresh views when windows are resized (thanks to the BaseX guys). Toolkit.getDefaultToolkit().setDynamicLayout(true); if (mUseSystemLookAndFeel) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { LOGWRAPPER.error(e.getMessage(), e); } } else { try { for (final LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (final Exception e) { // If Nimbus is not available, you can set the GUI to another look and // feel. try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException exc) { LOGWRAPPER.error(exc.getMessage(), exc); } } } // Create GUI. new GUI(new GUIProp()); }
private void setLookAndFeel() { // TODO: De volgende werkt nog niet (appname in title balk) System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", APP_NAME); try { // Native platform Look and Feel UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // Cross platform Look and Feel // UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) { System.out.println(e.getMessage()); } }
/** * Main method of the app. * * @param args Main method args */ public static void main(final String[] args) { for (final LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { try { UIManager.setLookAndFeel(info.getClassName()); } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException exc) { exc.printStackTrace(); } break; } } javax.swing.SwingUtilities.invokeLater( new Runnable() { public void run() { createAndShowGUI(); } }); }
public List<TailType> getTailTypeFromArgs(String... types) { List<TailType> tailers = new LinkedList<TailType>(); TailType tailType = null; for (String type : types) { if ("".equals(type)) { System.out.println("------------- WARNING -----------------"); System.out.println("---- No Tail Type passed as argument, using default NoOpTailType ----"); tailers.add(new NoopTailType()); } else { Class<?> clazz; try { clazz = Class.forName("org.mongo.tail.types." + type); tailType = (TailType) clazz.newInstance(); tailers.add(tailType); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { e.printStackTrace(); throw new RuntimeException( "Unknown tail type passed to TailTypeInjector. You must pass the name of the TailType class."); } } } return tailers; }
public static void createAndShowGUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } JFrame frame = new JFrame("@title@"); frame.setIconImages( Arrays.asList( makeBufferedImage(new StarIcon(), 16, 16), makeBufferedImage(new StarIcon(16, 8, 5), 40, 40))); // frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.getContentPane().add(new MainPanel(frame)); frame.setResizable(false); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
public boolean deleteEvent(int id) { Connection con = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql://160.153.16.42:3306/Enterprise_Gym", user, pass); PreparedStatement deleteNews = null; System.out.println("The id to be deleted is:" + id); int i; String DeleteEvent = "DELETE e.* FROM event e WHERE e.idevent = ?;"; deleteNews = con.prepareStatement(DeleteEvent); deleteNews.setInt(1, id); i = deleteNews.executeUpdate(); System.out.println("The variable i is:" + i); if (i == 0) { System.out.println("false"); return false; } else { return true; } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) { System.out.println("expection thrown"); System.out.println("false, exception"); e.printStackTrace(); return false; } }
public static void createAndShowGUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } // UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.allAuditoryCues")); // UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.defaultCueList")); // UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.noAuditoryCues")); UIManager.put("AuditoryCues.playList", OPTION_PANE_AUDITORY_CUES); // UIManager.put("OptionPane.informationSound", "/example/notice2.wav"); // UIManager.put("OptionPane.informationSound", "sounds/OptionPaneError.wav"); // System.out.println(UIManager.get("AuditoryCues.actionMap")); JFrame frame = new JFrame("@title@"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(new MainPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
public MainWindow() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } setTitle("Podmieniacz"); setResizable(false); pop = new PopUpMenu(); popup2 = new PopUpMenu(); run = new boolean[4]; defaults[0] = "Œcie¿ka do katalogu"; defaults[1] = "Rozszerzenie pliku, bez \".\""; // Tablica wartoœci logicznych run[] s³u¿y do sprawdzenia // warunków potrzebnych do prawid³owego dzia³ania programu. // Pocz¹tkowo wszystkie równe s¹ false. for (int r = 0; r < run.length; r++) { run[r] = false; } setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 720, 480); JMenuBar menuBar = new JMenuBar(); JMenu mnPomoc = new JMenu("Pomoc"); JMenuItem help = new JMenuItem("Pomoc programu Podmieniacz"); mnPomoc.add(help); // W przypadku wybrania opcji "pomoc programu" pojawia siê okno pomocy help.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { HelpWindow hw = new HelpWindow(); hw.setVisible(true); } }); // help.addActionListener(this); help.setIcon(new ImageIcon(MainWindow.class.getResource("/resources/Help-icon.png"))); JMenuItem about = new JMenuItem("O programie Podmieniacz"); mnPomoc.add(about); // W przypadku wybrania opcji "o programie" pojawia siê okno informacji about.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { AboutWindow aw = new AboutWindow(); aw.setVisible(true); } }); // about.addActionListener(this); menuBar.add(mnPomoc); setJMenuBar(menuBar); Icon pic = null; try { pic = new ImageIcon( ImageIO.read(getClass().getResourceAsStream(("/resources/lupa_yellow.png")))); } catch (IOException e) { e.printStackTrace(); } contentPane = new JPanel(); contentPane.setForeground(Color.DARK_GRAY); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); GridBagLayout gbl_contentPane = new GridBagLayout(); gbl_contentPane.columnWidths = new int[] {175, 371, 0}; gbl_contentPane.rowHeights = new int[] {30, 30, 30, 30, 30, 0, 30, 30, 0, 30}; gbl_contentPane.columnWeights = new double[] {0.1, 0.8, 0.1}; gbl_contentPane.rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE}; contentPane.setLayout(gbl_contentPane); directory = new Input(defaults[0], defaults[0]); directory.setToolTipText("Na przyk\u0142ad: C:\\Users"); directory.setForeground(Color.DARK_GRAY); directory.add(pop.getPopupMenu()); directory.setComponentPopupMenu(pop.getPopupMenu()); GridBagConstraints gbc_directory = new GridBagConstraints(); gbc_directory.fill = GridBagConstraints.HORIZONTAL; gbc_directory.insets = new Insets(0, 0, 5, 5); gbc_directory.gridx = 1; gbc_directory.gridy = 1; directory.getPreferredSize(); JLabel lblKatalogDoPrzeszukania = new JLabel("Katalog do przeszukania:"); GridBagConstraints gbc_lblKatalogDoPrzeszukania = new GridBagConstraints(); gbc_lblKatalogDoPrzeszukania.insets = new Insets(0, 0, 5, 5); gbc_lblKatalogDoPrzeszukania.anchor = GridBagConstraints.EAST; gbc_lblKatalogDoPrzeszukania.gridx = 0; gbc_lblKatalogDoPrzeszukania.gridy = 1; contentPane.add(lblKatalogDoPrzeszukania, gbc_lblKatalogDoPrzeszukania); contentPane.add(directory, gbc_directory); directory.setColumns(10); btnWybierz = new JButton("Wybierz..."); btnWybierz.setPreferredSize(new Dimension(136, 20)); btnWybierz.setToolTipText("Wybierz katalog, w którym nale¿y wyszukaæ pliki"); // Klikniêcie przycisku spowoduje wyœwietlenie okna wyboru katalogu btnWybierz.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { OpenDirectory od = new OpenDirectory(); directory.setText(od.getFolder()); } }); GridBagConstraints gbc_btnWybierz = new GridBagConstraints(); gbc_btnWybierz.anchor = GridBagConstraints.WEST; gbc_btnWybierz.insets = new Insets(0, 0, 5, 0); gbc_btnWybierz.gridx = 2; gbc_btnWybierz.gridy = 1; contentPane.add(btnWybierz, gbc_btnWybierz); JLabel lblRozszerzenie = new JLabel("Rozszerzenie pliku:"); GridBagConstraints gbc_lblRozszerzenie = new GridBagConstraints(); gbc_lblRozszerzenie.anchor = GridBagConstraints.EAST; gbc_lblRozszerzenie.insets = new Insets(0, 0, 5, 5); gbc_lblRozszerzenie.gridx = 0; gbc_lblRozszerzenie.gridy = 2; contentPane.add(lblRozszerzenie, gbc_lblRozszerzenie); fileFormat = new Input(defaults[1], defaults[1]); fileFormat.setToolTipText("Na przyk\u0142ad: txt"); fileFormat.setForeground(Color.DARK_GRAY); fileFormat.add(pop.getPopupMenu()); fileFormat.setComponentPopupMenu(pop.getPopupMenu()); GridBagConstraints gbc_fileFormat = new GridBagConstraints(); gbc_fileFormat.insets = new Insets(0, 0, 5, 5); gbc_fileFormat.fill = GridBagConstraints.HORIZONTAL; gbc_fileFormat.gridx = 1; gbc_fileFormat.gridy = 2; contentPane.add(fileFormat, gbc_fileFormat); fileFormat.setColumns(10); JLabel lblacuchZnakwDo = new JLabel("\u0141a\u0144cuch znak\u00F3w do wyszukania:"); GridBagConstraints gbc_lblacuchZnakwDo = new GridBagConstraints(); gbc_lblacuchZnakwDo.anchor = GridBagConstraints.EAST; gbc_lblacuchZnakwDo.insets = new Insets(0, 0, 5, 5); gbc_lblacuchZnakwDo.gridx = 0; gbc_lblacuchZnakwDo.gridy = 3; contentPane.add(lblacuchZnakwDo, gbc_lblacuchZnakwDo); findText = new Input("", ""); findText.setForeground(Color.DARK_GRAY); findText.add(pop.getPopupMenu()); findText.setComponentPopupMenu(pop.getPopupMenu()); GridBagConstraints gbc_findText = new GridBagConstraints(); gbc_findText.insets = new Insets(0, 0, 5, 5); gbc_findText.fill = GridBagConstraints.HORIZONTAL; gbc_findText.gridx = 1; gbc_findText.gridy = 3; contentPane.add(findText, gbc_findText); findText.setColumns(10); JLabel lblacuchZnakwDo_1 = new JLabel("\u0141a\u0144cuch znak\u00F3w do zamiany:"); GridBagConstraints gbc_lblacuchZnakwDo_1 = new GridBagConstraints(); gbc_lblacuchZnakwDo_1.anchor = GridBagConstraints.EAST; gbc_lblacuchZnakwDo_1.insets = new Insets(0, 0, 5, 5); gbc_lblacuchZnakwDo_1.gridx = 0; gbc_lblacuchZnakwDo_1.gridy = 4; contentPane.add(lblacuchZnakwDo_1, gbc_lblacuchZnakwDo_1); replaceText = new Input("", ""); replaceText.setForeground(Color.DARK_GRAY); replaceText.add(pop.getPopupMenu()); replaceText.setComponentPopupMenu(pop.getPopupMenu()); GridBagConstraints gbc_replaceText = new GridBagConstraints(); gbc_replaceText.insets = new Insets(0, 0, 5, 5); gbc_replaceText.fill = GridBagConstraints.HORIZONTAL; gbc_replaceText.gridx = 1; gbc_replaceText.gridy = 4; contentPane.add(replaceText, gbc_replaceText); replaceText.setColumns(10); findReplace = new JButton("Znajd\u017A i zamie\u0144"); findReplace.setPreferredSize(new Dimension(136, 20)); findReplace.setToolTipText("Kliknij aby wyszukaæ i zamieniæ ³añcuch znaków w plikach"); // Klikniêcie "znajdŸ i zamieñ" findReplace.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Wyczyszczenie komponentu textArea results.setText(""); // Przypisanie wartoœci podanych przez u¿ytkownika do zmiennych String catalogPath = directory.getText(); String format = fileFormat.getText(); String strToFind = findText.getText(); String strReplace = replaceText.getText(); File directory = new File(catalogPath); /* * Sprawdzenie czy wprowadzona œcie¿ka jest b³êdna lub czy nie * odnosi siê do katalogu (tylko do pliku) Jeœli tak wyœwietlony * zostanie komunikat o b³êdzie, zmienna logiczna przyjmie * wartoœæ false, czyli nie jest spe³niony jeden z warunków * dzia³ania programu. W przeciwnym wypadku warunki s¹ spe³nione * i zmienna logiczna przyjmuje wartoœæ true */ if (!(directory.exists() && directory.isDirectory())) { new ErrorWindow("Podany katalog nie istnieje"); run[0] = false; } else run[0] = true; /* * Sprawdzenie czy nie wprowadzono formatu pliku oraz czy * spe³niony zosta³ wczeœniejszy warunek. Jeœli jest to * spe³nione pojawia siê komunikat o b³êdzie zmienna logiczna = * false W przeciwnym wypaku run = true */ if (format.equals("") && run[0]) { new ErrorWindow("Nie podano rozszerzenia pliku"); run[1] = false; } else run[1] = true; /* * Sprawdzenie czy nie wprowadzono ³añcucha znaków do wyszukania * oraz czy spe³nione zosta³y wczeœniejsze warunki. Jeœli jest * to spe³nione pojawia siê komunikat o b³êdzie zmienna logiczna * = false W przeciwnym wypaku run = true */ if (strToFind.equals("") && run[0] && run[1]) { new ErrorWindow("Nie podano ³añcucha znaków do wyszukania"); run[2] = false; } else run[2] = true; /* * Sprawdzenie czy nie wprowadzono ³añcucha znaków do podmiany * oraz czy spe³nione zosta³y wczeœniejsze warunki. Jeœli jest * to spe³nione pojawia siê komunikat o b³êdzie zmienna logiczna * = false W przeciwnym wypaku run = true Pojawia siê okno * prosz¹ce u¿ytkownika o decyzjê czy zast¹piæ ³añcuch pustymi * znakami */ if (strReplace.equals("") && run[0] && run[1] && run[2]) { qw = new QuestionWindow( "Nie podano ³añcucha zastêpuj¹cego\n³añcuch wyszukany w plikach zostanie\nzast¹piony pustymi znakami.\nKontynuowaæ?"); if (qw.getChoice() == JOptionPane.YES_OPTION) run[3] = true; else run[3] = false; } else run[3] = true; /* * Jeœli wszystkie warunki s¹ spe³nione rozpoczyna siê operacja * na plikach */ if (run[0] && run[1] && run[2] && run[3]) { fr = new Findreplace(directory, format, strToFind, strReplace); // Drukowanie wyników printResult(fr.getResults(), results); } } }); GridBagConstraints gbc_findReplace = new GridBagConstraints(); gbc_findReplace.insets = new Insets(0, 0, 5, 5); gbc_findReplace.gridx = 1; gbc_findReplace.gridy = 5; contentPane.add(findReplace, gbc_findReplace); results = new JTextArea(); results.setToolTipText("Lista plik\u00F3w, kt\u00F3re zosta\u0142y przetworzone"); results.setFont(new Font("Tahoma", Font.PLAIN, 13)); results.setEditable(false); results.setForeground(Color.DARK_GRAY); popup2.disableItem("Cut"); popup2.disableItem("Paste"); lblZnalezionePlikiO = new JLabel("Pliki poddane operacji:"); GridBagConstraints gbc_lblZnalezionePlikiO = new GridBagConstraints(); gbc_lblZnalezionePlikiO.anchor = GridBagConstraints.SOUTH; gbc_lblZnalezionePlikiO.insets = new Insets(0, 0, 5, 5); gbc_lblZnalezionePlikiO.gridx = 1; gbc_lblZnalezionePlikiO.gridy = 6; contentPane.add(lblZnalezionePlikiO, gbc_lblZnalezionePlikiO); yellowLoupe = new JLabel(""); yellowLoupe.setIcon(pic); GridBagConstraints gbc_lblNewLabel = new GridBagConstraints(); gbc_lblNewLabel.anchor = GridBagConstraints.EAST; gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5); gbc_lblNewLabel.gridx = 0; gbc_lblNewLabel.gridy = 7; contentPane.add(yellowLoupe, gbc_lblNewLabel); results.add(popup2.getPopupMenu()); results.setComponentPopupMenu(popup2.getPopupMenu()); JScrollPane scroll = new JScrollPane(results); GridBagConstraints scrollConstrains = new GridBagConstraints(); scrollConstrains.insets = new Insets(0, 0, 5, 5); scrollConstrains.fill = GridBagConstraints.BOTH; scrollConstrains.gridx = 1; scrollConstrains.gridy = 7; scrollConstrains.gridwidth = 1; contentPane.add(scroll, scrollConstrains); lblpiotrBartkiewicz = new JLabel("@Piotr Bartkiewicz"); GridBagConstraints gbc_lblpiotrBartkiewicz = new GridBagConstraints(); gbc_lblpiotrBartkiewicz.anchor = GridBagConstraints.SOUTHEAST; gbc_lblpiotrBartkiewicz.gridx = 2; gbc_lblpiotrBartkiewicz.gridy = 8; contentPane.add(lblpiotrBartkiewicz, gbc_lblpiotrBartkiewicz); }
public boolean updateEvent( Part filepart, String title, String description, String location, String startdate, String enddate, int points, int theme, int id) throws IOException { InputStream inputStream = null; int length = 0; String type = null; if (filepart != null) { // prints out some information for debugging length = (int) filepart.getSize(); type = filepart.getContentType(); // obtains input stream of the upload file inputStream = filepart.getInputStream(); } Connection con = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql://160.153.16.42:3306/Enterprise_Gym", user, pass); if (inputStream != null && length != 0) { PreparedStatement ps = null; String sqlOption2 = "UPDATE event SET title=?,description=?,date=?,end_date=?,location=?,points=?,theme_idtheme=?,image=?,image_length=?,image_type=? WHERE idevent=?"; ps = con.prepareStatement(sqlOption2); ps.setString(1, title); ps.setString(2, description); // fetches input stream of the upload file for the blob column ps.setString(3, startdate); ps.setString(4, enddate); ps.setString(5, location); ps.setInt(6, points); ps.setInt(7, theme); ps.setBlob(8, inputStream); ps.setInt(9, length); ps.setString(10, type); ps.setInt(11, id); ps.executeUpdate(); return true; } else { PreparedStatement ps = null; String sqlOption2 = "UPDATE event SET title=?,description=?,date=?,end_date=?,location=?,points=?,theme_idtheme=? WHERE idevent=?"; ps = con.prepareStatement(sqlOption2); ps.setString(1, title); ps.setString(2, description); // fetches input stream of the upload file for the blob column ps.setString(3, startdate); ps.setString(4, enddate); ps.setString(5, location); ps.setInt(6, points); ps.setInt(7, theme); ps.setInt(8, id); ps.executeUpdate(); return true; } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) { System.out.println("expection thrown"); System.out.println("false, exception"); e.printStackTrace(); return false; } }
public boolean awardPoints(int userID, int eventID) { Connection con = null; int theme = 0; int points = 0; System.out.println(userID + "User id Event id:" + eventID); String AwardPoints = ""; String SetAttended = ""; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql://160.153.16.42:3306/Enterprise_Gym", user, pass); PreparedStatement ps = null; PreparedStatement awardPoints = null; PreparedStatement getThemePoints = null; PreparedStatement setAttended = null; String GetThemePoints = "SELECT e.theme_idtheme, e.points FROM event e WHERE e.idevent = " + eventID; ResultSet rs = null; getThemePoints = con.prepareStatement(GetThemePoints); rs = getThemePoints.executeQuery(); rs.next(); theme = rs.getInt("theme_idtheme"); points = rs.getInt("points"); if (theme == 1) { AwardPoints = "UPDATE user u SET u.action_points = u.action_points + " + points + " WHERE u.iduser = "******"UPDATE user u SET u.practice_points = u.practice_points + " + points + " WHERE u.iduser = "******"UPDATE user u SET u.theory_points = u.theory_points + " + points + " WHERE u.iduser = "******"UPDATE user u SET u.virtual_points = u.virtual_points + " + points + " WHERE u.iduser = "******"UPDATE user u SET u.project_points = u.project_points + " + points + " WHERE u.iduser = "******"UPDATE event_has_user e SET e.attended = 1 WHERE e.user_iduser = "******"expection thrown"); System.out.println("false, exception"); e.printStackTrace(); return false; } }
/** Constructor to create the frame and its components */ public CoreyTextEditor() { // Create a scroll pane area.setFont(new Font("Monospaced", Font.PLAIN, 12)); JScrollPane scroll = new JScrollPane( area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); add(scroll, BorderLayout.CENTER); // Adds the system default look and feel try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) { e.printStackTrace(); } // Create a menu bar JMenuBar JMB = new JMenuBar(); setJMenuBar(JMB); JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); JMB.add(file); JMB.add(edit); // Finishing our menu bar file.add(New); file.add(Open); file.add(Save); file.add(SaveAs); file.addSeparator(); file.add(Quit); edit.add(Cut); edit.add(Copy); edit.add(Paste); edit.getItem(0).setText("Cut"); edit.getItem(0).setIcon(new ImageIcon("cut.gif")); edit.getItem(1).setText("Copy"); edit.getItem(1).setIcon(new ImageIcon("copy.gif")); edit.getItem(2).setText("Paste"); edit.getItem(2).setIcon(new ImageIcon("paste.gif")); // Time to make a toolbar! JToolBar tool = new JToolBar(); add(tool, BorderLayout.NORTH); tool.add(New); tool.add(Open); tool.add(Save); tool.addSeparator(); JButton cut = tool.add(Cut); JButton cop = tool.add(Copy); JButton pas = tool.add(Paste); cut.setText(null); cut.setIcon(new ImageIcon("cut.gif")); cop.setText(null); cop.setIcon(new ImageIcon("copy.gif")); pas.setText(null); pas.setIcon(new ImageIcon("paste.gif")); Save.setEnabled(false); SaveAs.setEnabled(false); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); pack(); /* KeyListener to change Save and SaveAs */ KeyListener k1 = new KeyAdapter() { public void keyPressed(KeyEvent e) { changed = true; Save.setEnabled(true); SaveAs.setEnabled(true); } }; area.addKeyListener(k1); setTitle(currentFile + " - CoreyTextEditor"); setVisible(true); }
// private c'tor 'hides' the public default one. CouponSystem is a singleton private CouponSystemJFrame() { // load sys params from properties file Utils.logMessage(this, Severity.INFO, "Coupon system created."); // NOT IN USE in a web-coupon system. ( see method doc ) // Utils.sysparam already set by a LoaderServlet // // Utils.loadSystemParameters(); sysParams = Utils.getSystemParameters(); _systemName = sysParams.get("SYSTEM_NAME"); _adminHash = sysParams.get("ADMIN_HASH"); _lookAndFeelTemplate = sysParams.get("LOOK_AND_FEEL_TEMPLATE"); _threadEnabled = Boolean.parseBoolean(sysParams.get("THREAD_ENABLED")); _threadIntervalMinutes = Integer.parseInt(sysParams.get("THREAD_INTERVAL_MINUTES")); _loggingEnabled = Boolean.parseBoolean(sysParams.get("LOGGING_ENABLED")); Utils.setLoggingEnabled(_loggingEnabled); Utils.logMessage( this, Severity.DEBUG, "hashmap assigned to local vars, configuration applied."); setTitle("Coupon System : " + _systemName); setResizable(false); try { UIManager.setLookAndFeel(_lookAndFeelTemplate); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { Utils.logMessage(this, Severity.PANIC, "cannot load LookAndFeel template. exiting..."); e.printStackTrace(); // System.exit(0); } // load this JFrame only after initialization from properties file. this.setVisible(true); // Main app CANNOT be closed with 'x' , must press on the 'shutdown' // buttong for gracefull shutdown. setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setBounds(100, 100, 785, 380); contentPane = new JPanel(); contentPane.setLayout(null); setContentPane(contentPane); btnLogin = new JButton("Login"); btnLogin.addActionListener(this); btnLogin.setBounds(659, 253, 98, 79); contentPane.add(btnLogin); listSysParams = new JList<Entry<String, String>>(); listSysParams.setBorder(new LineBorder(new Color(0, 0, 0))); listSysParams.setFont(new Font("Consolas", Font.PLAIN, 14)); listSysParams.setEnabled(false); listSysParams.setBounds(20, 11, 737, 219); contentPane.add(listSysParams); // a model is needed for JTable DefaultListModel<Entry<String, String>> model = new DefaultListModel<Entry<String, String>>(); listSysParams.setModel(model); JPanel panelSystem = new JPanel(); panelSystem.setBorder(new LineBorder(new Color(0, 0, 0))); panelSystem.setLayout(null); panelSystem.setBounds(20, 253, 428, 79); contentPane.add(panelSystem); btnShutdown = new JButton("Shutdown system"); btnShutdown.setForeground(Color.RED); btnShutdown.setBounds(20, 36, 181, 23); panelSystem.add(btnShutdown); btnThread = new JButton("Stop cleaner thread"); btnThread.addActionListener(this); btnThread.setForeground(Color.RED); btnThread.setBounds(224, 36, 181, 23); panelSystem.add(btnThread); JLabel lblSys = new JLabel( "Coupon system running on : " + System.getProperty("os.name") + " / [version-" + System.getProperty("os.version") + "]."); lblSys.setBounds(20, 11, 369, 14); panelSystem.add(lblSys); btnShutdown.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { // calling for gracefull shutdown shutdown(); } }); // get a Set of Entries from all KVP in Map Set<Entry<String, String>> entries = sysParams.entrySet(); for (Entry<String, String> entry : entries) { model.addElement(entry); } // get/create the connection pool connPool = ConnPool.getInstance(); // pass it to DAO's createDAOs(connPool); if (_threadEnabled) { // start the daily cleaner thread startTimer(); } }
Calender() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { // TODO Auto-generated catch block e.printStackTrace(); } panel = new JPanel(); panel.setLayout(new MigLayout("", "2[]0[]0[]0[]0[]0[]0[]2", "")); month = new JComboBox<String>(months); year = new JComboBox<String>(years); daysNameButton = new JButton[7]; panel.add(month, "span 3"); panel.add(year, "span 4,wrap"); daysButton = new JButton[37]; setUndecorated(true); setBackground(Color.white); for (int i = 0; i < 7; i++) { daysNameButton[i] = new JButton(days[i]); daysNameButton[i].setMargin(new Insets(3, 3, 3, 3)); daysNameButton[i].setBorderPainted(false); daysNameButton[i].setContentAreaFilled(false); if (i == 6) panel.add(daysNameButton[i], "wrap"); else panel.add(daysNameButton[i]); } for (int i = 0; i < 37; i++) { daysButton[i] = new JButton("00"); daysButton[i].setMargin(new Insets(3, 3, 3, 3)); daysButton[i].setContentAreaFilled(false); daysButton[i].setBorderPainted(false); if (i % 7 == 6) panel.add(daysButton[i], "wrap"); else panel.add(daysButton[i]); } panel.setBackground(Color.white); panel.setBorder(BorderFactory.createLineBorder(Color.black, 2, true)); add(panel); // setPreferredSize(new Dimension(100, 100)); setDefaultCloseOperation(EXIT_ON_CLOSE); pack(); validate(); setVisible(true); month.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int m = month.getSelectedIndex() + 1; String y = (String) year.getSelectedItem(); Calendar cal = Calendar.getInstance(); String input_date = "01/" + m + "/" + y; SimpleDateFormat format1 = new SimpleDateFormat("dd/MM/yyyy"); try { Date dt1 = format1.parse(input_date); cal.setTime(dt1); System.out.println(cal.get(Calendar.DAY_OF_MONTH)); System.out.println(cal.get(Calendar.YEAR)); System.out.println(getDay(cal.get(Calendar.DAY_OF_WEEK))); int max = cal.getActualMaximum(Calendar.DAY_OF_MONTH); fillCal(getDay(cal.get(Calendar.DAY_OF_WEEK)), max); revalidate(); repaint(); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); this.year.setSelectedItem("" + year); this.month.setSelectedIndex(month); }