谢谢了 帮看看新手不会啊
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class JOptionPaneExample extends JFrame {
private JButton but1;
private JButton but2, but3;
public JOptionPaneExample(){
super("JOptionExample对话框组合");
Container c= getContentPane();
c.setLayout(new GridLayout(2,2,20,20));
but1=new JButton("按钮1");
c.add(but1);
but1.addActionListener(new handle());
but1=new JButton("按钮2");
c.add(but2);
but1.addActionListener(new handle());
but1=new JButton("按钮3");
c.add(but3);
but1.addActionListener(new handle());
setSize(200,300);
show();
}
public class handle implements ActionListener{
public void actionPerformed(ActionEvent e) {
String title="信息对话框";
String content="显示对话框内容";
int dialogtype=JOptionPane.PLAIN_MESSAGE;
if(e.getSource()==but1){
title="信息message duihuankuagn";
dialogtype=JOptionPane.INFORMATION_MESSAGE ;
JOptionPane.showMessageDialog(null,content,title,dialogtype);
}
else if(e.getSource()==but2){
title="信息message2 duihuankuagn";
dialogtype=JOptionPane.QUESTION_MESSAGE ;
JOptionPane.showMessageDialog(null,content,title,dialogtype);
}
else if (e.getSource()==but3){
title="信息message3 duihuankuagn";
dialogtype=JOptionPane.QUESTION_MESSAGE ;
JOptionPane.showInputDialog(null,content,title,dialogtype);
}
}
public void main(String[] args){
JOptionPaneExample app=new JOptionPaneExample();
}
}
}