谢谢了 帮看看新手不会啊

mabin1121 2011-05-12 04:19:03
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();
}

}
}





...全文
87 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
mabin1121 2011-05-19
  • 打赏
  • 举报
回复
谢谢你啊 那个括弧括错地方了 (回复你的晚了 不好意思哈)
lvhongfen 2011-05-12
  • 打赏
  • 举报
回复


Lz的面板是不是不显示啊!
给类里面加上一个构造方法,然后在方法体里面写
super("吕红芬");//窗体的名称
this.setSize(400,300);设置窗体大小
this.setVisible(true);//设置窗体展示(“没有的话没法展示窗体的”)

23,403

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧