Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4568988
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:09:17+00:00 2026-05-21T19:09:17+00:00

I searched through a few pages, but most seem to be just having comprehension

  • 0

I searched through a few pages, but most seem to be just having comprehension issues as to what static means.The problem I have lies in that we are using a static class, FocusListener, and ActionListener. The class that has the event handling calls on the static class, and when a JTextfield is fill and tabbed away from FocusListener updates that static variable instantly. When all JTextfields are filled and FocusListener has updated the variables, there is a submit JButton. As soon as the button is clicked, the static methods are called to finish of any variables that are calculated using the previously updated variables. User is not aware of this. The variables do not update though, and I am curious if I am implementing this wrong? Thanks in advance.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class WellParameters extends JInternalFrame implements FocusListener, ActionListener {
    JLabel  measuredDepthL, ..., pitGainL, drillBitSizeL, 
                mudInActivePitsL, mainPanelLabel;
        JTextField  measuredDepthT, ..., pitGainT, drillBitSizeT, mudInActivePitsT;
        JPanel  mainPanel, firstPanel, secondPanel, thirdPanel, fourthPanel, submitButtonPanel;
        JButton submitButton;

        WellParameters() {  
            super("Well Parameters", true, true, false, true);
            this.setBounds(0, 0, 600, 385);
            this.setVisible(true);
            this.setLayout(new BorderLayout());

            ...//GUI Stuff

            this.add(submitButtonPanel, BorderLayout.SOUTH);
        }
    @Override
    public void focusGained(FocusEvent e) {} //Ignore this!

    @Override
    public void focusLost(FocusEvent e) {
        try {
            if(e.getSource() == measuredDepthT) {
                KillWellCalculations.measuredDepth = Integer.parseInt(measuredDepthT.getText());

              ...//Others 

            } else if(e.getSource() == mudInActivePitsT) {
                KillWellCalculations.mudInActivePits = Double.parseDouble(mudInActivePitsT.getText());
            }
        } catch (Exception ignore) {}

    }
    @Override
    public void actionPerformed(ActionEvent e) {
        try {
            if(e.getSource() == submitButton) {
            System.out.println(KillWellCalculations.pumpEfficiency);
            KillWellCalculations.setPressureBeforeCasingBurstAndFormationFracture(); //Doesn't work
            KillWellCalculations.setCirculatingPressures();
            KillWellCalculations.setTriplexPumpCapacity();
            System.out.println(KillWellCalculations.mudInActivePits);
            System.out.println(KillWellCalculations.pumpFactor);
            System.out.println(KillWellCalculations.finalCirculatingPressure);}
        }
        catch(Exception ignore) {}
    }
}

That was the GUI, and this is the static class… They are 2 separate classes. Not in the same file.
package killwellsheet;

public class KillWellCalculations {

    static int measuredDepth;           //Total Depth from open hole to bottom

        ... //Tons of other variables

    static double totalStrokes;         //add strokes

    //Used to set different circulating pressures for the well
    public static void setCirculatingPressures() {
        initialCirculatingPressure = circulatingPressureKillRate + shutInDrillPipePressure;
        finalCirculatingPressure = circulatingPressureKillRate * (killMudWeight/currentMudWeight);
    }   
    //Calculates capacity of anypipe
    private static double pipeCapacity(double length, double insideDiameter) {
        return length * ((insideDiameter*insideDiameter)/1029.4);
    }
    //Calculates capacity of the annulus/open hole
    private static double annulusCapacity(double length, double insideDiameter, double outsideDiameter) {
        return length * (((insideDiameter*insideDiameter)-(outsideDiameter*outsideDiameter))/1029.4);
    } 

         ... //Other functions

    //Set the casing burst pressure
    public static void setPressureBeforeCasingBurstAndFormationFracture() {
        beforeCasingBurst = burstPressure*0.70;
        beforeFormationFracture = (0.052*casingShoeDepth)*(fracGradientMWEquivalent - currentMudWeight);
    }
    public static void bariteNeedAndVolumeIncrease() {
        bariteSacksRequired = (totalMudVolume/100)*((1099*(killMudWeight-currentMudWeight))/(28.35-killMudWeight));
        increaseInMudVolume = 0.091*bariteSacksRequired;
    }
    public static void pumpStrokes() {
        surfaceToBit = (mudInDrillString)/pumpFactor;
        bitToSurface = (mudInAnnulus)/pumpFactor;
        totalStrokes = surfaceToBit + bitToSurface;
    }
}//end class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:09:18+00:00Added an answer on May 21, 2026 at 7:09 pm

    Some clarifications… By reading your code, the only thing I see is that your class WellParameters implements the Interfaces FocusListener and ActionListener (not static classes). As far as I can figure out from your code, the methods focusGained(FocusEvent e) and focusLost(FocusEvent e) are implemented from the former Interface and updates the values of the static class, and you would depend on same calculated values in the ActionListener event actionPerformed(). The problem you are facing here is race-condition regarding the static instance values.

    http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html
    A.3.4 Unreachable

    An object enters an unreachable state
    when no more strong references to it
    exist. When an object is unreachable,
    it is a candidate for collection. Note
    the wording: Just because an object is
    a candidate for collection doesn’t
    mean it will be immediately collected.
    The JVM is free to delay collection
    until there is an immediate need for
    the memory being consumed by the
    object. It’s important to note that
    not just any strong reference will
    hold an object in memory. These must
    be references that chain from a
    garbage collection root. GC roots are
    a special class of variable that
    includes

  2. Temporary variables on the stack (of any thread)
  3. Static variables (from any class)
  4. Special references from JNI native code
  5. Based on this Garbage Collection documentation, I suspect that ALL the static references of your class KillWellCalculations were eligible to be garbage collected after the call to the FocusEvent methods and, for this reason, they are not available by the time the event actionPerformed() is fired.

    You can still use the static methods of the class KillWellCalculations as a utility class only if this class is used by other classes. If not, you can transform it into a Value class that holds the calculations for you, WITHOUT the static references. As you need to have a reference to an instance of a class that holds the values of the calculation… For instance:

    public Class CalculatedValues {
         private int measuredDepth;
         private double mudInActivePits;
    
         public static CalculatedValues makeNew() {
              return new CalculatedValues();
         }
    
         public void setMeasuredDepth(String measuredDepthTString) {
               if (measuredDepthTString == null) {
                    throw new IllegalArgumentException("The measured depth must be provided.");
               }
               try {
                    this.measuredDepth = Integer.parseInt(measuredDepthTString);
               } catch(NumberFormatException nfe) {
                    throw new IllegalArgumentException("The value provided is not an interger.");
               }
         }
         public int getMeasuredDepth() {
              return measuredDepth;
         }
    
         public void setMudInActivePitsT(String mudInActivePitsTString) {
               if (mudInActivePitsTString == null) {
                    throw new IllegalArgumentException("The measured mudInActivePits must be provided.");
               }
               try {
                    this.mudInActivePits = Double.parseDouble(measuredDepthTString);
               } catch(NumberFormatException nfe) {
                    throw new IllegalArgumentException("The value provided is not an double.");
               }
         }
         public double getMeasuredDepth() {
              return mudInActivePits;
         }
    
         //...
         //...
         // MORE THE OTHER VALUES/PROPERTIES IMPORTANT/NEEDED BY THE CALCULATION. 
    
         public void doAllCalculations() {
              // YOU HAVE TO IMPLEMENT THE LOGIC FOR THOSE ONES, OPTIONALLY USING THE SAME UTILITY/HELPER STATIC METHODS FROM 
              setPressureBeforeCasingBurstAndFormationFracture();
              setCirculatingPressures();
              setTriplexPumpCapacity();
         }
    }
    

    Then, modify the constructor of the class to have an instance of the value object:

    ... 
    ...
    // THE VALUE OBJECT REFERENCE WITH THE VALUES YOU NEED TO HOLD DURING THE FORM INTERACTION
    private CalculatedValues calculatedValues;
    
    WellParameters() {  
        super("Well Parameters", true, true, false, true);
        this.setBounds(0, 0, 600, 385);
        this.setVisible(true);
        this.setLayout(new BorderLayout());
    
        ...//GUI Stuff
    
        this.add(submitButtonPanel, BorderLayout.SOUTH);
    
        // THE VALUE OBJECT REFERENCE...
        calculatedValues = CalculatedValues.makeNew();
    }
    

    Then, update the reference with the calculation:

    @Override
    public void focusLost(FocusEvent e) {
        try {
            if(e.getSource() == measuredDepthT) { 
                //KillWellCalculations.measuredDepth = Integer.parseInt(measuredDepthT.getText());
                // the exceptions thrown can be caught in the catch below and you can display the error message from the value class.
                calculatedValues.setMeasuredDepth(measuredDepthT.getText());
    
              ...//Others 
    
                // collect other values as well...
    
            } else if(e.getSource() == mudInActivePitsT) {
                //KillWellCalculations.mudInActivePits = Double.parseDouble(mudInActivePitsT.getText());
                // do try/catch for the possible runtime exception and display an error message
                calculatedValues.setMudInActivePitsT(mudInActivePitsT.getText());
    
            }
        } catch (Exception ignore) { 
        }
    
    }
    

    The the updates on the final step also using the instance reference:

      @Override
        public void actionPerformed(ActionEvent e) {
          try {
            if(e.getSource() == submitButton) {
            System.out.println(KillWellCalculations.pumpEfficiency);
            // THE REFERENCES THAT THIS STATIC METHOD USE WERE ALL GARBAGE-COLLECTED AT THE TIME OF THE CALL... IF SHOULD HAVE THE CALCULATED METHODS IN THE VALUE CLASS. SOMETHING LIKE THE FOLLOWING:
            // KillWellCalculations.setPressureBeforeCasingBurstAndFormationFracture(); //Doesn't work
            //KillWellCalculations.setCirculatingPressures();
            //KillWellCalculations.setTriplexPumpCapacity();
            //System.out.println(KillWellCalculations.mudInActivePits);
            //System.out.println(KillWellCalculations.pumpFactor);
            //System.out.println(KillWellCalculations.finalCirculatingPressure);}
    
            // DO THE FINAL CALCULATION IN A SINGLE METHOD IN THE VALUE OBJECT.
            calculatedValues.doAllCalculations();
    
            // HERE ARE THE GETTERS FROM THE CALCULATED VALUES OF THE DO ALL CALCULATIONS YOU HAVE TO IMPLEMENT.
            System.out.println(calculatedValues.getMudInActivePits());
            System.out.println(calculatedValues.getPumpFactor());
            System.out.println(calculatedValues.getFinalCirculatingPressure());}
    
            // CONSIDERING YOU'RE DONE WITH THE VALUES, JUST CLEAR THE INSTANCE VALUES
            // AS THIS REFERENCE IS NOT STATIC AND IT WILL NOT BE GARBAGE-COLLECTED. 
            calculatedValues.clearValues();
        }
        catch(Exception ignore) {}
      }
    

    I did some work way back related to GUI… You can see a very similar example at http://code.google.com/p/marcellodesales-cs-research/source/browse/trunk/grad-ste-ufpe-brazil/ptf-add-on-dev/src/br/ufpe/cin/stp/ptfaddon/view/swing/execution/JWizardInternalFrame.java

    Good Luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched through many times but have not seen this before. Probably really
So I have searched through a few question here regarding the AlertDialog, and I'm
Firstly, I have searched for related answers, there is a few - but couldn't
I have searched through for this logic pretty much everywhere but am sure I
I have searched through Google, SO and Android developers but I need some further
i searched through Stack overflow but fail to find a solution in regards to
I have searched through internet & found that there are no any direct method
I've searched through the other expected Class Name error questions on here, but they
although I searched through existing threads for my problem I havent found a solution
I've searched through the documentation and searched around but there is nothing said about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.