How to code a Cancel button in a frame

hello..i'm new to java..and i'm currently working on a project that displays a 'Quiz' screen, meaning a new frame from the main frame..
the problem is, how do i code the Cancel button in the 'Quiz' frame so that only the 'Quiz' frame disappears and leave the main frame for user to view? i've tried using setDefaultCloseOperation( EXIT_ON_CLOSE ); but it seems that it closes all the program..and i don't want that.
how should i do it??
please help me..thanks

1. Check out my StandardDialog class as an example of how to implement a cancel button
2. use either the HIDE_ON_CLOSE or DISPOSE_ON_CLOSE standard closing operations

Similar Messages

  • How to disable the cancel button in InputDialogBox?

    Can someone please tell me how to disable the cancel button in an input dialog box?
    thanks,

    Cross posted: [http://www.coderanch.com/t/487888/Swing-AWT-SWT-JFace/java/disable-cancel-button-input-dialog]

  • How to use the cancel button in showInputDialog

    um how would i go with overriding the cancel button's deafult function in JOptionPane.showInputDialog?
    in my code:
    package alphaOne;
    * this program takes in a number and gets the factorial of that number
    import javax.swing.*;
    public class Factorial {
         public Factorial() {
               * variables intilization, input is where the option pane puts the data
               * number is teh actucal number entered parsed from string result is
               * where the resutl is stored flag1 is the indicator if the user had
               * entered an integer
              String input;
              int flag1 = 0;
              int number = 0;
              long result = 0;
               * this while loop runs continously unless an integer is entered
              while (flag1 != 1)
                   try {
                        input = JOptionPane
                                  .showInputDialog("Enter the number to be factored, Integer only: ");
                        number = Integer.parseInt(input);
                        flag1 = 1;
                   } catch (NumberFormatException ea) {
                        JOptionPane.showMessageDialog(null,
                                  "The input was not a integer!", "Warning",
                                  JOptionPane.ERROR_MESSAGE);
              result = number;
              for (int x = 1; x < number; x++) {
                   result = result * (x);
              JOptionPane.showMessageDialog(null, "The result is: " + result,
                        "Result", JOptionPane.CLOSED_OPTION);
              try {
                   System.exit(0);
              } catch (SecurityException ea) {
                   System.out.print("ARRRRR its dead!");
         public static void main(String[] args) {
              Factorial One = new Factorial();
    }the cancel button does not break the while loop

    what is the value of null compared to when you compare it, and do we use the String.equals() or the String == null to compare? as seen in here i tried with input.equals(null) as a comparison but it deos not exit when i press cancel
    package alphaOne;
    * this program takes in a number and gets the factorial of that number
    import javax.swing.*;
    public class Factorial {
         public Factorial() {
               * variables intilization, input is where the option pane puts the data
               * number is teh actucal number entered parsed from string result is
               * where the resutl is stored flag1 is the indicator if the user had
               * entered an integer
              String input;
              boolean flag1 = false;
              int number = 0;
              long result = 0;
               * this while loop runs continously unless an integer is entered
              while (flag1 != true){
                   try {
                        input = JOptionPane
                                  .showInputDialog("Enter the number to be factored, Integer only: ");
                        number = Integer.parseInt(input);
                        System.out.println(input);
                        flag1 = true;
                        if (input.equals(null))
                             try {
                                  System.exit(0);
                             } catch (SecurityException ea) {
                                  System.out.print("ARRRRR its dead!");
                   } catch (NumberFormatException ea) {
                        JOptionPane.showMessageDialog(null,
                                  "The input was not a integer!", "Warning",
                                  JOptionPane.ERROR_MESSAGE);
              result = number;
              for (int x = 1; x < number; x++) {
                   result = result * (x);
              JOptionPane.showMessageDialog(null, "The result is: " + result,
                        "Result", JOptionPane.INFORMATION_MESSAGE);
              try {
                   System.exit(0);
              } catch (SecurityException ea) {
                   System.out.print("ARRRRR its dead!");
         public static void main(String[] args) {
              Factorial One = new Factorial();
    }i have also tried to ue input == null, input == "", input.equals(""), input.equals(" ")
    Message was edited by:
    TheHolyLancer
    i edited the part so it is bold
    Message was edited by:
    TheHolyLancer

  • How to handle the "cancel" button and "close" icon of a popup ?

    Hi,
    I have a popup with "cancel button" and "close icon"(on the top right corner of the popup), I want the same operations to be performed on clicking of any of these two components.
    Is there a way to handle such situation ?
    I read about 2 cases to look into this but they didn't work too well for me.
    1. I read about the "popcancellistener" but that listener is called whenever the popup closes, so suppose I have an "ok button" on the popup to create a record, after the record is created, the popup closes and goes into the "popcancellistener", now the question is "how do we know if it came there because of the 'ok button' or 'some other event'".
    2. I even checked the "DialogListener", now I'm able to distinguish between the 'OK' and 'CANCEL' button in the dialoglistener using the "Dialog.Outcome.ok/cancel", but when a user clicks on the close icon, we do not enter the "DialogListener" at all, so in this case "how do we handle the close icon click event"
    Do let me know if you need any more information from my side.
    Thanks for the help in advance.

    The following mechanism responds to any of the following events: <Esc> key, Close icon ('x'), Cancel button
    JavaScript part:
    function popupClosedListener(event){
                  var source = event.getSource();
                  var popupId = source.getClientId();
                  var params = {};
                  params['popupId'] = popupId;
                  var type = "serverPopupClosed";
                  var immediate = true;
                  AdfCustomEvent.queue(source, type, params, immediate);
    }JSF part:
             <af:popup ....>
                  <af:clientListener method="popupClosedListener"
                                           type="popupClosed"/>
                  <af:serverListener type="serverPopupClosed"
                                          method="#{myBean.serverPopupClosedMetod}"/>
            </af:popup>Finally, Java part:
    public void serverPopupClosedMetod(ClientEvent event){
    }

  • How to enable the "Cancel button" so you can stop a report while loading ...

    I have seen that some reports have a Cancel button located just below "the loading ..".
    How can I enable that button in MS Reporting service 2005?

    The following mechanism responds to any of the following events: <Esc> key, Close icon ('x'), Cancel button
    JavaScript part:
    function popupClosedListener(event){
                  var source = event.getSource();
                  var popupId = source.getClientId();
                  var params = {};
                  params['popupId'] = popupId;
                  var type = "serverPopupClosed";
                  var immediate = true;
                  AdfCustomEvent.queue(source, type, params, immediate);
    }JSF part:
             <af:popup ....>
                  <af:clientListener method="popupClosedListener"
                                           type="popupClosed"/>
                  <af:serverListener type="serverPopupClosed"
                                          method="#{myBean.serverPopupClosedMetod}"/>
            </af:popup>Finally, Java part:
    public void serverPopupClosedMetod(ClientEvent event){
    }

  • How to disable the cancel button in the ProgressMonitor

    hi,
    I need to know, is there any way to disable/remove the (cancel)button in the ProgressMonitor?
    One more problem is,
    Once i click the cancel button, isCanceled() return true, how to make it false again so that the process continue....
    It is very urgently.....
    please help me out.
    Thanks in advance.
    Regards,
    Deepa Raghuraman

    I don't think that's a good solution, because Cancel button itself is not disabled, so user is tempted to click it and nothing happens.
    A better but dangerous solution is this:
    progressMonitor = new ProgressMonitor(ProgressMonitorDemo.this,
                                         "Running a Long Task",
                                         "", 0, 100);
    progressMonitor.setMillisToDecideToPopup(0);
    progressMonitor.setMillisToPopup(0);
    progressMonitor.setProgress(0);
    JDialog dialog = (JDialog)progressMonitor.getAccessibleContext().getAccessibleParent();
    JOptionPane pane = (JOptionPane)dialog.getContentPane().getComponent(0);
    pane.setOptions(new Object[]{});Refer to the same question here [http://stackoverflow.com/questions/512151/how-do-i-disable-the-cancel-button-when-using-javax-swing-progressmonitor] .

  • How to show ok & cancel button using showMessageDialog

    hi to all, when i use showMessageDialog it gives only ok option,
    like
    JOptionPane.ShowMessageDialog(null,"are you sure you want to continue" ,"Confirmation",JOptionPane.QUESTION_MESSAGE);
    this statement shows only ok option, i want ok and cancel option both.
    and can u tell me how to put actions in ok & cancel option
    like if user clicks ok option then he can continue the program , if user clicks cancel then he would exit from the program.
    can u tell how to comapre that using if statement
    please reply me as soon as possible.

    This is probably close to what you want. I believe messages can be replaced by null. You can probably figure out the rest from the API.
    response = JOptionPane.showConfirmDialog(myFrame,
                                             messages,
                                            "Delete hard drive?",
                                             JOptionPane.OK_CANCEL_OPTION);
    // If User hit CANCEL button we jump out
    if (response == JOptionPane.CANCEL_OPTION)
        return;

  • How to code the Back button

    Hi everyone,
    In my application on a perticular jsp page i had a back button.On clicking this back button one should go to the previous page.Can anyone suggest me how to code for this particular back button as all my efforts to code that button are in vain. I need this urgent.
    Hope you will help me,

    <input type="button" name="back" value="back" onclick="history.go(-1)">

  • How to code a NEXT button

    Hello everyone,
    I am developing an web application in jsp.As a part of this application i need to get a list of records from the database.As per my code all the records are being listed in the same page. But i want to display some 50-100 records per page and keep a NEXT button on each page so that when the user clicks on this button he can go to the next set of records.But i am not getting an idea abt how to code this.So can anyone help me in this regard or just give me an idea of how to print a certain no. of records per page and the NEXT button coding.

    Is your application only jsp or struts or jsp/Helper java classes?
    In any case, assuming that the number of records are not very large, it is better to avoid repeated DB calls. The common way to implement this is to fetch all the records and store it in a data structure(an ArrayList for eg:) in the session. You would also have to maintain another variable for the current last record number. On click of the next button, fetch the records from current last record to current last record + 50 (or 100 or infact, you can make this as a variable too) from the session ArrayList and show it in the same jsp. Also, update the current last record number.
    The other way around (if at all you have session considerations) is to make a new call to the DB everytime you click on Next.

  • How to use a cancel button........

    hello everyone,
                  i have a selection screen, from where i am calling a selection-screen as a pop-up screen. the fields i am checking on the pop-up screen will get append on the previous screen. now the problem i am facing with the cancel button.
        if i am pressing the cancel button still the checked fields are getting appended.
    i want to exit from the screen and want to keep the previous screen as it is. it is a simple report program.
    please help me out.
    thanks i advance.

    I am using set screen 0. and leave screen.
    but still the problem persists.
    let me tell you in detail.
    i am going to pop-up screen to get the fields appended on my previous screen.
    if i check some checkboxes on it and click ok then according to those checked fields the corresponding select-options should come on previous screen. 
    because i have added set screen 0. to 'OK'.
    now what i am facing is if i check some checkboxes on the pop-up and say 'CANCEL' still the program is appending the those checkboxes and appending them on the previous screen.
    what i am expecting is, it should exit the pop-up screen and should maintain the previous screen as it is.
    thanks

  • How to capture OK / Cancel Button response of warning type message in EBS D2K form using Form personalization

    Hi Experts
    We are working on one requirement in which on a standard D2K EBS form based on the response of a warning message we need to perform certain actions using Form Personalization.
    The problem is that we are not able to capture response of OK and Cancel buttons of the warning.
    If any one has come across such scenario, I would request to please share your valuable suggestions. 2898414
    Thank You
    Regards
    Mirza Tanzeel

    Figured out myself that this is mot possible using Form Personalization.
    Only option possible is to try implementing by modifying custom.pll
    Thanks
    Mirza Tanzeel

  • How to add Ok & Cancel Button--- [solved]

    Hi,
    i have two data blocks,M is master and D is detail
    if the user checks the check box in M and D,i want the user to have option of canceling the process by clicking cancel button or processed by clicking ok .
    i was able to create alert message for the user , but the user does not have the option of canceling the process when the message pop ups
              IF :M .CHECKBOX = 1 and D.CHECKBOX = 1 THEN
              message_handler_pkg.display_error('display message '||:M.dataitem,v_alert_response);
    thanks in advance
    Message was edited by:
    Rowdheer
    Message was edited by:
    Rowdheer

    Create an alert in your form with required no of buttons, u will have an option of upto 3 buttons . Use this alert along with your messaging options ..
    Provided your messaging package has options to include the alerts
    try this procedure !
    PROCEDURE disp_alert
              ( ALERT_NAME               IN     VARCHAR2,
              ALERT_MESSAGE          IN     VARCHAR2,
              ALERT_RETURN_VAL          OUT     NUMBER ) IS
         AL_ID ALERT;
         BEGIN
         AL_ID := FIND_ALERT(ALERT_NAME);
         SET_ALERT_PROPERTY(AL_ID,ALERT_MESSAGE_TEXT,ALERT_MESSAGE);
         ALERT_RETURN_VAL := SHOW_ALERT(AL_ID);
         IF IV_N_ALERT_RETURN_VAL = ALERT_BUTTON1 THEN
              ALERT_RETURN_VAL := 1;
         ELSIF IV_N_ALERT_RETURN_VAL = ALERT_BUTTON2 THEN
              ALERT_RETURN_VAL := 2;
         ELSIF IV_N_ALERT_RETURN_VAL = ALERT_BUTTON3 THEN
              ALERT_RETURN_VAL := 3;
         END IF;
    END;
    ssr

  • How to make 'Cancel' button go back to page before

    Hello,
    In Oracle Sales module there a lot of pages e.g. Customer, Oppty and Lead Histories etc. Where button 'Cancel' is used. I need to create one on custom page.
    The custom page is called from update contact page and 'Cancel' button should return user back to 'update contact' page. I copied/pasted oracle code but then my 'Cancel' button returning me to Sales Dashboard page not update contact.
    My page's controller when 'Cancel' is clicked executes:
    processTargetURL(oapagecontext, null, null);
    Could you please tell me how can i get Cancel button work properly?
    thanks a lot

    Hi,
    I am not sure, but are you looking for passing information through destination URL. In the case of a 'button' (not Submitbutton), you can set the destination URL like "OA.jsp?OAFunc=<func_name>&Parameter1={@value}"
    Also if you use setForwardURL, then you can pass parameters in a Hashmap. See the syntax of Hashmap.
    public void setForwardURL(String url,
    String functionName,
    byte menuContextAction,
    String menuName,
    com.sun.java.util.collections.HashMap parameters, //note this
    boolean retainAM,
    String addBreadCrumb,
    byte messagingLevel)
    This way your requirement to send multiple parameters together can be addressed.
    Hope that helps.
    Thanks

  • Stopping a thread from "cancel" button

    Hello all,
    I have a problem trying to stop a thread. I have a class that hits database and retrieves lots of data. This retrieval can take a long time if lots of data, so I have a progress bar displayed. This progress bar has a cancel button. I am not sure how to link the cancel button to the thread so the thread can exit. See code below for example of whats going on:
    public class MainApp {
      public void doWork() {
        ProgressBar pbar = new ProgressBar();
        pbar.show();
        DatabaseThread dbThread = new DatabaseThread();
        dbThread.run();
    public class ProgressBar {
      // displays a progress bar with cancel button
    public class DatabaseThread extends Thread {
      public void run() {
        // hit database
    }So how am I to cancel the DatabaseThread class from the ProgressBar class. Thanks for all suggestions!

    what i said is that you need to hava a reference to your thread ine the class that handle the progressBar.
    and in your Thread class you create a method like setCanceled(boolean b)...
    public MyThread extends Thread{
       private boolean canceled = false;
       public void setCanceled(boolean b){
          canceled = b;
       public void run(){
          while(!canceled){
            //do your stuff

  • CANCEL button processing

    hi all,
           what is the code for cancel button meance without process of current screen leave to another transaction.
    thanx in advance.

    Define functional type = E for this 'CANCEL' button in gui status.
    In the PAI of the screen add MODULE EXIT_SCREEN at EXIT_COMMAND.
    Inside this module you should enter the following code:
    case sy-ucomm.
      when ''CANC'.
       If you want you can add a warning  here
         set screen 0. " This will take you back to the calling screen
         leave screen.
      when others.
    endcase.
    if you overwrote old values (from previous screen) in the current screen (that you are exiting) then make sure these changes are reverted. I am guessing this happends automatically, its been a while since I worked on screen ...
    Raj

Maybe you are looking for

  • Código de Status 109

    Boa Tarde, Estamos com a situação de um rejeição de 9 Nfe que estão retornando o código de status 109 - Serviço Paralisado sem Previsão da SEFAZ-MT. Como podemos alterar esse código de status, para que o nota fiscal possa ser reenviado para a Sefaz?

  • Solaris 2.6 Patch cluster

    Is there anyone out there knows where I can get the last Solaris 2.6 patch cluster? I know it's de-supported now but sadly some legacy applications are still out there and need to run on old software/hardware. Many thanks in advance, Jonathan

  • How can I remove and reinstall Bridge CC?

    I started the installation of Bridge CC from Creative Cloud and then tried to cancel it to make an installation change.  My Creative Cloud console now shows that Bridge CC is installed, but it does not run.  Neither is it listed in Programs and Featu

  • Importing DVD on iTunes???

    I'm not able to put my dvd's that I own on my iTunes movie library. Please help. I know I can purchase movies from the iTunes store, but I also know there is a way to import my movies to iTunes. I called Apple and they said it's possible but they are

  • Firefox says it is "done" loading but all i see is a white screen

    any page i try to load it says it is "done" loading but the screen is blank. it isn't a specific page but any one that i try.