List of usage examples for java.awt.event WindowAdapter WindowAdapter
WindowAdapter
From source file:javaapplication3.SolidscapeDialog.java
public void SolidscapeDialogStart() { instance = new InstanceCall(); setTitle("Add Information about" + new File(BPath.getText()).getName()); hideErrorFields();/*w ww .ja va 2 s . c o m*/ Date date = Calendar.getInstance().getTime(); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); this.dateRunTxt.setText(sdf.format(date)); this.setLocationRelativeTo(null); //search database for buildName //File BPathfile = new File(BPath.getText().replace("\\", "\\\\")); setVisible(true); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { String ObjButtons[] = { "Yes", "No" }; int PromptResult = JOptionPane.showOptionDialog(null, "Save as an Open Build?", "Save", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, ObjButtons, ObjButtons[1]); if (PromptResult == JOptionPane.YES_OPTION) { gatherScrapThenExit(); PrinterBuild.selectAllFiles("Solidscape"); dispose(); } else { ResultSet r = SolidscapeMain.dba.searchPendingByBuildName(new File(BPath.getText()).getName()); try { while (r.next()) { SolidscapeMain.dba.updatePendingJobsBuildName(r.getString("buildName"), r.getString("fileName")); } } catch (SQLException ex) { Logger.getLogger(SolidscapeDialog.class.getName()).log(Level.SEVERE, null, ex); } ResultSet s = SolidscapeMain.dba .searchSolidscapeByBuildName(new File(BPath.getText()).getName()); try { while (s.next()) { SolidscapeMain.dba.deleteByBuildName(s.getString("buildName"), "solidscape"); } } catch (SQLException ex) { Logger.getLogger(SolidscapeDialog.class.getName()).log(Level.SEVERE, null, ex); } dispose(); } } }); }
From source file:net.sf.housekeeper.swing.MainFrame.java
/** * Initializes and packs a new main frame. *//*from w w w . ja v a2 s. c o m*/ public MainFrame() { super(); view = new JFrame(); initLookAndFeel(); final String version = ConfigurationManager.INSTANCE.getConfiguration() .getString(ConfigurationManager.HOUSEKEEPER_VERSION); view.setTitle("Housekeeper " + version); view.setJMenuBar(buildMenuBar()); view.getContentPane().add(buildComponents()); view.pack(); view.setLocationRelativeTo(null); //Use the controller for exiting the application view.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); view.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { exitApplication(); } }); }
From source file:NwFontChooserS.java
private void initAll() { getContentPane().setLayout(null);/*from w w w . ja va 2 s .c o m*/ setBounds(50, 50, 450, 450); addLists(); addButtons(); Sample.setBounds(10, 320, 415, 25); Sample.setForeground(Color.black); getContentPane().add(Sample); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); } }); }
From source file:GridsCanvas.java
Grids(String title, int w, int h, int rows, int cols) { setTitle(title);//from ww w . jav a2s . c o m // Now create a Canvas and add it to the Frame. GridsCanvas xyz = new GridsCanvas(w, h, rows, cols); add(xyz); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); dispose(); System.exit(0); } }); // Normal end ... pack it up! pack(); }
From source file:com.diversityarrays.kdxplore.vistool.VisToolbarFactory.java
static public VisToolToolBar create(final String title, final JComponent comp, final Closure<File> snapshotter, final VisToolDataProvider visToolDataProvider, boolean floatable, final String[] imageSuffixes) { Window window = GuiUtil.getOwnerWindow(comp); boolean anyButtons = false; final JCheckBox keepOnTop; if (window == null) { keepOnTop = null;/*from w w w.ja v a2 s . c o m*/ } else { anyButtons = true; keepOnTop = new JCheckBox(Msg.OPTION_KEEP_ON_TOP(), true); keepOnTop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { window.setAlwaysOnTop(keepOnTop.isSelected()); } }); window.setAlwaysOnTop(keepOnTop.isSelected()); // buttons.add(keepOnTop); final PropertyChangeListener alwaysOnTopListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { keepOnTop.setSelected(window.isAlwaysOnTop()); } }; window.addPropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener); window.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { window.removeWindowListener(this); window.removePropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener); } }); } final JButton cameraButton; if (snapshotter == null) { cameraButton = null; } else { Action cameraAction = new AbstractAction(Msg.ACTION_SNAPSHOT()) { @Override public void actionPerformed(ActionEvent e) { if (chooser == null) { chooser = new JFileChooser(); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (!f.isFile()) { return true; } String loname = f.getName().toLowerCase(); for (String sfx : imageSuffixes) { if (loname.endsWith(sfx)) { return true; } } return false; } @Override public String getDescription() { return Msg.DESC_IMAGE_FILE(); } }); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); } if (JFileChooser.APPROVE_OPTION == chooser.showSaveDialog(comp)) { File file = chooser.getSelectedFile(); snapshotter.execute(file); } } }; ImageIcon icon = loadIcon("camera-24.png"); //$NON-NLS-1$ if (icon != null) { cameraAction.putValue(Action.SMALL_ICON, icon); cameraAction.putValue(Action.NAME, null); } anyButtons = true; cameraButton = new JButton(cameraAction); } final JButton refreshButton; if (visToolDataProvider == null) { refreshButton = null; } else { anyButtons = true; refreshButton = new JButton(Msg.ACTION_REFRESH()); ImageIcon icon = loadIcon("refresh-24.png"); //$NON-NLS-1$ if (icon != null) { refreshButton.setIcon(icon); // don't remove the name } refreshButton.setForeground(Color.RED); refreshButton.setEnabled(false); refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (visToolDataProvider.refreshData()) { refreshButton.setEnabled(false); } } }); visToolDataProvider.addVisToolDataChangedListener(new VisToolDataChangedListener() { @Override public void visToolDataChanged(Object source) { refreshButton.setEnabled(true); } }); } VisToolToolBar toolBar = null; if (anyButtons) { toolBar = new VisToolToolBar(keepOnTop, cameraButton, refreshButton); toolBar.setFloatable(floatable); } return toolBar; }
From source file:PropertiesTest.java
public PropertiesFrame() { // get position, size, title from properties String userDir = System.getProperty("user.home"); File propertiesDir = new File(userDir, ".corejava"); if (!propertiesDir.exists()) propertiesDir.mkdir();//from ww w .j a v a 2 s .co m propertiesFile = new File(propertiesDir, "program.properties"); Properties defaultSettings = new Properties(); defaultSettings.put("left", "0"); defaultSettings.put("top", "0"); defaultSettings.put("width", "" + DEFAULT_WIDTH); defaultSettings.put("height", "" + DEFAULT_HEIGHT); defaultSettings.put("title", ""); settings = new Properties(defaultSettings); if (propertiesFile.exists()) try { FileInputStream in = new FileInputStream(propertiesFile); settings.load(in); } catch (IOException ex) { ex.printStackTrace(); } int left = Integer.parseInt(settings.getProperty("left")); int top = Integer.parseInt(settings.getProperty("top")); int width = Integer.parseInt(settings.getProperty("width")); int height = Integer.parseInt(settings.getProperty("height")); setBounds(left, top, width, height); // if no title given, ask user String title = settings.getProperty("title"); if (title.equals("")) title = JOptionPane.showInputDialog("Please supply a frame title:"); if (title == null) title = ""; setTitle(title); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { settings.put("left", "" + getX()); settings.put("top", "" + getY()); settings.put("width", "" + getWidth()); settings.put("height", "" + getHeight()); settings.put("title", getTitle()); try { FileOutputStream out = new FileOutputStream(propertiesFile); settings.store(out, "Program Properties"); } catch (IOException ex) { ex.printStackTrace(); } System.exit(0); } }); }
From source file:LDAPTest.java
public LDAPFrame() { setTitle("LDAPTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel northPanel = new JPanel(); northPanel.setLayout(new java.awt.GridLayout(1, 2, 3, 1)); northPanel.add(new JLabel("uid", SwingConstants.RIGHT)); uidField = new JTextField(); northPanel.add(uidField);/*from w ww . j a va 2s. c o m*/ add(northPanel, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(); add(buttonPanel, BorderLayout.SOUTH); findButton = new JButton("Find"); findButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { findEntry(); } }); buttonPanel.add(findButton); saveButton = new JButton("Save"); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { saveEntry(); } }); buttonPanel.add(saveButton); deleteButton = new JButton("Delete"); deleteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { deleteEntry(); } }); buttonPanel.add(deleteButton); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { try { if (context != null) context.close(); } catch (NamingException e) { e.printStackTrace(); } } }); }
From source file:com.sec.ose.osi.ui.frm.main.manage.dialog.JDlgProjectAdd.java
/** * This is the default constructor/* ww w . java 2 s . c o m*/ */ public JDlgProjectAdd(JFrame frame) { super(frame, "Add Project", true); this.setMinimumSize(new Dimension(600, 300)); this.setResizable(true); this.setIconImage(new ImageIcon(WindowUtil.class.getResource("icon.png")).getImage()); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { projectListTableModel.recoveySelectedIndex(); } }); initialize(); }
From source file:com.isencia.passerelle.hmi.specific.HMITest.java
/** */* w ww .ja v a 2s. c om*/ */ @Override protected Component initUI(final String title) { frame = new JFrame(title); frame.setLocation(600, 300); frame.setSize(500, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { logger.info("HMITest closing..."); } }); frame.setJMenuBar(createDefaultMenu()); frame.show(); return frame; }
From source file:com.oracle.tutorial.jdbc.CoffeesFrame.java
public CoffeesFrame(JDBCTutorialUtilities settingsArg) throws SQLException { super("The Coffee Break: COFFEES Table"); // Set window title this.settings = settingsArg; connection = settings.getConnection(); // Close connections exit the application when the user // closes the window addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { try { connection.close();/*from w w w . j a va 2 s . com*/ } catch (SQLException sqle) { JDBCTutorialUtilities.printSQLException(sqle); } System.exit(0); } }); // Initialize and lay out window controls CachedRowSet myCachedRowSet = getContentsOfCoffeesTable(); myCoffeesTableModel = new CoffeesTableModel(myCachedRowSet); myCoffeesTableModel.addEventHandlersToRowSet(this); table = new JTable(); // Displays the table table.setModel(myCoffeesTableModel); label_COF_NAME = new JLabel(); label_SUP_ID = new JLabel(); label_PRICE = new JLabel(); label_SALES = new JLabel(); label_TOTAL = new JLabel(); textField_COF_NAME = new JTextField(10); textField_SUP_ID = new JTextField(10); textField_PRICE = new JTextField(10); textField_SALES = new JTextField(10); textField_TOTAL = new JTextField(10); button_ADD_ROW = new JButton(); button_UPDATE_DATABASE = new JButton(); button_DISCARD_CHANGES = new JButton(); label_COF_NAME.setText("Coffee Name:"); label_SUP_ID.setText("Supplier ID:"); label_PRICE.setText("Price:"); label_SALES.setText("Sales:"); label_TOTAL.setText("Total Sales:"); textField_COF_NAME.setText("Enter new coffee name"); textField_SUP_ID.setText("101"); textField_PRICE.setText("0"); textField_SALES.setText("0"); textField_TOTAL.setText("0"); button_ADD_ROW.setText("Add row to table"); button_UPDATE_DATABASE.setText("Update database"); button_DISCARD_CHANGES.setText("Discard changes"); // Place the components within the container contentPane; use GridBagLayout // as the layout. Container contentPane = getContentPane(); contentPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); contentPane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; c.weightx = 0.5; c.weighty = 1.0; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; contentPane.add(new JScrollPane(table), c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 1; c.gridwidth = 1; contentPane.add(label_COF_NAME, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 1; c.gridwidth = 1; contentPane.add(textField_COF_NAME, c); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.25; c.weighty = 0; c.anchor = GridBagConstraints.LINE_START; c.gridx = 0; c.gridy = 2; c.gridwidth = 1; contentPane.add(label_SUP_ID, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 2; c.gridwidth = 1; contentPane.add(textField_SUP_ID, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 3; c.gridwidth = 1; contentPane.add(label_PRICE, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 3; c.gridwidth = 1; contentPane.add(textField_PRICE, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 4; c.gridwidth = 1; contentPane.add(label_SALES, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 4; c.gridwidth = 1; contentPane.add(textField_SALES, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.25; c.weighty = 0; c.gridx = 0; c.gridy = 5; c.gridwidth = 1; contentPane.add(label_TOTAL, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.75; c.weighty = 0; c.gridx = 1; c.gridy = 5; c.gridwidth = 1; contentPane.add(textField_TOTAL, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.5; c.weighty = 0; c.gridx = 0; c.gridy = 6; c.gridwidth = 1; contentPane.add(button_ADD_ROW, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.5; c.weighty = 0; c.gridx = 1; c.gridy = 6; c.gridwidth = 1; contentPane.add(button_UPDATE_DATABASE, c); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.5; c.weighty = 0; c.gridx = 0; c.gridy = 7; c.gridwidth = 1; contentPane.add(button_DISCARD_CHANGES, c); // Add listeners for the buttons in the application button_ADD_ROW.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(CoffeesFrame.this, new String[] { "Adding the following row:", "Coffee name: [" + textField_COF_NAME.getText() + "]", "Supplier ID: [" + textField_SUP_ID.getText() + "]", "Price: [" + textField_PRICE.getText() + "]", "Sales: [" + textField_SALES.getText() + "]", "Total: [" + textField_TOTAL.getText() + "]" }); try { myCoffeesTableModel.insertRow(textField_COF_NAME.getText(), Integer.parseInt(textField_SUP_ID.getText().trim()), Float.parseFloat(textField_PRICE.getText().trim()), Integer.parseInt(textField_SALES.getText().trim()), Integer.parseInt(textField_TOTAL.getText().trim())); } catch (SQLException sqle) { displaySQLExceptionDialog(sqle); } } }); button_UPDATE_DATABASE.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { myCoffeesTableModel.coffeesRowSet.acceptChanges(); } catch (SQLException sqle) { displaySQLExceptionDialog(sqle); // Now revert back changes try { createNewTableModel(); } catch (SQLException sqle2) { displaySQLExceptionDialog(sqle2); } } } }); button_DISCARD_CHANGES.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { createNewTableModel(); } catch (SQLException sqle) { displaySQLExceptionDialog(sqle); } } }); }