当前位置: 代码迷 >> Java相关 >> 求助!!java中如何弹出提示信息框?????
  详细解决方案

求助!!java中如何弹出提示信息框?????

热度:322   发布时间:2008-09-24 20:57:51.0
求助!!java中如何弹出提示信息框?????
各位高手们请教如何在java中如何让窗口中弹出信息提示框?
搜索更多相关的解决方案: java  提示  

----------------解决方案--------------------------------------------------------
MessageBox.show("要显示的字符串","标题",消息框按钮,消息框图标)
这样就可以啦!
----------------解决方案--------------------------------------------------------
package bc;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;

public class Frametest extends JFrame {
    public Frametest() {
        try {
            this.setSize(400,300);
            this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
            this.setVisible(true);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        jButton1.setBounds(new Rectangle(134, 126, 135, 55));
        jButton1.setText("jButton1");
        jButton1.addActionListener(new Frametest_jButton1_actionAdapter(this));
        this.getContentPane().add(jButton1);
    }

    public static void main(String[] args) {
        Frametest frametest = new Frametest();
    }

    JButton jButton1 = new JButton();
    public void jButton1_actionPerformed(ActionEvent e) {
       JOptionPane.showMessageDialog(null, "成功");
    }
}


class Frametest_jButton1_actionAdapter implements ActionListener {
    private Frametest adaptee;
    Frametest_jButton1_actionAdapter(Frametest adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}
----------------解决方案--------------------------------------------------------
JOptionPane里面很多方法都可以。
如JOptionPane.show...Dialog
----------------解决方案--------------------------------------------------------
  相关解决方案