package org.jfml.test;import java.awt.*;
import javax.swing.*;
import java.awt.event.*;public class MyApp extends JFrame
{
public MyApp()
{
final Container contentPane = getContentPane();
JButton jbutton = new JButton("Display dialog"); contentPane.add(jbutton, BorderLayout.NORTH); jbutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int result =
JOptionPane.showConfirmDialog(
(Component) MyApp.this,
"yes or no",
"yes or no",
JOptionPane.YES_NO_OPTION);
System.out.println("result = " + result);
if (0 == result)
{
MyApp.this.dispose();
}
}
});
} public static void main(String[] args)
{
MyApp app = new MyApp();
app.setBounds(0, 0, 300, 300);
app.setVisible(true); app.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
app.addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
}); }
}
import javax.swing.*;
import java.awt.event.*;public class MyApp extends JFrame
{
public MyApp()
{
final Container contentPane = getContentPane();
JButton jbutton = new JButton("Display dialog"); contentPane.add(jbutton, BorderLayout.NORTH); jbutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int result =
JOptionPane.showConfirmDialog(
(Component) MyApp.this,
"yes or no",
"yes or no",
JOptionPane.YES_NO_OPTION);
System.out.println("result = " + result);
if (0 == result)
{
MyApp.this.dispose();
}
}
});
} public static void main(String[] args)
{
MyApp app = new MyApp();
app.setBounds(0, 0, 300, 300);
app.setVisible(true); app.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
app.addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
}); }
}
import javax.swing.*;
import java.awt.event.*;public class MyApp extends JFrame
{
public MyApp()
{
final Container contentPane = getContentPane();
JButton jbutton = new JButton("Display dialog");
contentPane.add(jbutton,BorderLayout.NORTH);
jbutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int result = JOptionPane.showConfirmDialog((Component)null,"yes or no","yes or no",JOptionPane.YES_NO_OPTION);
if (result == 0)
MyApp.this.dispose();//看这里
}
}
);
} public static void main(String[] args)
{
MyApp app = new MyApp();
app.setBounds(0,0,300,300);
app.setVisible(true);
app.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
app.addWindowListener(new WindowAdapter(){public void WindowClosing(WindowEvent e){System.exit(0);}});
}
}