本文整理匯總了Java中javax.swing.JOptionPane.showOptionDialog方法的典型用法代碼示例。如果您正苦於以下問題:Java JOptionPane.showOptionDialog方法的具體用法?Java JOptionPane.showOptionDialog怎麽用?Java JOptionPane.showOptionDialog使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JOptionPane
的用法示例。
在下文中一共展示了JOptionPane.showOptionDialog方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: closeApplication
import javax.swing.JOptionPane; //導入方法依賴的package包/類
private void closeApplication() {
int response = JOptionPane.showOptionDialog(myCP, "Exit AIMerger?", "Exit",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null,
JOptionPane.YES_OPTION);
switch (response) {
default:
// This should never happen
throw new IllegalArgumentException("not an option");
case JOptionPane.CLOSED_OPTION:
case JOptionPane.CANCEL_OPTION:
offerNewMerge();
break;
case JOptionPane.OK_OPTION:
System.exit(0);
break;
}
}
示例2: errorDialogue
import javax.swing.JOptionPane; //導入方法依賴的package包/類
private void errorDialogue(String messageString, int whichField) {
Object[] message = {messageString};
Object[] options = {"OK"};
int n = JOptionPane.showOptionDialog(new JFrame(),
message, "Alert!",
JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null,
options, options[0]);
if(JOptionPane.ERROR_MESSAGE == n && whichField == 0){
this.addStudentFullName.setText("");
} else if(n == JOptionPane.ERROR_MESSAGE && whichField == 1){
this.addStudentID.setText("171-15-XXXX");
} else if(n == JOptionPane.ERROR_MESSAGE && whichField == 2){
this.addFathersNameField.setText("");
} else if(n == JOptionPane.ERROR_MESSAGE && whichField == 3){
this.addMothersNameField.setText("");
} else if(n == JOptionPane.ERROR_MESSAGE && whichField == 4){
displayUpdateStudentPanel(true, false);
} else if(n == JOptionPane.ERROR_MESSAGE && whichField == 5){
panelVisiblity(true, false, false, false);
} else if(n == JOptionPane.ERROR_MESSAGE && whichField == 6){
loginVisiblity(true, false);
} else {
//DO NOTHING JUST DISPLAY MESSAGE
}
}
示例3: offerNewMerge
import javax.swing.JOptionPane; //導入方法依賴的package包/類
private void offerNewMerge() {
int response = JOptionPane.showOptionDialog(myCP, "Projects Successfully Merged. "
+ "Would you like to merge more projects?", "Projects Merged", JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, null, JOptionPane.YES_OPTION);
switch (response) {
default:
// This should never happen
throw new IllegalArgumentException("not an option");
case JOptionPane.CLOSED_OPTION:
case JOptionPane.NO_OPTION:
closeApplication();
break;
case JOptionPane.YES_OPTION:
offerToMergeToNewProject();
break;
}
}
示例4: getDupAction
import javax.swing.JOptionPane; //導入方法依賴的package包/類
int getDupAction(String url) {
JTextField txt = new JTextField(url, 30);
String lbl = StringResource.getString("DUP_TXT");
JComboBox choice = new JComboBox(new String[] { StringResource.getString("DUP_OP1"),
StringResource.getString("DUP_OP2"), StringResource.getString("DUP_OP3") });
JCheckBox chk = new JCheckBox(StringResource.getString("DUP_CHK"));
int ret = JOptionPane.showOptionDialog(null, new Object[] { txt, lbl, choice, chk },
StringResource.getString("DUP_TITLE"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
null, null);
if (ret == JOptionPane.OK_OPTION) {
int index = choice.getSelectedIndex();
if (chk.isSelected()) {
config.duplicateLinkAction = index;
}
return index;
}
return -1;
}
示例5: checkCard
import javax.swing.JOptionPane; //導入方法依賴的package包/類
public Card checkCard(Card card)
{
if(card.getPointValue() == 1)
{
Object[] options =
{
"1 Point!",
"11 Points!"
};
int ask = JOptionPane.showOptionDialog(rootPane,
"You drew an Ace. Would you like it to be worth 1 or 11 points?",
"Blackjack Game",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, options, options[0]);
if(ask == 1)
card.setPointValue(11);
else
card.setPointValue(1);
}
return card;
}
示例6: errorMessage
import javax.swing.JOptionPane; //導入方法依賴的package包/類
public static void errorMessage(Exception exceptionMsg, boolean quiet) {
/**
* Display Jpanel Error messages any SQL Errors. Overloads
* errorMessage(String e)
*/
Object[] options = { "OK", };
JOptionPane.showOptionDialog(null, exceptionMsg, messagerHeader,
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE, null,
options, options[0]);
if (!quiet) {
exceptionMsg.printStackTrace();
}
// DatabaseManagerSwing.StatusMessage(READY_STATUS);
}
示例7: showExceptionDialog
import javax.swing.JOptionPane; //導入方法依賴的package包/類
private void showExceptionDialog(Exception e) {
Object[] buttonTexts = {
Messages.PLUGIN_EXCEPTION_DIALOG_BUTTON_OK,
Messages.PLUGIN_EXCEPTION_DIALOG_BUTTON_EXIT,
Messages.PLUGIN_EXCEPTION_DIALOG_BUTTON_IGNORE
};
String message = String.format(
Messages.PLUGIN_EXCEPTION_DIALOG_MESSAGE,
plugin.getClass().getSimpleName(),
String.valueOf(e.getMessage())
);
int buttonIndex = JOptionPane.showOptionDialog(
null,
message,
Messages.PLUGIN_EXCEPTION_DIALOG_TITLE,
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
buttonTexts,
buttonTexts[0]
);
if (buttonIndex == 1) {
System.exit(0);
}
ignoreExceptions = buttonIndex == 2;
}
示例8: showDirectionsPopup
import javax.swing.JOptionPane; //導入方法依賴的package包/類
public void showDirectionsPopup() {
ImageIcon ico = MenuMaker.get16xIcon(getClass().getClassLoader().getResource("32x/intel.png"));
JButton[] options = new JButton[2];
JButton nahButton = GUIController.generateOkayButton(null, display);
nahButton.setText("I already know how to play");
nahButton.setFocusable(false);
options[0] = nahButton;
JButton openLink = new JButton(
"<html> <a href=\"\">https://en.wikipedia.org/wiki/Advance_Wars#Gameplay</a></html>");
openLink.setIcon(ico);
openLink.setFocusable(false);
openLink.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(new URI("https://en.wikipedia.org/wiki/Advance_Wars#Gameplay"));
} catch (Exception exept) {
/* TODO: error handling */
}
} else {
/* TODO: error handling */
}
}
});
options[1] = openLink;
JOptionPane.showOptionDialog(this, "Please see the following page (click link below):\n" + ""
+ "\nI added quite a few more Units to the game." + "\nCommanding Officers are not yet implemented\n"
+ "\nIn short, click a unit you wish to move, where to move, and what to do"
+ "\n To win, capture the enemy HQ or destroy all enemy units!", "How to Play", 0, 0, ico, options, 0);
}
示例9: btnSairActionPerformed
import javax.swing.JOptionPane; //導入方法依賴的package包/類
private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
Object[] options = {"Sim", "Não"};
if (JOptionPane.showOptionDialog(null, "Deseja mesmo sair da aplicação?", "Cadastro de Usuários",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]) == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
示例10: windowClosing
import javax.swing.JOptionPane; //導入方法依賴的package包/類
@Override
public void windowClosing(WindowEvent arg0) {
Player player = StateHandler.player;
if (player != null && StateHandler.getState().equals(States.GAME) || StateHandler.getState().equals(States.PAUSE)) {
if (StateHandler.getState().equals(States.GAME)) StateHandler.pause();
int confirm = JOptionPane.showOptionDialog(null, "Would you like to save?", "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm == 0) {
DataHandler.savePlayer(player);
}
}
System.exit(0);
}
示例11: getCredential
import javax.swing.JOptionPane; //導入方法依賴的package包/類
Credential getCredential(String shost, String suser, String spass) {
JTextField host = new JTextField(shost);
JTextField user = new JTextField(suser);
JPasswordField pass = new JPasswordField(spass);
Object[] obj = new Object[6];
obj[0] = getString("HOST");
obj[1] = host;
obj[2] = getString("USER_NAME");
obj[3] = user;
obj[4] = getString("PASSWORD");
obj[5] = pass;
while (JOptionPane.showOptionDialog(null, obj, getString("LBL_CR"),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
null, null, null) == JOptionPane.OK_OPTION) {
if (host.getText() == null || host.getText().length() < 1) {
JOptionPane.showMessageDialog(null, getString("LBL_HOST"));
continue;
}
if (user.getText() == null || user.getText().length() < 1) {
JOptionPane.showMessageDialog(null, getString("LBL_USER"));
continue;
}
Credential c = new Credential();
c.host = host.getText();
c.user = user.getText();
c.pass = pass.getPassword().length > 0 ? new String(pass
.getPassword()) : null;
return c;
}
return null;
}
示例12: btnExcluirActionPerformed
import javax.swing.JOptionPane; //導入方法依賴的package包/類
private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
int linha = tabelaHospital.getSelectedRow();
Object[] options = {"Sim", "Não"};
if (linha == -1) {
JOptionPane.showMessageDialog(rootPane, "Selecione uma linha!");
} else if (JOptionPane.showOptionDialog(null, "Deseja mesmo excluir esse Cadastro?", "Excluir Cadastro",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]) == JOptionPane.YES_OPTION) {
hospital = hospitalDAO.pesquisarHospitalPorID((int) tabelaHospital.getValueAt(linha, 0));
hospitalDAO.deletar(hospital);
JOptionPane.showMessageDialog(null, "Cadastro excluído com sucesso");
atualizarTabela();
}
}
示例13: actionRemoverItem
import javax.swing.JOptionPane; //導入方法依賴的package包/類
private void actionRemoverItem(){
remItem = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (tabelaItem.getSelectedRow()==-1){
JOptionPane.showMessageDialog(null, "Selecione o registro a ser apagado","Alerta", JOptionPane.PLAIN_MESSAGE);
return;
}
Object[] options = {"Sim", "Não"};
int n = JOptionPane.showOptionDialog(null, "Deseja realmente apagar o registro: "+tabelaItem.getSelectedRow(), "Alerta", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE, null, options,options[0] );
if (n == 1){
return;
}
// Realiza o calculo dos campos valorTotal e quantidade
int quant = -1 + Integer.parseInt(quantidadeItens.getText());
quantidadeItens.setText("" + quant);
String j =""+tabelaItem.getValueAt(tabelaItem.getSelectedRow(), 4);
double valorF = - Double.parseDouble(j) + Double.parseDouble(valorTotal.getText());
valorTotal.setText("" + valorF);
// Somente após o calculo é removida a linha da tabela
modelItem.removeRow(tabelaItem.getSelectedRow());
}
};
}
示例14: actionPerformed
import javax.swing.JOptionPane; //導入方法依賴的package包/類
public void actionPerformed(ActionEvent e) {
String currentFileName = TEdit.getCurrentFileName();
Object[] options = {"Cancel",
"No",
"Yes"};
int n = JOptionPane.showOptionDialog(TEdit.getFrame(),
"Would you like to save "+ currentFileName +" ?",
"Save",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
if(n == 0)
return;
if(n==2){
if(currentFileName.contentEquals("Untitled"))
TEdit.saveFileAs();
else
TEdit.saveFile(currentFileName);
}
if(n==1){
TEdit.updateTextArea("","Untitled");
TEdit.setEnabled("SaveAs",true);
}
//displayResult("Action for first button/menu item", e);
}
示例15: processAssertionError
import javax.swing.JOptionPane; //導入方法依賴的package包/類
/**
* Processes assertion errors by showing a warning dialog to the user
* and pausing the simulation (if it's running)
* @param e The error that was thrown
*/
private void processAssertionError(AssertionError e) {
String title = e.getClass().getSimpleName() + " (simulation paused)";
String msg = e.getMessage();
String txt = (msg != null ? msg : "") + " at simtime " +
SimClock.getIntTime() + "\n\ncaught at:\n" +
e.getStackTrace()[0].toString() +
"\nNote that the simulation might be in inconsistent state, "+
"continue only with caution.\n\n Show rest of the stack trace?";
// rest of the update cycle that caused the exception is skipped
// so the user is warned about the consequences
if (guiControls != null) {
guiControls.setPaused(true);
}
int selection = JOptionPane.showOptionDialog(getParentFrame(), txt,
title, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
null, null, null);
if (selection == 0) {
txt = "";
for (StackTraceElement trace : e.getStackTrace()) {
txt += trace.toString()+"\n";
}
JOptionPane.showMessageDialog(getParentFrame(), txt,
"stack trace", JOptionPane.INFORMATION_MESSAGE);
}
}