Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why doesn't my WindowListener work?

 
Jerry Goldsmith
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to execute a test method inside my window listener. All it is supposed to do is show a dialog saying "Inside listener" when the first dialog closes. I can't seem to get it to work. Can anyone see what I'm doing wrong? Thanks. Here is the code:

public class Jerry_Test
{
public static void start()
{

JFrame parentFrame = new JFrame();
JLabel new_label = new JLabel("New part number");
JTextField new_text = new JTextField(50);
JPanel new_panel = new JPanel();
new_label.setLabelFor(new_text);
new_panel.add(new_label);

final JOptionPane new_pane = new JOptionPane(new_panel);
new_pane.setWantsInput(true);

final JDialog new_dialog = new_pane.createDialog(parentFrame, "Test");
new_dialog.setModal(false);
new_dialog.setVisible(true);
new_dialog.toFront();

new_dialog.addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
test_output();
}
}
);

}

public static void stop()
{
}

public static void test_output()
{
JFrame parentFrame_2 = new JFrame();
JOptionPane.showMessageDialog(parentFrame_2, "Inside the listener");
}

}
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
worked OK for me, java 1.4.0_01
 
Jerry Goldsmith
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still doesn't work for me. JDK 1.4.2.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic