JOptionPane in NetBeans

Could someone please have a look at my NetBeans code below and tell me why the program freezes if you click on the Quit menu item under the File menu. I tried commenting out the JOptionPane code and it works fine so its something to do with that, but i can't figure out what.

/*

* mapperGUI.java

*

* Created on 06 December 2005, 22:11

*/

package my.sitemapper.pkg;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

import javax.swing.text.*;

import java.text.*;

import java.util.*;

import javax.swing.undo.*;

import javax.swing.event.*;

import java.awt.print.*;

import javax.swing.JOptionPane;

/**

*

* @author Faz

*/

public class mapperGUI extends javax.swing.JFrame implements ActionListener {

/** Creates new form mapperGUI */

public mapperGUI() {

initComponents();

jButton1.addActionListener(this);

jButton2.addActionListener(this);

jButton3.addActionListener(this);

jButton4.addActionListener(this);

jButton5.addActionListener(this);

jButton6.addActionListener(this);

jTextField1.addActionListener(this);

jMenuItem1.addActionListener(this);

jMenuItem2.addActionListener(this);

jMenuItem3.addActionListener(this);

jMenuItem4.addActionListener(this);

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">

private void initComponents() {

jToolBar1 = new javax.swing.JToolBar();

jPanel1 = new javax.swing.JPanel();

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

jButton4 = new javax.swing.JButton();

jButton5 = new javax.swing.JButton();

jButton6 = new javax.swing.JButton();

jPanel2 = new javax.swing.JPanel();

jLabel1 = new javax.swing.JLabel();

jTextField1 = new javax.swing.JTextField();

jSeparator1 = new javax.swing.JSeparator();

jButton3 = new javax.swing.JButton();

jStatusBar1 = new com.zfqjava.swing.JStatusBar();

jMenuBar1 = new javax.swing.JMenuBar();

jMenu1 = new javax.swing.JMenu();

jMenuItem1 = new javax.swing.JMenuItem();

jMenuItem2 = new javax.swing.JMenuItem();

jMenuItem3 = new javax.swing.JMenuItem();

jMenu2 = new javax.swing.JMenu();

jMenuItem4 = new javax.swing.JMenuItem();

jMenu3 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle("Site Analyser & Mapper (SAM)");

setAlwaysOnTop(true);

setBackground(new java.awt.Color(102, 204, 255));

jPanel1.setBackground(new java.awt.Color(153, 204, 255));

jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

jPanel1.setName("Quick Functions");

jButton1.setText("Save Map");

jButton2.setText("Load Map");

jButton4.setText("Change Style");

jButton5.setText("New Target");

jButton6.setText("Exit");

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1Layout.createSequentialGroup()

.addContainerGap()

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)

.add(jButton5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)

.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 97, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(org.jdesktop.layout.GroupLayout.TRAILING, jButton4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)

.add(jButton6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.addContainerGap())

);

jPanel1Layout.linkSize(new java.awt.Component[] {jButton1, jButton2, jButton4, jButton5}, org.jdesktop.layout.GroupLayout.HORIZONTAL);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1Layout.createSequentialGroup()

.addContainerGap()

.add(jButton5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(27, 27, 27)

.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(30, 30, 30)

.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(28, 28, 28)

.add(jButton4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 31, Short.MAX_VALUE)

.add(jButton6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addContainerGap())

);

jPanel1Layout.linkSize(new java.awt.Component[] {jButton1, jButton2, jButton4, jButton5}, org.jdesktop.layout.GroupLayout.VERTICAL);

jPanel2.setBackground(new java.awt.Color(153, 204, 255));

jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

jLabel1.setFont(new java.awt.Font("Tahoma", 3, 12));

jLabel1.setText("Search Map:");

jButton3.setText("Go");

org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);

jPanel2.setLayout(jPanel2Layout);

jPanel2Layout.setHorizontalGroup(

jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2Layout.createSequentialGroup()

.addContainerGap()

.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2Layout.createSequentialGroup()

.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 93, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jButton3))

.add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE))

.addContainerGap())

);

jPanel2Layout.setVerticalGroup(

jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()

.addContainerGap(286, Short.MAX_VALUE)

.add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(jButton3))

.addContainerGap())

);

jStatusBar1.setBorderPainted(true);

jStatusBar1.setText("Ready");

jMenu1.setText("File");

jMenuItem1.setText("Open");

jMenu1.add(jMenuItem1);

jMenuItem2.setText("Save");

jMenu1.add(jMenuItem2);

jMenuItem3.setText("Quit");

jMenu1.add(jMenuItem3);

jMenuBar1.add(jMenu1);

jMenu2.setText("Map");

jMenuItem4.setText("Change Style");

jMenu2.add(jMenuItem4);

jMenuBar1.add(jMenu2);

jMenu3.setText("Help");

jMenuBar1.add(jMenu3);

setJMenuBar(jMenuBar1);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jToolBar1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE)

.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()

.addContainerGap()

.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(14, 14, 14)

.add(jPanel2)

.addContainerGap())

.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()

.addContainerGap()

.add(jStatusBar1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()

.add(jToolBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)

.add(jPanel2)

.add(jPanel1, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jStatusBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addContainerGap())

);

pack();

}// </editor-fold>

public void actionPerformed(ActionEvent e) {

Object eventSource = e.getSource();

if (eventSource instanceof JMenuItem) {

String label = (String) e.getActionCommand();

if (label.equals("Quit")) {

int confirm = JOptionPane.showConfirmDialog(null,

"Would you like to save?",

"Exit Application",

JOptionPane.YES_NO_CANCEL_OPTION);

if( confirm == JOptionPane.YES_OPTION) {

//jStatusBar1.setText("Exiting and Saving file");

dispose();

System.exit(0);

}

else if ( confirm == JOptionPane.NO_OPTION) {

//jStatusBar1.setText("Exiting Without Saving file");

dispose();

System.exit(0);

}

else {}

}

}

else {

JButton button = (JButton) e.getSource();

String label = button.getText();

if (label.equals("Exit")) {

dispose();

System.exit(0);

}

}

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new mapperGUI().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JButton jButton2;

private javax.swing.JButton jButton3;

private javax.swing.JButton jButton4;

private javax.swing.JButton jButton5;

private javax.swing.JButton jButton6;

private javax.swing.JLabel jLabel1;

private javax.swing.JMenu jMenu1;

private javax.swing.JMenu jMenu2;

private javax.swing.JMenu jMenu3;

private javax.swing.JMenuBar jMenuBar1;

private javax.swing.JMenuItem jMenuItem1;

private javax.swing.JMenuItem jMenuItem2;

private javax.swing.JMenuItem jMenuItem3;

private javax.swing.JMenuItem jMenuItem4;

private javax.swing.JPanel jPanel1;

private javax.swing.JPanel jPanel2;

private javax.swing.JSeparator jSeparator1;

private com.zfqjava.swing.JStatusBar jStatusBar1;

private javax.swing.JTextField jTextField1;

private javax.swing.JToolBar jToolBar1;

// End of variables declaration

}

[12487 byte] By [faraz4evera] at [2007-10-2 10:07:30]
# 1

Your code is not compilable, as you are using third party library.

>I tried commenting out the JOptionPane code and it works fine so its something to do with that, but i can't figure out what.

Then post a simple executable demo program that only demonstrates the stated behavior.

ajneoa at 2007-7-13 1:25:09 > top of Java-index,Security,Event Handling...