I had give a lot of search on this.. I have a problem that can be summarized with this code:
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JDialog ui = new RandomDialog();
}
});
item
is just a menu Item and RandomDialog
is a class that extends JDialog
.
Every time I made a change in RandomDialog
class, I had to "update" the ui
declaration from JDialog
to RandomDialog
and then vice-versa.
What is the problem?
[EDIT]
I have a JFrame
, with a JMenuBar
and JMenuItem
. One of these Items had a listener like the one above. I want to open a JDialog
when that item is pressed. What happens is every time I make a change on the code from the class that represents that JDialog
(a separate class that extends JDialog
) that change is not presented unless I change the declaration of the JDialog
. So imagine that I have the declaration like this:
JDialog ui = new RandomDialog();
If I make a change, I have to put like this:
RandomDialog ui = new RandomDialog();
And next I have to put again:
JDialog ui = new RandomDialog();
And so on, so on...
By changing JDialog
to RandomDialog
and then back to JDialog
you are not changing the code, but you are changing the timestamp of the file. This causes your build system to rebuild the .class
file from the Java file, build .jar
file, and then possibly deploy it to a server, depending on how you have it set up.
The cause of the problem is that your build system does not realize that this file (with the JMenuItem
) depends on the other file (with the RandomDialog
) so changes to the RandomDialog
are not causing a rebuild to be done.
To solve this, you will need to look at your project structure. You have not described how the code is being built. Usually if you use an IDE, it will let you manage project dependencies.
In NetBeans Clean & Build usually will do the necessary re-build.
Be sure to enable Compile On Save
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.