1、建议你看看jdk自带的例子程序;
2、下面的代码是例子程序中的一个对话框,不知道你需要用户输入、选择还是其他,如果比较特殊,可以自己设计对话框,其中包含的元素自己定制。
public JButton createComponentDialogButton() {
Action a = new AbstractAction(getString("OptionPaneDemo.componentbutton")) {
public void actionPerformed(ActionEvent e) {
// In a ComponentDialog, you can show as many message components and
// as many options as you want:
// Messages
Object[] message = new Object[4];
message[0] = getString("OptionPaneDemo.componentmessage");
message[1] = new JTextField(getString("OptionPaneDemo.componenttextfield"));
// Options
String[] options = {
getString("OptionPaneDemo.component_op1"),
getString("OptionPaneDemo.component_op2"),
getString("OptionPaneDemo.component_op3"),
getString("OptionPaneDemo.component_op4"),
getString("OptionPaneDemo.component_op5")
};
int result = JOptionPane.showOptionDialog(
getDemoPanel(), // the parent that the dialog blocks
message, // the dialog message array
getString("OptionPaneDemo.componenttitle"), // the title of the dialog window
JOptionPane.DEFAULT_OPTION, // option type
JOptionPane.INFORMATION_MESSAGE, // message type
null, // optional icon, use null to use the default icon
options, // options string array, will be made into buttons
options[3] // option that should be made into a default button
);
switch(result) {
case 0: // yes
JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r1"));
break;
case 1: // no
JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r2"));
break;
case 2: // maybe
JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r3"));
break;
case 3: // probably
JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r4"));
break;
default:
break;
}