OnJava8-Examples/ui/Dialogs.java

34 lines
948 B
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// ui/Dialogs.java
2015-12-15 11:47:04 -08:00
// (c)2016 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
2015-06-15 17:47:35 -07:00
// Creating and using Dialog Boxes.
import javax.swing.*;
import java.awt.*;
import static onjava.SwingConsole.*;
2015-06-15 17:47:35 -07:00
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");
ok.addActionListener(e ->
dispose()); // Closes the dialog
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() {
b1.addActionListener(e -> dlg.setVisible(true));
add(b1);
}
public static void main(String[] args) {
run(new Dialogs(), 125, 75);
}
2015-09-07 11:44:36 -06:00
}