Application Techniques



Displaying Dialogs

How to display various kinds of dialogs from a form.

About this technique

Details

Category

Java Client Techniques> Dialogs and subforms

Description

You'll learn about:

You can run this technique code from:

NOTE   First make sure that database is running on your localhost SilverStream Server

Related reading

See the chapter on programming forms in the Programmer's Guide

Displaying a message dialog   Top of page

The following code shows how to display a message box in response to a user clicking on a button.:

  private void handle_btnShowMessage_actionPerformed(ActionEvent evt) 
  { 
  // Reset label values 
  lblResultValue.setText(""); 
  lblMethod.setText(""); 
   
  agDialog.showMessage("Example message", "Display your message 
     here."); 
  lblMethod.setText("public void showMessage(String message)" + 
  "\npublic void showMessage(String caption, String message)"); 
  } 
   

Notes about the code

Displaying an OK/Cancel dialog   Top of page

The following code shows how to display an OK/Cancel dialog in response to the user clicking the OK/Cancel button. The code gets the user's response from the dialog box and sets the form's RESULT label appropriately.

  private void handle_btnOKCancel_actionPerformed(ActionEvent evt) 
  { 
    // Reset label values 
    lblResultValue.setText(""); 
    lblMethod.setText(""); 
   
    boolean response = agDialog.showMessageOKCancel("OK or Cancel", 
    "Question which requires confirmation or cancellation."); 
    if (response) 
      lblResultValue.setText("true"); 
    else 
      lblResultValue.setText("false"); 
    lblMethod.setText("public boolean showMessageOKCancel(String 
      caption, String message)" + 
        "\n\nReturns 'true' if OK, otherwise 'false'."); 
  } 

Notes about the code

Displaying a Yes/No dialog   Top of page

The following code shows how to display a Yes/No dialog in response to the user clicking the Yes/No button, making it the current focus. The code gets the user's response from the dialog box and sets the form's RESULT label appropriately.

  private void handle_btnYesNo_actionPerformed(ActionEvent evt) 
  { 
    // Reset label values 
    lblResultValue.setText(""); 
    lblMethod.setText(""); 
     
    boolean response; 
    response = agDialog.showMessageYesNo("OK or Cancel", "Question 
      which requires a Yes or No answer."); 
    if (response) 
      lblResultValue.setText("true"); 
    else 
      lblResultValue.setText("false"); 
    lblMethod.setText("public boolean showMessageYesNo(String 
      caption, String message)" + 
         "\n\nReturns 'true' if Yes, otherwise 'false'."); 
  } 

Notes about the code

Displaying a Yes/No/Cancel dialog   Top of page

The following code shows how to display a Yes/No/Cancel dialog in response to the user clicking the Yes/No/Cancel button, making it the current focus. The code gets the user's response from the dialog box and sets the form's RESULT label appropriately.

  private void handle_btnYesNoCancel_actionPerformed(ActionEvent evt) 
  { 
     // Reset labels 
      lblResultValue.setText(""); 
      lblMethod.setText(""); 
       
       Boolean response = agDialog.showMessageYesNoCancel("Yes, No  
        or Cancel", "Question which requires a Yes or No answer, 
         or cancellation."); 
      if (response == null) 
        lblResultValue.setText("null"); 
      else if (response.booleanValue()) 
        lblResultValue.setText("true"); 
      else 
        lblResultValue.setText("false"); 
      lblMethod.setText("public Boolean 
       showMessageYesNoCancel(String caption,  
         String message)" + 
          "\n\nReturns 'null' if Cancel, 'true' if Yes,  
              otherwise 'false'."); 
  } 

Notes about the code

Displaying an error message dialog   Top of page

The following code attempts to create a substring (beginning at index=1) from a null string. Since this attempt results in an error, the system throws an exception. In the catch block, the exception handles the exception by displaying the error message in a dialog. This dialog has Error as its title and contains an OK button, which the user clicks to close the dialog.

  private void handle_btnDisplayError_actionPerformed(ActionEvent evt) 
    { 
       Reset labels 
       lblResultValue.setText(""); 
       lblMethod.setText(""); 
       try 
       { 
         String s = "".substring(1); 
       } 
       catch (Exception e) 
       { 
         agDialog.displayError(e); 
       } 
    } 

Notes about the code

Displaying a form for editing data in a dialog   Top of page

The following code displays a form as a modal dialog box. The form it displays is named dlgExample, which is stored in the Examples3_Java database. The code passes the contents of the record shown in the DATA RETURNED FROM SHOW FORM DIALOG area to the dlgExample form. The user can use the dialog to change either the customer name or the order date of the displayed record. The code then passes the updated values in the dialog to the form and updates the record in the database.

  private void handle_btnShowFormDialog_actionPerformed(ActionEvent evt) 
    { 
      Reset Label values 
      lblResultValue.setText(""); 
      lblMethod.setText(""); 
   
      Hashtable example = new Hashtable(); 
      Object results[] = new Object[3]; 
      example.put("sParam", CustomerName.getText()); 
      example.put("iParam", 
         Integer.toString(CustomerID.getValue())); 
      example.put("dtParam", OrderDate.getValue()); 
      try 
      { 
        results = (Object[]) agDialog.showFormDialog 
          ("Example", "dlgExample", example); 
      } 
      catch (java.io.IOException e) 
      { 
        agDialog.displayError(e); 
        return; 
      } 
      catch (AgoApiException e) 
      { 
        agDialog.displayError(e); 
        return; 
      } 
      lblResultValue.setText("" + results[0]); 
      if (!((String)results[0]).equalsIgnoreCase("***cancel***")) 
      { 
        CustomerID.setValue(((Integer) results[1]).intValue()); 
        OrderDate.setValue((java.sql.Date) results[2]); 
        try 
        { 
          agData.updateRows(); 
          CustomerName.setText((String) results[0]); 
        } 
        catch (AgoApiException e) 
        { 
          agDialog.displayError(e); 
        } 
      } 
    } 

Notes about the code






Copyright © 2000, SilverStream Software, Inc. All rights reserved.