JOptionPane problem

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
raaz007Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
gnoonConnect With a Mentor Commented:
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
 
sciuriwareCommented:
... 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
 
raaz007Author Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
raaz007Author Commented:
I may have misunderstand your comment.

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

Thanks...!!
0
 
gnoonCommented:
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
 
raaz007Author Commented:
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
 
raaz007Author Commented:
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
 
raaz007Author Commented:
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
 
gnoonCommented:
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
 
raaz007Author Commented:
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
 
raaz007Author Commented:
Can you tell me where i m doing a mistake....????
0
 
raaz007Author Commented:
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
 
raaz007Author Commented:
???????????????????????

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
 
gnoonCommented:
>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
All Courses

From novice to tech pro — start learning today.