Solved

JOptionPane problem

Posted on 2004-04-26
16
287 Views
Last Modified: 2010-03-31
Hi, I am getting a problem while displaying the JOptionPanes....I am doing in the following manner

if (e.getSource() == but_Submit) {
      if (!chk_Order.isSelected()) { //some condition
        checkStatusType(); // This mehtod has JOptionPane
        checkHours(); //This too has JOptionPane
        checkWorkers(); //This too has JOptionPane


        if (txt_Name.getText().equalsIgnoreCase("")) {
          JOptionPane.showMessageDialog(null,
                                        "Name must be entered");
          txt_Name.requestFocus();
        }

       if (txt_Desc.getText().equalsIgnoreCase("")) {
          JOptionPane.showMessageDialog(null,
                                        "Desc must be entered");
          txt_Desc.requestFocus();
        }


What is heepening right now, all the JOptionPanes are displayed if the conditons are not satisfied. I want one JOptionPane message to be displayed at a time.

e.g. , if the condition in checkStatusType() is not satisfied, show only that JOptionPane and so on.

I hope u understood my problem....I wud appreciate for an immediate response. Thanks
0
Comment
Question by:raaz007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
16 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 10921283
... immediate response ...  for 20 points!

Well, I think that you are firing your popups from an ActionHandler (actionPerformed() ).
So you are working inside the dispatch thread on that moment.
Some activities there must be 'invoked' by SwingUtilities.invokeAndWait() or .invokeLater().
In fact: you can't move if you stand on your tail (if you were a cat or so).

;JOOP!
0
 

Author Comment

by:raaz007
ID: 10922274
Wats this, if you dont know or dont want to answer you shud not accept the question itself. Who asked you to accept it.

I didn't understand the meaning of having more points. Since I have less points remaining i gave 20 points....!!!!
0
 

Author Comment

by:raaz007
ID: 10922666
I may have misunderstand your comment.

I wud appreciate if u can elaborate more on the same.

Thanks...!!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:gnoon
ID: 10924493
try this

if (e.getSource() == but_Submit) {

      boolean shown = false;

      if (!chk_Order.isSelected()) { //some condition
        shown = checkStatusType(); // This mehtod has JOptionPane, should returns a boolean.
        if(shown) return; // break out if there's something wrong about status type
        shown = checkHours(); //This too has JOptionPane
        if(shown) return; // break out if there's something wrong about hours
        shown = checkWorkers(); //This too has JOptionPane
        if(shown) return; // break out if there's something wrong about workers


        if (txt_Name.getText().equalsIgnoreCase("")) {
          JOptionPane.showMessageDialog(null,
                                        "Name must be entered");
          txt_Name.requestFocus();
          return;
        }

       if (txt_Desc.getText().equalsIgnoreCase("")) {
          JOptionPane.showMessageDialog(null,
                                        "Desc must be entered");
          txt_Desc.requestFocus();
          return;
        }

so the dialog will show by step. Is this you want to do?
0
 

Author Comment

by:raaz007
ID: 10929707
It works in the same way as it was working...I changed all my functions to boolean which returns boolean and also modified the code the way u have mentioned but it still shows all JOptionPanes as it was showing earliear.

0
 

Author Comment

by:raaz007
ID: 10929749
I am doing it as follows:

if (e.getSource() == but_Submit) {
     if (!chk_Order.isSelected()) {
        boolean shown = false;
        shown = checkStatusType();
        if (shown) return;
        shown = checkHours();
        if (shown) return;
        shown = checkWorkers();
        if (shown) return;
        //checkStatusType();
        //checkHours();
        //checkWorkers();

if (txt_Name.getText().equalsIgnoreCase("")) {
          JOptionPane.showMessageDialog(null,
                                        "Name must be entered");
          txt_Name.requestFocus();
          return;
        }

       if (txt_Desc.getText().equalsIgnoreCase("")) {
          JOptionPane.showMessageDialog(null,
                                        "Desc must be entered");
          txt_Desc.requestFocus();
          return;
        }


If anything wrong here, pls do let me know...!!!

0
 

Author Comment

by:raaz007
ID: 10933441
I am pasting the written in one of the method:

public boolean checkStatusType() {
    String str_Status = null;
    try {

      stmt = con_Time.createStatement();
      String query_Status =
          "select time_entry_id,work_order_number,Work_order_step from tt_time_entry " +
          "where craft_id in(select craft_id from tt_craft where craft_name = '" +
          txt_Craft.getText() + "') " +
          "and zone_id in(select zone_id from tt_zone where zone_name = '" +
          txt_Zone.getText() + "') " +
          "and entry_date=TO_DATE('" + txt_Date.getText() + "','mm/dd/yyyy')" +
          "and WORK_ORDER_TYPE_ID=0 AND Status_id=0";

      ResultSet rs_Status = stmt.executeQuery(query_Status);

      //Loop through each column, getting the column data and displaying
      while (rs_Status.next()) {
        str_Status = rs_Status.getString(1);
      }
      rs_Status.close();

      if (str_Status.equals(null)) {
      }
      else {
        JOptionPane.showMessageDialog(null, "All Work Orders must have Status and Type assigned");
      }

      stmt.close();
    }
    catch (Exception sqe) {
      sqe.printStackTrace();
      //JOptionPane.showMessageDialog(null, "System Error: Call the help desk@8333. Time of Error: " + now);
    }
    //return str_Status;
    //return false;
    return true;
  }


Let me know if you didn't understand the code...!!!!
0
 
LVL 16

Expert Comment

by:gnoon
ID: 10934503
I suggest you to break out the function whenever it shows the first message/error dialog, include checkStatusType() function.

public boolean checkStatusType() {
    String str_Status = null;
    try {

      stmt = con_Time.createStatement();
      String query_Status =
          "select time_entry_id,work_order_number,Work_order_step from tt_time_entry " +
          "where craft_id in(select craft_id from tt_craft where craft_name = '" +
          txt_Craft.getText() + "') " +
          "and zone_id in(select zone_id from tt_zone where zone_name = '" +
          txt_Zone.getText() + "') " +
          "and entry_date=TO_DATE('" + txt_Date.getText() + "','mm/dd/yyyy')" +
          "and WORK_ORDER_TYPE_ID=0 AND Status_id=0";

      ResultSet rs_Status = stmt.executeQuery(query_Status);

      //Loop through each column, getting the column data and displaying
      while (rs_Status.next()) {
        str_Status = rs_Status.getString(1);
      }
      rs_Status.close();

      if (str_Status.equals(null)) {
      }
      else {
        JOptionPane.showMessageDialog(null, "All Work Orders must have Status and Type assigned");
        return true; // so the caller( of this function )'ll knows that a dialog was shown.
      }

      stmt.close();
    }
    catch (Exception sqe) {
      sqe.printStackTrace();
      //JOptionPane.showMessageDialog(null, "System Error: Call the help desk@8333. Time of Error: " + now);
      return true;
    }
    //return str_Status;
    return false;
    //return true;
  }
0
 

Author Comment

by:raaz007
ID: 10939860
I did it in the same way what you have mentioned for all three methods. Error meassage works fine for first method, I mean if there is error in 1st method. But it doesn't work fro remaining it doesn't do anything upon clicking Submit button...!!!!!!!

Though I had written the code in the event of Submit button as follows:


if (e.getSource() == but_Submit) {
     if (!chk_Order.isSelected()) {
        boolean shown = false;
        shown = checkStatusType();
        if (shown) return;
        shown = checkHours();
        if (shown) return;
        shown = checkWorkers();
        if (shown) return;
        //checkStatusType();
        //checkHours();
        //checkWorkers();

if (txt_Name.getText().equalsIgnoreCase("")) {
          JOptionPane.showMessageDialog(null,
                                        "Name must be entered");
          txt_Name.requestFocus();
          return;
        }

       if (txt_Desc.getText().equalsIgnoreCase("")) {
          JOptionPane.showMessageDialog(null,
                                        "Desc must be entered");
          txt_Desc.requestFocus();
          return;
        }
0
 

Author Comment

by:raaz007
ID: 10943795
Can you tell me where i m doing a mistake....????
0
 
LVL 16

Accepted Solution

by:
gnoon earned 20 total points
ID: 10945164
My understand is you're trying to make data constraints process, and the process will start whenever a button is clicked .. right?
While the process is running and the 1st invalid occur, it'll promts to user and breaks out itseft after user clicked OK.
So let me know my misunderstand.

If that right, the process will be the code inside the actionPerformed(), includes deep code in the callee method. What you need to do is break out from the method(actionPerformed) if the 1st error is found. If the error occur in the deep part (e.g inside checkStatusType), it should break out itself and tells the upper(actionPerformed) to break out too.

If you still stuck, please post the part/whole of code that wouldn't work.
0
 

Author Comment

by:raaz007
ID: 10949654
I had already pasted the whole code if you can see above. Now I am pasting it once more.......



Code of one of the method......!!

public boolean checkStatusType() {
    String str_Status = null;
    try {

      stmt = con_Time.createStatement();
      String query_Status =
          "select time_entry_id,work_order_number,Work_order_step from tt_time_entry " +
          "where craft_id in(select craft_id from tt_craft where craft_name = '" +
          txt_Craft.getText() + "') " +
          "and zone_id in(select zone_id from tt_zone where zone_name = '" +
          txt_Zone.getText() + "') " +
          "and entry_date=TO_DATE('" + txt_Date.getText() + "','mm/dd/yyyy')" +
          "and WORK_ORDER_TYPE_ID=0 AND Status_id=0";

      ResultSet rs_Status = stmt.executeQuery(query_Status);

      //Loop through each column, getting the column data and displaying
      while (rs_Status.next()) {
        str_Status = rs_Status.getString(1);
      }
      rs_Status.close();

      if (str_Status.equals(null)) {
      }
      else {
        JOptionPane.showMessageDialog(null, "All Work Orders must have Status and Type assigned");
        return true; // so the caller( of this function )'ll knows that a dialog was shown.
      }

      stmt.close();
    }
    catch (Exception sqe) {
      sqe.printStackTrace();
      //JOptionPane.showMessageDialog(null, "System Error: Call the help desk@8333. Time of Error: " + now);
      return true;
    }
    //return str_Status;
    return false;
    //return true;
  }




Code in the actionPerformed() .......!!!!!!!!!!!

if (e.getSource() == but_Submit) {
     if (!chk_Order.isSelected()) {
        boolean shown = false;
        shown = checkStatusType();
        if (shown) return;
        shown = checkHours();
        if (shown) return;
        shown = checkWorkers();
        if (shown) return;
        //checkStatusType();
        //checkHours();
        //checkWorkers();

if (txt_Name.getText().equalsIgnoreCase("")) {
          JOptionPane.showMessageDialog(null,
                                        "Name must be entered");
          txt_Name.requestFocus();
          return;
        }

       if (txt_Desc.getText().equalsIgnoreCase("")) {
          JOptionPane.showMessageDialog(null,
                                        "Desc must be entered");
          txt_Desc.requestFocus();
          return;
        }



Thats all I have. I mean I have pasted the code once again. Hope this makes sense to you....Let me know if you can..Thanks
0
 

Author Comment

by:raaz007
ID: 10949664
???????????????????????

My understand is you're trying to make data constraints process, and the process will start whenever a button is clicked .. right?
While the process is running and the 1st invalid occur, it'll promts to user and breaks out itseft after user clicked OK.
So let me know my misunderstand.


Yeah, this is what I want to achieve.....u r right
0
 
LVL 16

Expert Comment

by:gnoon
ID: 10955361
>Yeah, this is what I want to achieve.....u r right

I told you the solution in my previous comment, did you try it?

>Error meassage works fine for first method, I mean if there is error in 1st method. But it doesn't work fro remaining it doesn't do anything upon clicking Submit button...!!!!!!!

A little confusion, my understand is your first method is *checkStatusType()*, so you have no problem with it now, but why you post it code when I said "post the part/whole of code that wouldn't work." ??
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question