`
haitian235
  • 浏览: 61396 次
  • 性别: Icon_minigender_1
  • 来自: 海南
社区版块
存档分类
最新评论

Swing JDialogTest实现

阅读更多

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class JDialogTest extends JFrame implements ActionListener{
JButton b1=new JButton("showMessageDialog");
JButton b2=new JButton("showConfirmDialog");
JButton b3=new JButton("showOptionDialog");
JButton b4=new JButton("showInputDialog");
JDialogTest(){
getContentPane().setLayout(new GridLayout(2,2));
getContentPane().add(b1);
getContentPane().add(b2);
getContentPane().add(b3);
getContentPane().add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
setSize(250,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1)
JOptionPane.showMessageDialog(null,"你点击了消息对话框","showMessageDialog",JOptionPane.INFORMATION_MESSAGE);
else if(e.getSource()==b2)
JOptionPane.showConfirmDialog(null,"你点击了确认对话框","showConfirmDialog",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE);
else if(e.getSource()==b3){
Object[] str={"asp","vb","java"};
JOptionPane.showOptionDialog(null,"请选择一门课程","showOptionDialog",JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE,null,str,str[1]);
}
else if(e.getSource()==b4){
    String inputValue = JOptionPane.showInputDialog("Please input a value"); }
}
public static void main(String[] args){
new JDialogTest();
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics