OnJava8-Examples/gui/Dialogs.java

31 lines
787 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: gui/Dialogs.java
// Creating and using Dialog Boxes.
import javax.swing.*;
import java.awt.*;
import static net.mindview.util.SwingConsole.*;
class MyDialog extends JDialog {
public MyDialog(JFrame parent) {
super(parent, "My dialog", true);
setLayout(new FlowLayout());
add(new JLabel("Here is my dialog"));
JButton ok = new JButton("OK");
2015-05-06 12:09:38 -07:00
ok.addActionListener(e ->
dispose()); // Closes the dialog
2015-04-20 15:36:01 -07:00
add(ok);
setSize(150,125);
}
}
public class Dialogs extends JFrame {
private JButton b1 = new JButton("Dialog Box");
private MyDialog dlg = new MyDialog(null);
public Dialogs() {
2015-05-06 12:09:38 -07:00
b1.addActionListener(e -> dlg.setVisible(true));
2015-04-20 15:36:01 -07:00
add(b1);
}
public static void main(String[] args) {
run(new Dialogs(), 125, 75);
}
} ///:~