showConfirmDialog public static int showConfirmDialog(Component parentComponent, Object message) throws HeadlessExceptionBrings up a dialog with the options Yes, No and Cancel; with the title, Select an Option.Parameters:parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is usedmessage - the Object to display Returns:an integer indicating the option selected by the user Throws: HeadlessException - if GraphicsEnvironment.isHeadless returns true
showMessageDialog public static void showMessageDialog(Component parentComponent, Object message) throws HeadlessExceptionBrings up an information-message dialog titled "Message".Parameters:parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is usedmessage - the Object to display Throws: HeadlessException - if GraphicsEnvironment.isHeadless returns true
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class Frame1 extends JFrame {
JButton jButton1 = new JButton();public static void main(String[] args)
{
Frame1 test=new Frame1();
test.show();
}
public Frame1() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
jButton1.setBounds(new Rectangle(99, 81, 83, 28));
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setBounds(50,50,400,200);
jButton1.setText("jButton1");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
this.getContentPane().setLayout(null);
this.getContentPane().add(jButton1, null);
} void jButton1_actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(this,"a message box is shown");
}
}class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee; Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}新建文件Frame1.java,粘上代码,直接运行即可
public static int showConfirmDialog(Component parentComponent,
Object message)
throws HeadlessExceptionBrings up a dialog with the options Yes,
No and Cancel; with the
title, Select an Option.Parameters:parentComponent - determines the Frame in which the
dialog is displayed; if null,
or if the parentComponent has no
Frame, a
default Frame is usedmessage - the Object to display
Returns:an integer indicating the option selected by the user
Throws:
HeadlessException - if
GraphicsEnvironment.isHeadless returns
true
public static void showMessageDialog(Component parentComponent,
Object message)
throws HeadlessExceptionBrings up an information-message dialog titled "Message".Parameters:parentComponent - determines the Frame in
which the dialog is displayed; if null,
or if the parentComponent has no
Frame, a default Frame is usedmessage - the Object to display
Throws:
HeadlessException - if
GraphicsEnvironment.isHeadless returns
true