虎牙跟yy什么关系:关于JAVA

来源:百度文库 编辑:神马品牌网 时间:2024/05/08 05:12:52
请问有JAVA中有没有一个可以弹出窗口的一个类,窗口中要有两个按
钮(取消,确定),并且要能接收到用户是点了哪一个按钮!
就好像是VB中的MSGBOX()一样功能的!

请大家指点一下!
先谢了!

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

public class InputDialog implements ActionListener
{
JFrame f = null;
JLabel label = null;

public InputDialog()
{
f = new JFrame("OptionPane Demo");
Container contentPane = f.getContentPane();

JPanel panel = new JPanel();
panel.setLayout(new GridLayout(1,2));

JButton b = new JButton("Show Text Input");
b.addActionListener(this);
panel.add(b);
b = new JButton("Show ComboBox Input");
b.addActionListener(this);
panel.add(b);

label = new JLabel(" ",JLabel.CENTER);
contentPane.add(label,BorderLayout.NORTH);
contentPane.add(panel,BorderLayout.CENTER);
f.pack();
f.setVisible(true);

f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}

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

public void actionPerformed(ActionEvent e)
{
String cmd = e.getActionCommand();
String title = "Input Dialog";
String message ="您最熟悉哪一种程序语言?";
int messageType = JOptionPane.QUESTION_MESSAGE;
String[] values = {"JAVA","PHP","ASP","C++","VB"};
String result ="";

if(cmd.equals("Show Text Input")) {
result = JOptionPane.showInputDialog(f, message,
title, messageType);

} else if(cmd.equals("Show ComboBox Input")) {
result = (String)JOptionPane.showInputDialog(f, message,
title, messageType,null,values,values[0]);
}

if (result == null)
label.setText("您取消了对话框");
else{
label.setText("您输入:"+result);
}
}
}

java中没有这样现成的窗体,需要自己去编写代码

java中只有空白窗体,例如 javax.swing.JFrame