public class Test
{
public static void main(String[] args)
throws Exception
{
JFrame f = new JFrame("Test");
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JDialog d = new JDialog(f, "I'm a dialog")
{
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
};
d.setLocation(100, 100);
d.setVisible(true);
}
}
JDialog prefdia = new JDialog(this, "I'm a dialog")
{
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
};
prefdia.setVisible(true);
prefdia.setBounds(50, 50, 100, 100);
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ListenerDemo extends JFrame {
public ListenerDemo(String title) {
super(title);
setSize(600, 400);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
MyDialog d = new MyDialog(this);
d.setVisible(true);
}
class MyDialog extends JDialog {
MyDialog(Frame parent) {
super(parent, "Dialog-Titel", true);
setSize(400, 300);
setLocationRelativeTo(parent);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
public static void main(String[] args) {
new ListenerDemo("Frame-Titel");
}
}