Я просмотрел несколько страниц, но у большинства, похоже, просто проблемы с пониманием того, что означает static. Проблема, с которой я столкнулся, заключается в том, что мы используем статический класс, FocusListener и ActionListener. Класс, у которого есть обработка событий, вызывает статический класс, и когда поле JText заполнено и удалено от FocusListener, мгновенно обновляет эту статическую переменную. Когда все поля JText заполнены и FocusListener обновил переменные, появляется JButton отправки. Как только кнопка нажата, статические методы вызываются для завершения любых переменных, которые вычисляются с использованием ранее обновленных переменных. Пользователь об этом не знает. Однако переменные не обновляются, и мне любопытно, неправильно ли я это реализую? Заранее спасибо.
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) {}
}
}
Это был графический интерфейс, а это статический класс... Это два отдельных класса. Не в том же файле. пакет 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