Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

runtime error of JDialog

Posted on 2007-03-20
3
Medium Priority
?
303 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 2000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses

715 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