JavaSwing图形界面编程之消息提示框(一)


JavaSwing图形界面编程之消息提示框(一)_第1张图片

JavaSwing图形界面编程之消息提示框(一)_第2张图片

JavaSwing图形界面编程之消息提示框(一)_第3张图片

JavaSwing图形界面编程之消息提示框(一)_第4张图片

package three.day.frame;


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JOptionPaneDemo01 implements ActionListener
{
JFrame f = null;
public JOptionPaneDemo01()
{
f = new JFrame("OptionPane Demo");
Container cp = f.getContentPane();
cp.setLayout(new GridLayout(2,2));
JButton bt = new JButton("Show Error Icon");
bt.addActionListener(this);
cp.add(bt);
bt = new JButton("Show Warming Icon");
bt.addActionListener(this);
cp.add(bt);
bt = new JButton("Show Plain Icon");
bt.addActionListener(this);
cp.add(bt);
bt = new JButton("Show User default Icon");
bt.addActionListener(this);
cp.add(bt);
f.pack();
f.setVisible(true);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}


@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String cmd = e.getActionCommand();
String title = "Message Dialog";
String message = "";
int type = JOptionPane.PLAIN_MESSAGE;
if(cmd.equals("Show Error Icon"));
{
type = JOptionPane.ERROR_MESSAGE;
message = "Error Message";
}
if(cmd.equals("Show Warming Icon"))
{
type = JOptionPane.WARNING_MESSAGE;
message = "Warming Message";
}
if(cmd.equals("Show Plain Icon"))
{
type = JOptionPane.PLAIN_MESSAGE;
message = "Plain Message";
}
if(cmd.equals("Show User default Icon"))
{
type = JOptionPane.PLAIN_MESSAGE;
message = "User Default Message";
JOptionPane.showMessageDialog(f, message, title, type, new ImageIcon("2.gif"));
return;
}
JOptionPane.showMessageDialog(f, message, title, type);

}
public static void main(String[] args)
{
new JOptionPaneDemo01();
}


}

你可能感兴趣的:(JavaSwing图形界面编程)