Multiple windows... closing one exits the app!

Hi, I've created a simple web browser where the class with the main method is supposed to create some windows and have the app exit when the last window is closed. The problem is that when I go to close just one of the windows all the windows close and the application exits.
Any help is appreciated! :)
Browser.java
package browser.Browser;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class Browser {
     public static void main(String[] args) {
         BrowserFrame f1 = new BrowserFrame();
        f1.setVisible(true);
        BrowserFrame f2 = new BrowserFrame();
        f2.setVisible(true);
    /*public void newWindow() {
          BrowserFrame f = new BrowserFrame();
        f.setVisible(true);
BrowserFrame.java
package browser.Browser;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.net.*;
import java.io.*;
public class BrowserFrame extends JFrame implements
                                                       ActionListener,
                                                       HyperlinkListener {
     Color menuColor = new Color(220, 220, 220);
     URL url;
     JTextField URLBar;
     static JButton goButton;
     static JEditorPane ViewArea;
     * The constructor.
     public BrowserFrame() {
         //look and feel
         try {
             UIManager.setLookAndFeel(
                  UIManager.getSystemLookAndFeelClassName());
             Toolkit.getDefaultToolkit().setDynamicLayout(true);
          catch (ClassNotFoundException e) {/*do nothing*/}
          catch (InstantiationException e) {/*do nothing*/}
          catch (IllegalAccessException e) {/*do nothing*/}
          catch (UnsupportedLookAndFeelException e) {/*do nothing*/}
         //create the controls
         try {
              url = new URL("http://www.google.com");
         }catch(MalformedURLException e) {/*do nothing*/}
         URLBar = new JTextField();
         goButton = new JButton("Go");
          ViewArea = new JEditorPane();
          JPanel upperPanel = new JPanel();
         JPanel mainPanel = new JPanel();
         upperPanel.setLayout(new BorderLayout());
         mainPanel.setLayout(new BorderLayout());
          //set the control's properties
          goButton.setSize(new Dimension(12, 20));
          URLBar.setText(url.getProtocol() + "://" + url.getHost() + "/");
          URLBar.setBorder(BorderFactory.createEtchedBorder());
          ViewArea.setEditable(false);
          //Event handlers
          goButton.addActionListener(this);
          URLBar.addActionListener(this);
          ViewArea.addHyperlinkListener(this);
          //The scrollPane is for the ViewArea
         JScrollPane scrollPane = new JScrollPane(ViewArea);
         //add controls to the panel(s)
         mainPanel.add(upperPanel, BorderLayout.NORTH);
          upperPanel.add(URLBar, BorderLayout.CENTER);
          upperPanel.add(goButton, BorderLayout.EAST);
         mainPanel.add(scrollPane, BorderLayout.CENTER);
         //frame setup
         setJMenuBar(CreateJMenuBar());
         getContentPane().add(mainPanel);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setSize(600, 450);
         URLBar.setSize(getWidth() - goButton.getWidth(), 20);
         setVisible(true);
         connectToURL();
    //actionListener methods
    public void actionPerformed(ActionEvent e) {
          if(e.getActionCommand().equals("Exit")) {
               dispose();
               //System.exit(0);
          else if(e.getSource() == goButton) {
               try {
                   url = new URL(URLBar.getText());
                   connectToURL();
                  }catch (MalformedURLException err) { //try prefixing "http://"
                       try {
                            url = new URL("http://" + URLBar.getText());
                            connectToURL();
                       catch(MalformedURLException e2) {/*do nothing*/}
          else if(e.getSource() == URLBar) {
               System.out.println(URLBar.getText());
               try {
                    url = new URL(URLBar.getText());
                    connectToURL();
               catch (MalformedURLException err) { //try prefixing "http://"
                    try {
                            url = new URL("http://" + URLBar.getText());
                            connectToURL();
                       catch(MalformedURLException e2) {/*do nothing*/}
     public void hyperlinkUpdate(HyperlinkEvent e) {
          if (e.getEventType()==HyperlinkEvent.EventType.ACTIVATED) {
               if (e instanceof HTMLFrameHyperlinkEvent) {
                    ((HTMLDocument)ViewArea.getDocument()).processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent)e);
               else {
                    try {
                         ViewArea.setPage(e.getURL());
                         URLBar.setText(ViewArea.getPage().toString());
                    catch(IOException ioe) {
                         System.out.println(ioe);
     public void connectToURL() {
          try {
               URLBar.setText(url.toString());
               ViewArea.setPage(url);
          catch(IOException e) {
               URLBar.setText("failed.");
    public JMenuBar CreateJMenuBar() {
        JMenuBar menuBar = new JMenuBar();
        menuBar.setBorderPainted(false);
        JMenu menu = new JMenu("File");
        menu.setMnemonic(KeyEvent.VK_F); //for navigating the menu
        JMenuItem menuItem;
        menuBar.setBackground(menuColor);
        menu.setBackground(menuColor);
        menuBar.add(menu);
        //the menuitems for "File"
        menuItem = new JMenuItem("Exit", KeyEvent.VK_X);
        menuItem.getAccessibleContext().setAccessibleDescription("Exit the program");
        menuItem.setBackground(menuColor);
        menuItem.addActionListener(this);
        menu.add(menuItem);
        //the menuitems for "Edit"
        menu = new JMenu("Edit");
        return menuBar;
}

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);I don't know much of Swing but it might have something to do with this line. You might take a look at the Swing tutorials and the API docs.

Similar Messages

Maybe you are looking for

  • How to set up display properties for a crosstab is CSS?

    I am woundring how to setup css class and code like in this tutorial. myalerting.css ? Set up display properties for a crosstab: Design Studio 1.2 - YouTube. Design Studio 1.2: Set up display properties for a crosstab if you have sample file please s

  • Pie chart legend options

    I have a spreadsheet with "expense categories" in one column and "dollar figures" in the second column. When I highlight the columns and create a chart I DON'T want to have to use "show legend" (with the color circles at the bottom) as it repeats my

  • Slide show photos black

    I am trying to create a slide show from the pictures stored in iPhoto, but some of them do not show up in the slide show. Instead, there is a black screen for the three seconds that the photo should be showing. Others from the same library are fine t

  • Got another MI424WR

    well, went to a verizon store and replaced my REV. C MI424WR that was causing SLOW download speeds, they gave me a new in box MI424WR REV. E, plugged it in all in as usual... ORANGE internet LED, stays orange, never goes green. I tried unplugging the

  • [SOLVED] Is /opt empty by default?

    Hello, i had some issue installing a third party program. I downloaded it as binary, the only thing to do was to place it to /opt. It was a tar.bz2 file. it contents was opt folder, then PorgramName folder and so on. so i issued: sudo tar xjvf archiv