private class ShowAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent event) {
if(typePanel.getSelection().equals("Confirm")) {
//Confirm: 要显示的信息, 标题, 显示操作的类型, 显示的信息的类型
JOptionPane.showConfirmDialog(OptionDialogFrame.this, getMessage(), "Title",
getType(optionTypePanel), getType(messageTypePanel));
} else if(typePanel.getSelection().equals("Input")) {
if(inputPanel.getSelection().equals("Text field")) {
JOptionPane.showInputDialog(OptionDialogFrame.this, getMessage(), "Title", getType(messageTypePanel));
} else {
JOptionPane.showInputDialog(OptionDialogFrame.this, getMessage(), "Title", getType(messageTypePanel),
null, new String[] {"Yellow", "Blue", "Red"}, "Blue");
}
} else if(typePanel.getSelection().equals("Message")) {
JOptionPane.showMessageDialog(OptionDialogFrame.this, getMessage(), "Title", getType(messageTypePanel));
} else if(typePanel.getSelection().equals("Option")) {
JOptionPane.showOptionDialog(OptionDialogFrame.this, getMessage(), "Title", getType(optionTypePanel),
getType(messageTypePanel), null, getOptions(), getOptions()[0]);
}
}
}
@Override
public void actionPerformed(ActionEvent event) {
if(typePanel.getSelection().equals("Confirm")) {
//Confirm: 要显示的信息, 标题, 显示操作的类型, 显示的信息的类型
JOptionPane.showConfirmDialog(OptionDialogFrame.this, getMessage(), "Title",
getType(optionTypePanel), getType(messageTypePanel));
} else if(typePanel.getSelection().equals("Input")) {
if(inputPanel.getSelection().equals("Text field")) {
JOptionPane.showInputDialog(OptionDialogFrame.this, getMessage(), "Title", getType(messageTypePanel));
} else {
JOptionPane.showInputDialog(OptionDialogFrame.this, getMessage(), "Title", getType(messageTypePanel),
null, new String[] {"Yellow", "Blue", "Red"}, "Blue");
}
} else if(typePanel.getSelection().equals("Message")) {
JOptionPane.showMessageDialog(OptionDialogFrame.this, getMessage(), "Title", getType(messageTypePanel));
} else if(typePanel.getSelection().equals("Option")) {
JOptionPane.showOptionDialog(OptionDialogFrame.this, getMessage(), "Title", getType(optionTypePanel),
getType(messageTypePanel), null, getOptions(), getOptions()[0]);
}
}
}
本文介绍了一个使用Java Swing创建不同类型对话框的示例代码,包括确认对话框、输入对话框、消息对话框及选项对话框等。通过该示例可以了解如何根据不同场景选择合适的对话框类型,并设置其标题、消息内容及显示方式。
401

被折叠的 条评论
为什么被折叠?



