OnJava8-Examples/gui/Dialogs.java
2015-05-05 14:05:39 -07:00

35 lines
864 B
Java

//: gui/Dialogs.java
// Creating and using Dialog Boxes.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
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");
ok.addActionListener((ActionEvent 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((ActionEvent e) -> {
dlg.setVisible(true);
});
add(b1);
}
public static void main(String[] args) {
run(new Dialogs(), 125, 75);
}
} ///:~