Solved

runtime error of JDialog

Posted on 2007-03-20
3
301 Views
Last Modified: 2008-01-09
I have the following code that produces a JDialog from an ActionEvent:

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class replaceWindow extends JDialog {
            
      JLabel jlbl = new JLabel();
      JTextField jtextField = new JTextField();
      JButton jbtn = new JButton();
      
      public void replace() {
            
            add(jlbl, BorderLayout.CENTER);
            
            setLayout(new GridBagLayout());
            GridBagConstraints c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            
            jlbl = new JLabel ("0,0");
            c.weightx = 1;
            c.gridx = 0;
            c.gridy = 0;
            add(jlbl, c);
            
            jlbl = new JLabel ("1,0");
            c.weightx = 1;
            c.gridx = 1;
            c.gridy = 0;
            add(jlbl, c);
            
            jlbl = new JLabel ("2,0");
            c.weightx = 1;
            c.gridx = 2;
            c.gridy = 0;
            add(jlbl, c);
            
            jlbl = new JLabel ("3,0");
            c.weightx = 1;
            c.gridx = 3;
            c.gridy = 0;
            add(jlbl, c);
            
            jlbl = new JLabel ("4,0");
            c.weightx = 1;
            c.gridx = 4;
            c.gridy = 0;
            add(jlbl, c);
            
            jlbl = new JLabel ("5,0");
            c.weightx = 1;
            c.gridx = 5;
            c.gridy = 0;
            add(jlbl, c);
            
            jlbl = new JLabel ("6,0");
            c.weightx = 1;
            c.gridx = 6;
            c.gridy = 0;
            add(jlbl, c);
            
            jlbl = new JLabel ("7,0");
            c.weightx = 1;
            c.gridx = 7;
            c.gridy = 0;
            add(jlbl, c);
            
            jlbl = new JLabel ("0,1");
            c.weightx = 1;
            c.gridx = 0;
            c.gridy = 1;
            add(jlbl, c);
            
            jlbl = new JLabel ("Search:");
            c.weightx = 1;
            c.gridx = 1;
            c.gridy = 1;
            c.gridwidth = 2;
            add(jlbl, c);
            
            jlbl = new JLabel ("3,1");
            c.weightx = 1;
            c.gridx = 3;
            c.gridy = 1;
            add(jlbl, c);
            
            jlbl = new JLabel ("4,1");
            c.weightx = 1;
            c.gridx = 4;
            c.gridy = 1;
            add(jlbl, c);
            
            jlbl = new JLabel ("5,1");
            c.weightx = 1;
            c.gridx = 5;
            c.gridy = 1;
            add(jlbl, c);
            
            jlbl = new JLabel ("6,1");
            c.weightx = 1;
            c.gridx = 6;
            c.gridy = 1;
            add(jlbl, c);
            
            jlbl = new JLabel ("7,1");
            c.weightx = 1;
            c.gridx = 7;
            c.gridy = 1;
            add(jlbl, c);
            
            jlbl = new JLabel ("0,2");
            c.weightx = 1;
            c.gridx = 0;
            c.gridy = 2;
            add(jlbl, c);
            
            jtextField = new JTextField ();
            c.weightx = 1;
            c.gridx = 1;
            c.gridy = 2;
            c.gridwidth = 3;
            add(jtextField, c);
            
            jlbl = new JLabel ("4,2");
            c.weightx = 1;
            c.gridx = 4;
            c.gridy = 2;
            add(jlbl, c);
            
            jlbl = new JLabel ("5,2");
            c.weightx = 1;
            c.gridx = 5;
            c.gridy = 2;
            add(jlbl, c);
            
            jlbl = new JLabel ("6,2");
            c.weightx = 1;
            c.gridx = 6;
            c.gridy = 2;
            add(jlbl, c);
            
            jlbl = new JLabel ("7,2");
            c.weightx = 1;
            c.gridx = 7;
            c.gridy = 2;
            add(jlbl, c);
            
            setTitle("Replace");
            pack();
            setLocation(300, 200);
            setResizable(false);
            setVisible(true);
            setSize(400, 200);
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      }
      
}

When the first ActionEvent takes place, the JDialog box appears, when I close the JDialog box and attempt the same ActionEvent to trigger the JDialog box I get a runtime error.

Can anyone help ?
0
Comment
Question by:Vel Eous
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 18760521
Please post code where it's called
0
 
LVL 14

Author Comment

by:Vel Eous
ID: 18760548
Didnt relise the code I posted above was so long, sorry about that, should have trimmed it.

The code above is in a file called replaceWindow.java and the following code is in my main class:

replaceWindow replaceMethod = new replaceWindow();

toolsMenu.add(jmiReplace = new JMenuItem("Replace"));
               jmiReplace.setMnemonic('R');
               jmiReplace.setAccelerator(KeyStroke.getKeyStroke("ctrl R"));

jmiReplace.addActionListener(new mnReplace());

class mnReplace implements ActionListener {
         public void actionPerformed (ActionEvent e) {
               replaceMethod.replace();
         }
}
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 18760750
u dispise of the dialog on close so its not available to open again
so either get gid of dispose on close
or create a new instance of replaceWindow each time

(btw, if you do the former you don't nweed to set up the dialog everytime, a simple setVisible() would suffice.)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question