Solved

runtime error of JDialog

Posted on 2007-03-20
3
289 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:Tchuki
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Please post code where it's called
0
 
LVL 14

Author Comment

by:Tchuki
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now