Solved

runtime error of JDialog

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate example issues from command prompt 10 84
maven disable workspace resolution 1 72
ejb entity bean example issue 2 40
How to fix  socket closed error 11 61
In this post we will learn different types of Android Layout and some basics of an Android App.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

737 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