Example usage for java.awt.event WindowAdapter WindowAdapter

List of usage examples for java.awt.event WindowAdapter WindowAdapter

Introduction

In this page you can find the example usage for java.awt.event WindowAdapter WindowAdapter.

Prototype

WindowAdapter

Source Link

Usage

From source file:com.anji.floatingeye.FloatingEyeDisplay.java

private void init(Java2DSurface surface, FloatingEye anEye) {
    eye = anEye;// w  w  w. java2s. c  om

    // this frame has 3 sections - status, surface canvas, and eye canvas
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            setVisible(false);
            dispose();
        }
    });
    GridLayout mainLayout = new GridLayout(2, 1);
    mainLayout.setHgap(10);
    mainLayout.setVgap(10);
    getContentPane().setLayout(mainLayout);
    GridLayout topPanelLayout = new GridLayout(2, 1);
    topPanelLayout.setHgap(10);
    topPanelLayout.setVgap(10);
    Panel topPanel = new Panel(topPanelLayout);
    GridLayout bottomPanelLayout = new GridLayout(1, 2);
    bottomPanelLayout.setHgap(10);
    bottomPanelLayout.setVgap(10);
    Panel bottomPanel = new Panel(bottomPanelLayout);

    // 1 - status area
    statusArea = new TextArea("", 1, 1, TextArea.SCROLLBARS_VERTICAL_ONLY);
    statusArea.setEditable(false);
    statusArea.setFont(new Font("Dialog", Font.PLAIN, 10));
    statusArea.setSize(new Dimension(IMG_WIDTH * 2, IMG_HEIGHT / 2));

    // 2 - affinity history chart
    XYSeriesCollection seriesCollection = new XYSeriesCollection(affinitySeries);
    JFreeChart chart = ChartFactory.createXYLineChart("affinity history", "step", "affinity", seriesCollection,
            PlotOrientation.VERTICAL, false, false, false);
    ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();
    rangeAxis.setAutoRange(false);
    rangeAxis.setRange(0d, 1d);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(IMG_WIDTH * 2, IMG_HEIGHT / 2));

    // 3 - surface canvas
    surfaceCanvas = new SurfaceCanvas(surface, eye, IMG_WIDTH, IMG_HEIGHT);
    surfaceCanvas.setBackground(Color.WHITE);

    // 4 - eye canvas
    eyeCanvas = new EyeCanvas(eye, IMG_WIDTH, IMG_HEIGHT);
    eyeCanvas.setBackground(Color.WHITE);

    topPanel.add(statusArea);
    topPanel.add(chartPanel);
    bottomPanel.add(surfaceCanvas);
    bottomPanel.add(eyeCanvas);
    getContentPane().add(topPanel);
    getContentPane().add(bottomPanel);

    pack();
}

From source file:FileLister.java

/**
 * Constructor: create the GUI, and list the initial directory.
 *///from w w  w. ja v  a 2 s.co  m
public FileLister(String directory, FilenameFilter filter) {
    super("File Lister"); // Create the window
    this.filter = filter; // Save the filter, if any

    // Destroy the window when the user requests it
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            dispose();
        }
    });

    list = new List(12, false); // Set up the list
    list.setFont(new Font("MonoSpaced", Font.PLAIN, 14));
    list.addActionListener(this);
    list.addItemListener(this);

    details = new TextField(); // Set up the details area
    details.setFont(new Font("MonoSpaced", Font.PLAIN, 12));
    details.setEditable(false);

    buttons = new Panel(); // Set up the button box
    buttons.setLayout(new FlowLayout(FlowLayout.RIGHT, 15, 5));
    buttons.setFont(new Font("SansSerif", Font.BOLD, 14));

    up = new Button("Up a Directory"); // Set up the two buttons
    close = new Button("Close");
    up.addActionListener(this);
    close.addActionListener(this);

    buttons.add(up); // Add buttons to button box
    buttons.add(close);

    this.add(list, "Center"); // Add stuff to the window
    this.add(details, "North");
    this.add(buttons, "South");
    this.setSize(500, 350);

    listDirectory(directory); // And now list initial directory.
}

From source file:hspc.submissionsprogram.AppDisplay.java

AppDisplay() {
    this.setTitle("Dominion High School Programming Contest");
    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    this.setResizable(false);

    WindowListener exitListener = new WindowAdapter() {
        @Override//from w  w  w  .  ja v  a  2s .  c  om
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    this.addWindowListener(exitListener);

    JTabbedPane pane = new JTabbedPane();
    this.add(pane);

    JPanel submitPanel = new JPanel(null);
    submitPanel.setPreferredSize(new Dimension(500, 500));

    UIManager.put("FileChooser.readOnly", true);
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setBounds(0, 0, 500, 350);
    fileChooser.setVisible(true);
    FileNameExtensionFilter javaFilter = new FileNameExtensionFilter("Java files (*.java)", "java");
    fileChooser.setFileFilter(javaFilter);
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setControlButtonsAreShown(false);
    submitPanel.add(fileChooser);

    JSeparator separator1 = new JSeparator();
    separator1.setBounds(12, 350, 476, 2);
    separator1.setForeground(new Color(122, 138, 152));
    submitPanel.add(separator1);

    JLabel problemChooserLabel = new JLabel("Problem:");
    problemChooserLabel.setBounds(12, 360, 74, 25);
    submitPanel.add(problemChooserLabel);

    String[] listOfProblems = Main.Configuration.get("problem_names")
            .split(Main.Configuration.get("name_delimiter"));
    JComboBox problems = new JComboBox<>(listOfProblems);
    problems.setBounds(96, 360, 393, 25);
    submitPanel.add(problems);

    JButton submit = new JButton("Submit");
    submit.setBounds(170, 458, 160, 30);
    submit.addActionListener(e -> {
        try {
            File file = fileChooser.getSelectedFile();
            try {
                CloseableHttpClient httpClient = HttpClients.createDefault();
                HttpPost uploadFile = new HttpPost(Main.Configuration.get("submit_url"));

                MultipartEntityBuilder builder = MultipartEntityBuilder.create();
                builder.addTextBody("accountID", Main.accountID, ContentType.TEXT_PLAIN);
                builder.addTextBody("problem", String.valueOf(problems.getSelectedItem()),
                        ContentType.TEXT_PLAIN);
                builder.addBinaryBody("submission", file, ContentType.APPLICATION_OCTET_STREAM, file.getName());
                HttpEntity multipart = builder.build();

                uploadFile.setEntity(multipart);

                CloseableHttpResponse response = httpClient.execute(uploadFile);
                HttpEntity responseEntity = response.getEntity();
                String inputLine;
                BufferedReader br = new BufferedReader(new InputStreamReader(responseEntity.getContent()));
                try {
                    if ((inputLine = br.readLine()) != null) {
                        int rowIndex = Integer.parseInt(inputLine);
                        new ResultWatcher(rowIndex);
                    }
                    br.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(this, "No file selected.\nPlease select a java file.", "Error",
                    JOptionPane.WARNING_MESSAGE);
        }
    });
    submitPanel.add(submit);

    JPanel clarificationsPanel = new JPanel(null);
    clarificationsPanel.setPreferredSize(new Dimension(500, 500));

    cList = new JList<>();
    cList.setBounds(12, 12, 476, 200);
    cList.setBorder(new CompoundBorder(BorderFactory.createLineBorder(new Color(122, 138, 152)),
            BorderFactory.createEmptyBorder(8, 8, 8, 8)));
    cList.setBackground(new Color(254, 254, 255));
    clarificationsPanel.add(cList);

    JButton viewC = new JButton("View");
    viewC.setBounds(12, 224, 232, 25);
    viewC.addActionListener(e -> {
        if (cList.getSelectedIndex() != -1) {
            int id = Integer.parseInt(cList.getSelectedValue().split("\\.")[0]);
            clarificationDatas.stream().filter(data -> data.getId() == id).forEach(
                    data -> new ClarificationDisplay(data.getProblem(), data.getText(), data.getResponse()));
        }
    });
    clarificationsPanel.add(viewC);

    JButton refreshC = new JButton("Refresh");
    refreshC.setBounds(256, 224, 232, 25);
    refreshC.addActionListener(e -> updateCList(true));
    clarificationsPanel.add(refreshC);

    JSeparator separator2 = new JSeparator();
    separator2.setBounds(12, 261, 476, 2);
    separator2.setForeground(new Color(122, 138, 152));
    clarificationsPanel.add(separator2);

    JLabel problemChooserLabelC = new JLabel("Problem:");
    problemChooserLabelC.setBounds(12, 273, 74, 25);
    clarificationsPanel.add(problemChooserLabelC);

    JComboBox problemsC = new JComboBox<>(listOfProblems);
    problemsC.setBounds(96, 273, 393, 25);
    clarificationsPanel.add(problemsC);

    JTextArea textAreaC = new JTextArea();
    textAreaC.setLineWrap(true);
    textAreaC.setWrapStyleWord(true);
    textAreaC.setBorder(new CompoundBorder(BorderFactory.createLineBorder(new Color(122, 138, 152)),
            BorderFactory.createEmptyBorder(8, 8, 8, 8)));
    textAreaC.setBackground(new Color(254, 254, 255));

    JScrollPane areaScrollPane = new JScrollPane(textAreaC);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setBounds(12, 312, 477, 134);
    clarificationsPanel.add(areaScrollPane);

    JButton submitC = new JButton("Submit Clarification");
    submitC.setBounds(170, 458, 160, 30);
    submitC.addActionListener(e -> {
        if (textAreaC.getText().length() > 2048) {
            JOptionPane.showMessageDialog(this,
                    "Clarification body is too long.\nMaximum of 2048 characters allowed.", "Error",
                    JOptionPane.WARNING_MESSAGE);
        } else if (textAreaC.getText().length() < 20) {
            JOptionPane.showMessageDialog(this,
                    "Clarification body is too short.\nClarifications must be at least 20 characters, but no more than 2048.",
                    "Error", JOptionPane.WARNING_MESSAGE);
        } else {
            Connection conn = null;
            PreparedStatement stmt = null;
            try {
                Class.forName(JDBC_DRIVER);

                conn = DriverManager.getConnection(Main.Configuration.get("jdbc_mysql_address"),
                        Main.Configuration.get("mysql_user"), Main.Configuration.get("mysql_pass"));

                String sql = "INSERT INTO clarifications (team, problem, text) VALUES (?, ?, ?)";
                stmt = conn.prepareStatement(sql);

                stmt.setInt(1, Integer.parseInt(String.valueOf(Main.accountID)));
                stmt.setString(2, String.valueOf(problemsC.getSelectedItem()));
                stmt.setString(3, String.valueOf(textAreaC.getText()));

                textAreaC.setText("");

                stmt.executeUpdate();

                stmt.close();
                conn.close();

                updateCList(false);
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                try {
                    if (stmt != null) {
                        stmt.close();
                    }
                } catch (Exception ex2) {
                    ex2.printStackTrace();
                }
                try {
                    if (conn != null) {
                        conn.close();
                    }
                } catch (Exception ex2) {
                    ex2.printStackTrace();
                }
            }
        }
    });
    clarificationsPanel.add(submitC);

    pane.addTab("Submit", submitPanel);
    pane.addTab("Clarifications", clarificationsPanel);

    Timer timer = new Timer();
    TimerTask updateTask = new TimerTask() {
        @Override
        public void run() {
            updateCList(false);
        }
    };
    timer.schedule(updateTask, 10000, 10000);

    updateCList(false);

    this.pack();
    this.setLocationRelativeTo(null);
    this.setVisible(true);
}

From source file:gui.TraitViewerDialog.java

TraitViewerDialog(AppFrame appFrame, TraitFile tFile) {
    super(appFrame, "Trait Selection", true);
    this.tFile = tFile;

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            setVisible(false);//from w w  w .  ja v a  2  s  . co  m
        }
    });

    add(createControls());
    add(createButtons(), BorderLayout.SOUTH);
    // setSize(300, 250);
    setSize(500, 450);

    // pack();

    setLocationRelativeTo(appFrame);
    setResizable(false);
    setVisible(true);
}

From source file:au.com.jwatmuff.eventmanager.util.GUIUtils.java

/**
 * Makes a frame visible and blocks the caller until the frame is closed.
 * /*  w w w  . java2s .  com*/
 * @param frame
 */
public static void runModalJFrame(final JFrame frame) {
    // there may be a much better way of implementing this, i don't know..
    class RunningFlag {
        boolean value = true;
    }

    final RunningFlag flag = new RunningFlag();
    final Thread t = Thread.currentThread();

    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                frame.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosed(WindowEvent arg0) {
                        synchronized (t) {
                            flag.value = false;
                            t.notifyAll();
                        }
                    }
                });

                frame.setVisible(true);

            }
        });

        synchronized (t) {
            while (flag.value == true)
                try {
                    t.wait();
                } catch (InterruptedException e) {
                }
        }
    } catch (InterruptedException e) {
        log.error(e);
    } catch (InvocationTargetException e2) {
        log.error(e2);
    }
}

From source file:GUI.FormUsuarios.java

private void initializeComponent() {

    this.addWindowListener(new WindowAdapter() {

        public void windowOpened(WindowEvent e) {
            if (getID() != null) {
                int valor = ValoresCombobox.get(getTipo());
                cb_tipo.setSelectedIndex(valor - 1);
            }//from   ww w .jav  a  2s  .c  o m
        }

    });
}

From source file:altosui.AltosGraphUI.java

AltosGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException {
    super(file.getName());
    state = null;//from   w ww  .  j av  a2 s.c  o  m

    pane = new JTabbedPane();

    enable = new AltosUIEnable();

    stats = new AltosFlightStats(states);
    graphDataSet = new AltosGraphDataSet(states);

    graph = new AltosGraph(enable, stats, graphDataSet);

    statsTable = new AltosFlightStatsTable(stats);

    pane.add("Flight Graph", graph.panel);
    pane.add("Configure Graph", enable);
    pane.add("Flight Statistics", statsTable);

    has_gps = false;
    fill_map(states);
    if (has_gps)
        pane.add("Map", map);

    setContentPane(pane);

    AltosUIPreferences.register_font_listener(this);
    AltosPreferences.register_units_listener(this);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            setVisible(false);
            dispose();
            AltosUIPreferences.unregister_font_listener(AltosGraphUI.this);
            AltosPreferences.unregister_units_listener(AltosGraphUI.this);
        }
    });
    pack();

    setVisible(true);
    if (state != null && has_gps)
        map.centre(state);
}

From source file:net.sf.xmm.moviemanager.MovieManager.java

/**
 * Creates the main movie manager dialog
 *//*w ww. ja v a 2s.  co m*/
void createDialog() {

    dialogMovieManager = new DialogMovieManager();

    dialogMovieManager.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            MovieManagerCommandExit.execute();
        }
    });
}

From source file:FontPicker.java

public FontChooser(Frame parent) {
    super(parent, "Font Chooser", true);
    setSize(450, 450);/*  w w  w.j av a  2 s  . c  o m*/
    attributes = new SimpleAttributeSet();

    // Make sure that any way the user cancels the window does the right
    // thing
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            closeAndCancel();
        }
    });

    // Start the long process of setting up our interface
    Container c = getContentPane();

    JPanel fontPanel = new JPanel();
    fontName = new JComboBox(new String[] { "TimesRoman", "Helvetica", "Courier" });
    fontName.setSelectedIndex(1);
    fontName.addActionListener(this);
    fontSize = new JTextField("12", 4);
    fontSize.setHorizontalAlignment(SwingConstants.RIGHT);
    fontSize.addActionListener(this);
    fontBold = new JCheckBox("Bold");
    fontBold.setSelected(true);
    fontBold.addActionListener(this);
    fontItalic = new JCheckBox("Italic");
    fontItalic.addActionListener(this);

    fontPanel.add(fontName);
    fontPanel.add(new JLabel(" Size: "));
    fontPanel.add(fontSize);
    fontPanel.add(fontBold);
    fontPanel.add(fontItalic);

    c.add(fontPanel, BorderLayout.NORTH);

    // Set up the color chooser panel and attach a change listener so that
    // color
    // updates get reflected in our preview label.
    colorChooser = new JColorChooser(Color.black);
    colorChooser.getSelectionModel().addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            updatePreviewColor();
        }
    });
    c.add(colorChooser, BorderLayout.CENTER);

    JPanel previewPanel = new JPanel(new BorderLayout());
    previewLabel = new JLabel("Here's a sample of this font.");
    previewLabel.setForeground(colorChooser.getColor());
    previewPanel.add(previewLabel, BorderLayout.CENTER);

    // Add in the Ok and Cancel buttons for our dialog box
    JButton okButton = new JButton("Ok");
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            closeAndSave();
        }
    });
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            closeAndCancel();
        }
    });

    JPanel controlPanel = new JPanel();
    controlPanel.add(okButton);
    controlPanel.add(cancelButton);
    previewPanel.add(controlPanel, BorderLayout.SOUTH);

    // Give the preview label room to grow.
    previewPanel.setMinimumSize(new Dimension(100, 100));
    previewPanel.setPreferredSize(new Dimension(100, 100));

    c.add(previewPanel, BorderLayout.SOUTH);
}

From source file:org.fhaes.FHRecorder.FireHistoryRecorder.java

private void initComponents() {

    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {

            closeAfterRunningChecks();//from w w w. j  ava  2  s .  c  om

        }

    });

    setMinimumSize(new java.awt.Dimension(950, 675));
    setResizable(true);

    getContentPane().setLayout(new MigLayout("", "[810px,grow]", "[466.00,grow][42.00]"));

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    getContentPane().add(tabbedPane, "cell 0 0,grow");

    sampleInputHolder = new JPanel();
    siteInfoHolder = new JPanel();

    sampleInputHolder.setLayout(new BorderLayout());
    siteInfoHolder.setLayout(new BorderLayout());

    tabbedPane.addTab("Data", null, sampleInputHolder, null);
    tabbedPane.addTab("Metadata", null, siteInfoHolder, null);

    summaryHolder = new JPanel();
    tabbedPane.addTab("Summary", null, summaryHolder, null);

    graphicsHolder = new JPanel();
    tabbedPane.addTab("Graphics", null, graphicsHolder, null);
    graphicsHolder.setLayout(new BorderLayout(0, 0));

    chartScrollBar = new JScrollBar();
    chartScrollBar.setMaximum(110);
    chartScrollBar.addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent arg0) {
            if (graphicsPanel != null) {
                graphicsPanel.updateVisibleYears(chartScrollBar.getValue());
            }
        }
    });
    chartScrollBar.setOrientation(JScrollBar.HORIZONTAL);
    graphicsHolder.add(chartScrollBar, BorderLayout.SOUTH);

    fileErrorHolder = new JPanel();
    tabbedPane.addTab("File Errors", null, fileErrorHolder, null);

    panelButtonBar = new JPanel();
    getContentPane().add(panelButtonBar, "cell 0 1,alignx right,growy");

    useLimitsCheckBox = new JCheckBox("Keep FHX2 Limitations");
    panelButtonBar.add(useLimitsCheckBox);
    useLimitsCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            siteInfo.setLimitRestriction(useLimitsCheckBox.isSelected());
        }
    });

    btnSave = new JButton("Save");
    panelButtonBar.add(btnSave);
    btnSave.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            saveMenuItemActionPerformed(e);
        }

    });

    btnClose = new JButton("Close");
    btnClose.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            closeAfterRunningChecks();
        }

    });
    panelButtonBar.add(btnClose);

    btnCancel = new JButton("Discard changes");
    panelButtonBar.add(btnCancel);
    btnCancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            Controller.filePath = null;
            setVisible(false);

        }

    });

    pack();
}