Search in sources :

Example 1 with Button

use of java.awt.Button in project voltdb by VoltDB.

the class ZaurusEditor method actionPerformed.

/**
     *  <code>actionPerformed</code> method is the main entry point
     * which interprets the buttons and initiates the actions.
     *
     * @param e an <code>ActionEvent</code> value is been sent to ZaurusEditor as ActionListener
     *
     * <p>The possible events are:<ul> <li>Buttons on the <b>search
     * panel:</b> <dl><dt>Search Row<dd> Starts the search of rows in
     * the choosen table with the given search words and search
     * options. Without any search words, all rows will be found.<br>
     * If no row meets the criteria, there will be a message in the
     * status line.  <dt>New Row<dd> An empty input panel for the
     * choosen table is given. Any search words are
     * ignored.</dl><li>Buttons on the <b>edit panel:</b><br>Any
     * changes to field values on this panel will be updated to the
     * table when the actual row is left, i. e. when pressing one of
     * the buttons 'Prev', 'Next' or
     * 'Search'. <br><dl><dt>Cancel<dd>Any changes to field contents
     * are canceled and reset to the previous values.<dt>Prev<dd>Show
     * the previous row which meets the search
     * criteria.<dt>Next<dd>Show the next row which meets the search
     * criteria.<dt>Delete<dd>This button has to be clicked twice and
     * the shown row will be deleted from the table<dt>Search<dd>With
     * this button a new search is initiated. Any changes made to
     * field contents are saved</dl><li>Buttons on the <b>insert
     * panel:</b><dl><dt>Cancel Insert<dd>After beginning to fill a
     * new row, the insert may be cancelled. The search panel will be
     * shown next.<dt>New Insert<dd>The new row is inserted into the
     * table and a new empty insert panel is shown.<dt>New
     * Search<dd>The new row is inserted into the table and the search
     * panel is shown again.</ul>
     */
public void actionPerformed(ActionEvent e) {
    Button button = (Button) e.getSource();
    if (button == bSearchRow) {
        this.resetLastButtonDelete();
        // System.out.println("pressed search");
        aktHoldNr = getChoosenTableIndex();
        // search all rows
        int numberOfRows = ((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).searchRows(this.getWords(), (gAllWords.getSelectedCheckbox().getLabel().equals("all")), (gIgnoreCase.getSelectedCheckbox().getLabel().equals("yes")), (gNoMatchWhole.getSelectedCheckbox().getLabel().equals("no")));
        String tableName = (String) vHoldTableNames.elementAt(aktHoldNr);
        if (numberOfRows > 0) {
            lForm.show(pForm, tableName);
            lButton.show(pButton, "edit");
            bPrev.setEnabled(false);
            // if there is more than one row, enable the next button
            bNext.setEnabled(numberOfRows != 1);
            ZaurusEditor.printStatus("found " + numberOfRows + " rows in table " + tableName);
        } else if (numberOfRows == 0) {
            ZaurusEditor.printStatus("no rows found in table " + tableName);
        // numberOfRows could be -1 as well, if an SQL exception was encountered
        }
    // end of if (numberOfRows > 0)
    } else if ((button == bNewRow)) {
        // System.out.println("pressed new");
        aktHoldNr = getChoosenTableIndex();
        lForm.show(pForm, (String) vHoldTableNames.elementAt(aktHoldNr));
        lButton.show(pButton, "insert");
        ((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).insertNewRow();
    } else if (button == bNewInsert) {
        this.resetLastButtonDelete();
        // new search in edit row
        if (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).saveNewRow()) {
            // System.out.println("pressed new insert");
            ((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).insertNewRow();
        }
    } else if (button == bNewSearch) {
        this.resetLastButtonDelete();
        // new search in edit row
        if (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).saveChanges()) {
            // System.out.println("pressed new search");
            lForm.show(pForm, "search");
            lButton.show(pButton, "search");
        }
    } else if (button == bNewSearch1) {
        this.resetLastButtonDelete();
        // new search in insert row, succeeds if the saving is successfull
        if (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).saveNewRow()) {
            // System.out.println("pressed new search");
            lForm.show(pForm, "search");
            lButton.show(pButton, "search");
        }
    } else if ((button == bNext)) {
        this.resetLastButtonDelete();
        ZaurusEditor.clearStatus();
        if (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).saveChanges()) {
            bPrev.setEnabled(true);
            if (!((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).nextRow()) {
                bNext.setEnabled(false);
            }
        }
    } else if ((button == bPrev)) {
        this.resetLastButtonDelete();
        ZaurusEditor.clearStatus();
        if (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).saveChanges()) {
            bNext.setEnabled(true);
            if (!((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).prevRow()) {
                bPrev.setEnabled(false);
            }
        }
    } else if ((button == bCancel1)) {
        // cancel in edit panel
        this.resetLastButtonDelete();
        ((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).cancelChanges();
    } else if ((button == bCancel2)) {
        this.resetLastButtonDelete();
        // cancel in insert panel, just show the search panel again
        lForm.show(pForm, "search");
        lButton.show(pButton, "search");
    } else if (button == bDelete) {
        if (lastButtonDelete) {
            // delete and determine follow up actions, see comment in ZaurusTableForm.deleteRow()
            switch(((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).deleteRow()) {
                case 1:
                    lForm.show(pForm, "search");
                    lButton.show(pButton, "search");
                    break;
                case 2:
                    bPrev.setEnabled(false);
                    break;
                case 3:
                    bNext.setEnabled(false);
                    break;
                default:
                    break;
            }
            // end of switch (((ZaurusTableForm) vHoldForms.elementAt(aktHoldNr)).deleteRow())
            lastButtonDelete = false;
        } else {
            ZaurusEditor.printStatus("Press 'Delete' a second time to delete row.");
            lastButtonDelete = true;
        }
    // end of if (lastButtonDelete)
    }
// end of if (button == Rest)
}
Also used : Button(java.awt.Button)

Example 2 with Button

use of java.awt.Button in project voltdb by VoltDB.

the class ZaurusDatabaseManager method initGUI.

/**
     * Method declaration
     *
     */
private void initGUI() {
    Panel pQuery = new Panel();
    Panel pCommand = new Panel();
    // define a Panel pCard which takes four different cards/views:
    // tree of tables, command SQL text area, result window and an editor/input form
    pCard = new Panel();
    layoutCard = new CardLayout(2, 2);
    pCard.setLayout(layoutCard);
    // four buttons at the top to quickly switch between the four views
    butTree = new Button("Tree");
    butCommand = new Button("Command");
    butResult = new Button("Result");
    butEditor = new Button("Editor");
    butTree.addActionListener(this);
    butCommand.addActionListener(this);
    butResult.addActionListener(this);
    butEditor.addActionListener(this);
    Panel pButtons = new Panel();
    pButtons.setLayout(new GridLayout(1, 4, 8, 8));
    pButtons.add(butTree);
    pButtons.add(butCommand);
    pButtons.add(butResult);
    pButtons.add(butEditor);
    pResult = new Panel();
    pQuery.setLayout(new BorderLayout());
    pCommand.setLayout(new BorderLayout());
    pResult.setLayout(new BorderLayout());
    Font fFont = new Font("Dialog", Font.PLAIN, 12);
    txtCommand = new TextArea(5, 40);
    txtCommand.addKeyListener(this);
    txtResult = new TextArea(20, 40);
    txtCommand.setFont(fFont);
    txtResult.setFont(new Font("Courier", Font.PLAIN, 12));
    butExecute = new Button("Execute");
    butExecute.addActionListener(this);
    pCommand.add("South", butExecute);
    pCommand.add("Center", txtCommand);
    gResult = new Grid();
    setLayout(new BorderLayout());
    pResult.add("Center", gResult);
    tTree = new Tree();
    tTree.setMinimumSize(new Dimension(200, 100));
    gResult.setMinimumSize(new Dimension(200, 300));
    eEditor = new ZaurusEditor();
    pCard.add("tree", tTree);
    pCard.add("command", pCommand);
    pCard.add("result", pResult);
    pCard.add("editor", eEditor);
    fMain.add("Center", pCard);
    fMain.add("North", pButtons);
    doLayout();
    fMain.pack();
}
Also used : Panel(java.awt.Panel) CardLayout(java.awt.CardLayout) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) Button(java.awt.Button) TextArea(java.awt.TextArea) Dimension(java.awt.Dimension) Font(java.awt.Font)

Example 3 with Button

use of java.awt.Button in project jdk8u_jdk by JetBrains.

the class MultimonFullscreenTest method actionPerformed.

public void actionPerformed(ActionEvent ae) {
    GraphicsDevice dev = deviceMap.get(ae.getSource());
    System.err.println("Setting FS on device:" + dev);
    final Window fsWindow;
    if (useFSWindow) {
        fsWindow = new Window(this, dev.getDefaultConfiguration()) {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        };
    } else if (useFSDialog) {
        fsWindow = new Dialog((Frame) null, "FS Dialog on device " + dev, false, dev.getDefaultConfiguration());
        fsWindow.add(new Component() {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        });
    } else {
        fsWindow = new Frame("FS Frame on device " + dev, dev.getDefaultConfiguration()) {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        };
        if (addHWChildren) {
            fsWindow.add("South", new Panel() {

                public void paint(Graphics g) {
                    g.setColor(Color.red);
                    g.fillRect(0, 0, getWidth(), getHeight());
                }
            });
            fsWindow.add("North", new Button("Button, sucka!"));
        }
    }
    fsWindow.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                done = true;
                fsWindow.dispose();
            }
        }
    });
    fsWindow.addWindowListener(new WindowHandler());
    dev.setFullScreenWindow(fsWindow);
    if (dmChange && dev.isDisplayChangeSupported()) {
        DisplayMode[] dms = dev.getDisplayModes();
        DisplayMode myDM = null;
        for (DisplayMode dm : dms) {
            if (dm.getWidth() == 800 && dm.getHeight() == 600 && (dm.getBitDepth() >= 16 || dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) && (dm.getRefreshRate() >= 60 || dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN)) {
                myDM = dm;
                break;
            }
        }
        if (myDM != null) {
            System.err.println("Setting Display Mode: " + myDM.getWidth() + "x" + myDM.getHeight() + "x" + myDM.getBitDepth() + "@" + myDM.getRefreshRate() + "Hz on device" + dev);
            dev.setDisplayMode(myDM);
        } else {
            System.err.println("Can't find suitable display mode.");
        }
    }
    done = false;
    if (runRenderLoop) {
        Thread updateThread = new Thread(new Runnable() {

            public void run() {
                BufferStrategy bs = null;
                if (useBS) {
                    fsWindow.createBufferStrategy(2);
                    bs = fsWindow.getBufferStrategy();
                }
                while (!done) {
                    if (useBS) {
                        Graphics g = bs.getDrawGraphics();
                        renderDimensions(g, fsWindow.getBounds(), fsWindow.getGraphicsConfiguration());
                        bs.show();
                    } else {
                        fsWindow.repaint();
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
                if (useBS) {
                    bs.dispose();
                }
            }
        });
        updateThread.start();
    }
}
Also used : Window(java.awt.Window) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) BufferStrategy(java.awt.image.BufferStrategy) MouseAdapter(java.awt.event.MouseAdapter) Graphics(java.awt.Graphics) DisplayMode(java.awt.DisplayMode) Panel(java.awt.Panel) GraphicsDevice(java.awt.GraphicsDevice) Button(java.awt.Button) Dialog(java.awt.Dialog) Component(java.awt.Component)

Example 4 with Button

use of java.awt.Button in project jdk8u_jdk by JetBrains.

the class DimensionEncapsulation method run.

@Override
public void run() {
    runTest(new Panel());
    runTest(new Button());
    runTest(new Checkbox());
    runTest(new Canvas());
    runTest(new Choice());
    runTest(new Label());
    runTest(new Scrollbar());
    runTest(new TextArea());
    runTest(new TextField());
    runTest(new Dialog(new JFrame()));
    runTest(new Frame());
    runTest(new Window(new JFrame()));
    runTest(new FileDialog(new JFrame()));
    runTest(new List());
    runTest(new ScrollPane());
    runTest(new JFrame());
    runTest(new JDialog(new JFrame()));
    runTest(new JWindow(new JFrame()));
    runTest(new JLabel("hi"));
    runTest(new JMenu());
    runTest(new JTree());
    runTest(new JTable());
    runTest(new JMenuItem());
    runTest(new JCheckBoxMenuItem());
    runTest(new JToggleButton());
    runTest(new JSpinner());
    runTest(new JSlider());
    runTest(Box.createVerticalBox());
    runTest(Box.createHorizontalBox());
    runTest(new JTextField());
    runTest(new JTextArea());
    runTest(new JTextPane());
    runTest(new JPasswordField());
    runTest(new JFormattedTextField());
    runTest(new JEditorPane());
    runTest(new JButton());
    runTest(new JColorChooser());
    runTest(new JFileChooser());
    runTest(new JCheckBox());
    runTest(new JInternalFrame());
    runTest(new JDesktopPane());
    runTest(new JTableHeader());
    runTest(new JLayeredPane());
    runTest(new JRootPane());
    runTest(new JMenuBar());
    runTest(new JOptionPane());
    runTest(new JRadioButton());
    runTest(new JRadioButtonMenuItem());
    runTest(new JPopupMenu());
    //runTest(new JScrollBar()); --> don't test defines max and min in
    // terms of preferred
    runTest(new JScrollPane());
    runTest(new JViewport());
    runTest(new JSplitPane());
    runTest(new JTabbedPane());
    runTest(new JToolBar());
    runTest(new JSeparator());
    runTest(new JProgressBar());
    if (!failures.isEmpty()) {
        System.out.println("These classes failed");
        for (final Component failure : failures) {
            System.out.println(failure.getClass());
        }
        throw new RuntimeException("Test failed");
    }
}
Also used : JDesktopPane(javax.swing.JDesktopPane) Choice(java.awt.Choice) JTextArea(javax.swing.JTextArea) TextArea(java.awt.TextArea) JTextArea(javax.swing.JTextArea) Label(java.awt.Label) JLabel(javax.swing.JLabel) JTableHeader(javax.swing.table.JTableHeader) JToggleButton(javax.swing.JToggleButton) JToggleButton(javax.swing.JToggleButton) Button(java.awt.Button) JRadioButton(javax.swing.JRadioButton) JButton(javax.swing.JButton) JFrame(javax.swing.JFrame) Checkbox(java.awt.Checkbox) JDialog(javax.swing.JDialog) FileDialog(java.awt.FileDialog) Dialog(java.awt.Dialog) JTextField(javax.swing.JTextField) TextField(java.awt.TextField) JFormattedTextField(javax.swing.JFormattedTextField) JSlider(javax.swing.JSlider) ArrayList(java.util.ArrayList) List(java.awt.List) Canvas(java.awt.Canvas) JWindow(javax.swing.JWindow) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JOptionPane(javax.swing.JOptionPane) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JCheckBox(javax.swing.JCheckBox) JTree(javax.swing.JTree) JFileChooser(javax.swing.JFileChooser) JPasswordField(javax.swing.JPasswordField) ScrollPane(java.awt.ScrollPane) JScrollPane(javax.swing.JScrollPane) JTable(javax.swing.JTable) JSpinner(javax.swing.JSpinner) JSplitPane(javax.swing.JSplitPane) JColorChooser(javax.swing.JColorChooser) JInternalFrame(javax.swing.JInternalFrame) JDialog(javax.swing.JDialog) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) JInternalFrame(javax.swing.JInternalFrame) JRadioButton(javax.swing.JRadioButton) JLayeredPane(javax.swing.JLayeredPane) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) JTextField(javax.swing.JTextField) JSeparator(javax.swing.JSeparator) JTextPane(javax.swing.JTextPane) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) Scrollbar(java.awt.Scrollbar) Window(java.awt.Window) JWindow(javax.swing.JWindow) JScrollPane(javax.swing.JScrollPane) JViewport(javax.swing.JViewport) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) JToolBar(javax.swing.JToolBar) JPopupMenu(javax.swing.JPopupMenu) Panel(java.awt.Panel) JEditorPane(javax.swing.JEditorPane) JRootPane(javax.swing.JRootPane) FileDialog(java.awt.FileDialog) JMenu(javax.swing.JMenu) JMenuBar(javax.swing.JMenuBar)

Example 5 with Button

use of java.awt.Button in project jdk8u_jdk by JetBrains.

the class ContainerAIOOBE method main.

public static void main(final String[] args) throws Exception {
    ZContainer z = new ZContainer();
    z.add(new Button());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(z);
    oos.flush();
    oos.close();
    byte[] array = baos.toByteArray();
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(array));
    // Reading the object must not throw ArrayIndexOutOfBoundsException
    ZContainer zz = (ZContainer) ois.readObject();
    if (zz.getComponentCount() != 1) {
        throw new Exception("deserialized object must have 1 component");
    }
    if (!(zz.getComponent(0) instanceof Button)) {
        throw new Exception("deserialized object must contain Button component");
    }
    if (zz.getComponents().length != 0) {
        throw new Exception("deserialized object returns non-empty array");
    }
    System.out.println("Test passed");
}
Also used : Button(java.awt.Button) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Button (java.awt.Button)47 Panel (java.awt.Panel)25 Label (java.awt.Label)17 TextField (java.awt.TextField)13 GridBagConstraints (java.awt.GridBagConstraints)12 GridBagLayout (java.awt.GridBagLayout)12 Frame (java.awt.Frame)10 BorderLayout (java.awt.BorderLayout)9 ActionEvent (java.awt.event.ActionEvent)9 ActionListener (java.awt.event.ActionListener)9 GridLayout (java.awt.GridLayout)8 JPanel (javax.swing.JPanel)8 Component (java.awt.Component)7 Dimension (java.awt.Dimension)7 FlowLayout (java.awt.FlowLayout)7 Font (java.awt.Font)7 Choice (java.awt.Choice)6 Point (java.awt.Point)6 Insets (java.awt.Insets)5 MouseEvent (java.awt.event.MouseEvent)5