Solved

JOptionPane problem

Posted on 2004-04-26
16
273 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
  • 9
  • 4
16 Comments
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
... 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
Comment Utility
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
Comment Utility
I may have misunderstand your comment.

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

Thanks...!!
0
 
LVL 16

Expert Comment

by:gnoon
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 16

Expert Comment

by:gnoon
Comment Utility
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
Comment Utility
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
Comment Utility
Can you tell me where i m doing a mistake....????
0
 
LVL 16

Accepted Solution

by:
gnoon earned 20 total points
Comment Utility
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
Comment Utility
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
Comment Utility
???????????????????????

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
Comment Utility
>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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now