Solved

runtime error of JDialog

Posted on 2007-03-20
3
295 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
diffSum example 4 53
object oriented programming comparison 5 77
java stored proc example 9 46
Eclipse Help Java EE 5,6,7 Documentation, why not Java EE 8 8 30
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

820 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