Created
August 25, 2022 02:14
-
-
Save Vzor-/1095e6834ce7df1ab6994536a5ba258a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.*; | |
import java.awt.*; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
public class DialogTest { | |
public static void main(String[] args) { | |
DemoDialog test = new DemoDialog(null, 1); | |
test.setLocation(0,0); | |
test.setVisible(true); | |
} | |
private static class DemoDialog extends JDialog{ | |
private int num; | |
private JButton button; | |
private JPanel mainPanel; | |
public DemoDialog(Window owner, int num) { | |
super(owner, "Dialog #" + num , ModalityType.APPLICATION_MODAL); | |
button = new JButton("ok"); | |
button.addActionListener(buttonAction); | |
mainPanel = new JPanel(); | |
mainPanel.add(button); | |
getContentPane().add(mainPanel); | |
setSize(200, 100); | |
this.num = num; | |
} | |
private ActionListener buttonAction = new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
if(num == 1) { | |
DemoDialog test2 = new DemoDialog(null, 2); | |
test2.setLocation(0,200); | |
test2.setVisible(true); | |
} | |
// Uncomment to fix issue | |
// try { | |
// Thread.sleep(500); | |
// } catch (InterruptedException ex) { | |
// throw new RuntimeException(ex); | |
// } | |
setVisible(false); | |
System.out.println("Prompt #" + num + " resolved"); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment