35 lines
998 B
Java
35 lines
998 B
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
|
|
public class DialogExample {
|
|
private static JDialog dialog;
|
|
|
|
public DialogExample() {
|
|
JFrame frame = new JFrame();
|
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
|
|
|
dialog = new JDialog(frame, "New Dialog Box", true);
|
|
dialog.setLayout(new FlowLayout());
|
|
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
|
|
|
JButton button = new JButton("OK");
|
|
button.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
DialogExample.dialog.setVisible(false);
|
|
}
|
|
});
|
|
|
|
dialog.add(new JLabel("Click OK to Agree"));
|
|
dialog.add(button);
|
|
dialog.setSize(250, 250);
|
|
dialog.setVisible(true);
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
new DialogExample();
|
|
}
|
|
}
|