Ich bin ja fleißig dabei die letzten Tage... :autsch:
Ich gebe für eine Berechnung mehrere Daten in Textfeldern vor. Mein erster Ansatz war ein Knopf, mit dem ich die Berechnung starte und erst dann direkt vor der eigentlichen Berechnung alle Felder auslese. Jetzt arbeite ich daran, dass das Auslesen der Felder "intelligent" abläuft. Ich verwende Klassen, um die Daten der Textfelder zu speichern. PipeDataModel und FluidDataModel mit get und set Methoden für verschiedene Daten und eine Klasse mit statischen Funktionen für Berechnungen. Diesen Methoden werden dann die Daten-Klassen übergeben. Ich denke Events von den Textfelder abzufangen und die Eintragungen direkt vorzunehmen hat folgende Vorteile:
- Sobald die Daten im Textfeld eingetragen sind, sind sie auch in der Klasse PipeDataModel oder FluidDataModel gespeichert.
- Ich kann (wird später implementiert) direkt eine Konvertierung von den Eingabeeinheiten in die jeweilige Einheit, welche intern zur Berechnung verwendet wird, implementieren.
- Sind alle Daten vorhanden, kann die Berechnung automatisch durchgeführt werden. Wird ein Wert geändert, so wird direkt neu gerechnet (Threads, später).
Meine Anliegen:
1) Eure Meinung dazu?
2) Habt ihr einen Tip, wo man Beispiele über User Interfaces (Eingabeoberflächen) findet, die flexibel bzgl. der Einheiten ist? In Java selbst gibt es wohl etwas recht komfortables zur Konvertierung (habe ich von gelesen J.A.D.E.).
3) Welchen Listener implementiere ich am besten für die TextFelder? Der folgende Code reportet die Änderung jedes einzelnen Zeichens, was doch zu häufiger Neuberechnung (bei automatischer Neuberechnung, vielleicht einschränken auf nur alle 2 Sekunden neu rechnen oder so... *grübel*) führen würde:
Vielleicht sollte ich lieber mit nem ActionListener wie bei einem Button arbeiten? Hier bin ich noch etwas unsicher ob das überhaupt geht. Was ist empfehlenswert?
Um das ganze in einen Rahmen einordnen zu können schicke ich mal die gesamte Klasse mit. Ihr könnt bzgl. Aufgeräumtheit auf der "Kraut und Rüben"-Skala von 1 (top) bis 6 (flop) voten! Ne, mal im Ernst. Wäre toll, wenn ihr Feedback zu strukturellen Verbesserungen geben könnt. Wie schon gesagt bin ich mit dem Code hinter dem Button_Calculate Listener noch unzufrieden und möchte es wie oben beschrieben umsetzen.
Was ist die Strategie, um das ganze etwas mehr aufzuräumen? Ich bin einfach noch zu unerfahren. :?
Grüße
Sven
Ich gebe für eine Berechnung mehrere Daten in Textfeldern vor. Mein erster Ansatz war ein Knopf, mit dem ich die Berechnung starte und erst dann direkt vor der eigentlichen Berechnung alle Felder auslese. Jetzt arbeite ich daran, dass das Auslesen der Felder "intelligent" abläuft. Ich verwende Klassen, um die Daten der Textfelder zu speichern. PipeDataModel und FluidDataModel mit get und set Methoden für verschiedene Daten und eine Klasse mit statischen Funktionen für Berechnungen. Diesen Methoden werden dann die Daten-Klassen übergeben. Ich denke Events von den Textfelder abzufangen und die Eintragungen direkt vorzunehmen hat folgende Vorteile:
- Sobald die Daten im Textfeld eingetragen sind, sind sie auch in der Klasse PipeDataModel oder FluidDataModel gespeichert.
- Ich kann (wird später implementiert) direkt eine Konvertierung von den Eingabeeinheiten in die jeweilige Einheit, welche intern zur Berechnung verwendet wird, implementieren.
- Sind alle Daten vorhanden, kann die Berechnung automatisch durchgeführt werden. Wird ein Wert geändert, so wird direkt neu gerechnet (Threads, später).
Meine Anliegen:
1) Eure Meinung dazu?
2) Habt ihr einen Tip, wo man Beispiele über User Interfaces (Eingabeoberflächen) findet, die flexibel bzgl. der Einheiten ist? In Java selbst gibt es wohl etwas recht komfortables zur Konvertierung (habe ich von gelesen J.A.D.E.).
3) Welchen Listener implementiere ich am besten für die TextFelder? Der folgende Code reportet die Änderung jedes einzelnen Zeichens, was doch zu häufiger Neuberechnung (bei automatischer Neuberechnung, vielleicht einschränken auf nur alle 2 Sekunden neu rechnen oder so... *grübel*) führen würde:
Code:
jTextField_Density.getDocument().addDocumentListener(
new DocumentListener(){
public void insertUpdate(DocumentEvent e){
myFluidDataModel.setDensity(Double.valueOf(jTextField_Density.getText()));
}
public void changedUpdate(DocumentEvent e){
myFluidDataModel.setDensity(Double.valueOf(jTextField_Density.getText()));
}
public void removeUpdate(DocumentEvent e){
myFluidDataModel.setDensity(Double.valueOf(jTextField_Density.getText()));
}
});
Um das ganze in einen Rahmen einordnen zu können schicke ich mal die gesamte Klasse mit. Ihr könnt bzgl. Aufgeräumtheit auf der "Kraut und Rüben"-Skala von 1 (top) bis 6 (flop) voten! Ne, mal im Ernst. Wäre toll, wenn ihr Feedback zu strukturellen Verbesserungen geben könnt. Wie schon gesagt bin ich mit dem Code hinter dem Button_Calculate Listener noch unzufrieden und möchte es wie oben beschrieben umsetzen.
Was ist die Strategie, um das ganze etwas mehr aufzuräumen? Ich bin einfach noch zu unerfahren. :?
Grüße
Sven
Code:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
/**
* This class shall provide the graphics
* for doing a simple pressure loss calculation.
* That includes the following functionality:
* <ul>
* [*]Input Fields
* [*]Output Fields
* [*]Button to start Calculation
* [/list]
*
* @author sven
*
*/
public class BasicPressureLossToolGraphics extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane_Input = null;
private JSplitPane jSplitPane = null;
/*
* Menu
*/
private JMenuBar jJMenuBar = null;
private JMenu jMenu_File = null;
private JMenu jMenu_Help = null;
private JMenuItem jMenuItem_New = null;
private JMenuItem jMenuItem_Open = null;
private JMenuItem jMenuItem_Save = null;
private JMenuItem jMenuItem_SaveAs = null;
private JMenuItem jMenuItem_Exit = null;
private JMenu jMenu_Options = null;
private JMenuItem jMenuItem_Help = null;
private JMenuItem jMenuItem_About = null;
private JRadioButtonMenuItem jRadioButtonMenuItem_Colebrook = null;
private JRadioButtonMenuItem jRadioButtonMenuItem_Prandtl = null;
private JRadioButtonMenuItem jRadioButtonMenuItem_Nikuradse = null;
/*
* Graphics general
*/
private JTextField jTextField_MassFlow = null;
private JLabel jLabel_MassFlow = null;
private JLabel jLabel_Unit_MassFlow = null;
private JLabel jLabel_VolFlow = null;
private JTextField jTextField_VolFlow = null;
private JTextField jTextField_FrictionFactor = null;
private JLabel jLabel_Unit_VolFlow = null;
private JLabel jLabel_Heading_Input = null;
private JLabel jLabel_Density = null;
private JLabel jLabel_Unit_Density = null;
private JTextField jTextField_Density = null;
private JTextField jTextField_Viscosity = null;
private JLabel jLabel_Viscosity = null;
private JLabel jLabel_Unit_Viscosity = null;
private JLabel jLabel_Length = null;
private JTextField jTextField_Length = null;
private JLabel jLabel_UnitLength = null;
private JLabel jLabel_Diameter = null;
private JTextField jTextField_Diameter = null;
private JLabel jLabel = null;
private JPanel jPanel_Output = null;
private JLabel jLabel_Heading_Output = null;
private JLabel jLabel_PressureLoss = null;
private JTextField jTextField_PressureLoss = null;
private JLabel jLabel_Unit_Pressure = null;
private JTextField jTextField_FlowOutput = null;
private JLabel jLabel_FlowOutput = null;
private JLabel jLabel_Unit_FlowOutPut = null;
private JButton jButton_Calculate = null;
private JButton jButton_Diameter = null;
private JLabel jLabel_Roughness = null;
private JButton jButton_Roughness = null;
private JTextField jTextField_Roughness = null;
private JLabel jLabel_Unit_Roughness = null;
private JLabel jLabel_Velocity = null;
private JTextField jTextField_Velocity = null;
private JLabel jLabel1 = null;
private JLabel jLabel_Reynolds = null;
private JTextField jTextField_Reynolds = null;
private JButton jButton_fill = null;
/*
* Data needed for calculations is stored
* in the following data models.
*
*/
private PipeDataModel myPipeDataModel = null;
private FluidDataModel myFluidDataModel = null;
/*
* TODO: Get rid of data stored in
* single variables in our graphics
* class BasicPressureLossGraphics!
*
* Perhaps implement all text fields with
* change listeners that after a change
* the data is written directly into
* the DataModels. This could include
* intelligent unit conversion, format checks,
* emptying of the output fields...
*
* Right now the data is read from the
* text fields when the calculate button is
* pressed.
*/
private double innerDiameter = 0;
private double pipeRoughness = 0;
//private double reynolds = 0;
/*
* Testing...
*/
private JLabel jLabel_Warning_Reynolds = null;
private JLabel jLabel_FrictionFactor = null;
/**
* This is the default constructor
*/
public BasicPressureLossToolGraphics() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(331, 559);
this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Icons/rohr.png")));
this.setJMenuBar(getJJMenuBar());
this.setContentPane(getJSplitPane());
this.setResizable(false);
this.setPreferredSize(new Dimension(320, 526));
this.setTitle("Basic Pressure Loss");
// initialize Data storage
myFluidDataModel = new FluidDataModel();
myPipeDataModel = new PipeDataModel();
// set Listeners
initializeListeners();
initializeMenuListeners();
}
/**
* This method initializes jContentPane_Input
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane_Input() {
if (jContentPane_Input == null) {
jLabel_Unit_Roughness = new JLabel();
jLabel_Unit_Roughness.setBounds(new Rectangle(225, 240, 61, 16));
jLabel_Unit_Roughness.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Unit_Roughness.setText("mm");
jLabel_Roughness = new JLabel();
jLabel_Roughness.setBounds(new Rectangle(30, 240, 76, 16));
jLabel_Roughness.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Roughness.setText("Roughness");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(225, 210, 61, 16));
jLabel.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel.setText("mm");
jLabel_Diameter = new JLabel();
jLabel_Diameter.setBounds(new Rectangle(30, 210, 61, 16));
jLabel_Diameter.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Diameter.setText("Diameter");
jLabel_UnitLength = new JLabel();
jLabel_UnitLength.setBounds(new Rectangle(225, 180, 61, 16));
jLabel_UnitLength.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_UnitLength.setText("m");
jLabel_Length = new JLabel();
jLabel_Length.setBounds(new Rectangle(30, 180, 91, 16));
jLabel_Length.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Length.setText("Length");
jLabel_Unit_Viscosity = new JLabel();
jLabel_Unit_Viscosity.setBounds(new Rectangle(225, 135, 61, 16));
jLabel_Unit_Viscosity.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Unit_Viscosity.setText("cP");
jLabel_Viscosity = new JLabel();
jLabel_Viscosity.setBounds(new Rectangle(30, 135, 91, 16));
jLabel_Viscosity.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Viscosity.setText("Viscosity");
jLabel_Unit_Density = new JLabel();
jLabel_Unit_Density.setBounds(new Rectangle(225, 105, 61, 16));
jLabel_Unit_Density.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Unit_Density.setText("<html>kg/m<sup>3</sup></html>");
jLabel_Density = new JLabel();
jLabel_Density.setBounds(new Rectangle(30, 105, 91, 16));
jLabel_Density.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Density.setText("Density");
jLabel_Heading_Input = new JLabel();
jLabel_Heading_Input.setBounds(new Rectangle(15, 15, 106, 15));
jLabel_Heading_Input.setFont(new Font("Dialog", Font.BOLD, 12));
jLabel_Heading_Input.setText("Input Values:");
jLabel_Unit_VolFlow = new JLabel();
jLabel_Unit_VolFlow.setBounds(new Rectangle(225, 75, 61, 16));
jLabel_Unit_VolFlow.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Unit_VolFlow.setText("<html>m<sup>3</sup>/hr</html>");
jLabel_VolFlow = new JLabel();
jLabel_VolFlow.setBounds(new Rectangle(30, 75, 91, 16));
jLabel_VolFlow.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_VolFlow.setText("Vol. Flow");
jLabel_Unit_MassFlow = new JLabel();
jLabel_Unit_MassFlow.setBounds(new Rectangle(225, 45, 46, 16));
jLabel_Unit_MassFlow.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Unit_MassFlow.setText("kg/hr");
jLabel_MassFlow = new JLabel();
jLabel_MassFlow.setBounds(new Rectangle(30, 45, 91, 16));
jLabel_MassFlow.setToolTipText("");
jLabel_MassFlow.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_MassFlow.setText("Mass Flow");
jContentPane_Input = new JPanel();
jContentPane_Input.setLayout(null);
jContentPane_Input.add(getJTextField_MassFlow(), null);
jContentPane_Input.add(jLabel_MassFlow, null);
jContentPane_Input.add(jLabel_Unit_MassFlow, null);
jContentPane_Input.add(jLabel_VolFlow, null);
jContentPane_Input.add(getJTextField_VolFlow(), null);
jContentPane_Input.add(jLabel_Unit_VolFlow, null);
jContentPane_Input.add(jLabel_Heading_Input, null);
jContentPane_Input.add(jLabel_Density, null);
jContentPane_Input.add(jLabel_Unit_Density, null);
jContentPane_Input.add(getJTextField_Density(), null);
jContentPane_Input.add(getJTextField_Viscosity(), null);
jContentPane_Input.add(jLabel_Viscosity, null);
jContentPane_Input.add(jLabel_Unit_Viscosity, null);
jContentPane_Input.add(jLabel_Length, null);
jContentPane_Input.add(getJTextField_Length(), null);
jContentPane_Input.add(jLabel_UnitLength, null);
jContentPane_Input.add(jLabel_Diameter, null);
jContentPane_Input.add(getJTextField_Diameter(), null);
jContentPane_Input.add(jLabel, null);
jContentPane_Input.add(getJButton_Calculate(), null);
jContentPane_Input.add(getJButton_Diameter(), null);
jContentPane_Input.add(jLabel_Roughness, null);
jContentPane_Input.add(getJButton_Roughness(), null);
jContentPane_Input.add(getJTextField_Roughness(), null);
jContentPane_Input.add(jLabel_Unit_Roughness, null);
jContentPane_Input.add(getJButton_fill(), null);
}
return jContentPane_Input;
}
/**
* This Method initializes general Listeners.
*
*/
private void initializeListeners(){
jTextField_Density.getDocument().addDocumentListener(
new DocumentListener(){
public void insertUpdate(DocumentEvent e){
myFluidDataModel.setDensity(Double.valueOf(jTextField_Density.getText()));
}
public void changedUpdate(DocumentEvent e){
myFluidDataModel.setDensity(Double.valueOf(jTextField_Density.getText()));
}
public void removeUpdate(DocumentEvent e){
myFluidDataModel.setDensity(Double.valueOf(jTextField_Density.getText()));
}
});
/*
* This method calculates all values
* required for the output fields.
*
* First collect all necessary data and
* then write calculated data to output fields.
*
*/
jButton_Calculate.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
/*
* Write Text Field Data to FluidDataModel.
* Watch the standard units!!
*/
// //myFluidDataModel = new FluidDataModel(
// Double.valueOf(jTextField_Density.getText()),
// Double.valueOf(jTextField_Viscosity.getText())*1E-3
// );
/*
* Determine the standard flow format massFlow
*/
double massFlow;
if (jTextField_MassFlow.isEnabled()) {
massFlow = Double.valueOf(jTextField_MassFlow.getText())/3600;
//volFlow = massFlow/roh;
//jTextField_FlowOutput.setText(formatFlow.format(volFlow*3600));
}
else {
massFlow = Double.valueOf(jTextField_VolFlow.getText())/3600*myFluidDataModel.getDensity();
//jTextField_FlowOutput.setText(formatFlow.format(massFlow*3600));
}
/*
* Write Text Field Data to PipeDataModel.
* Watch the standard units!!
*/
myPipeDataModel = new PipeDataModel(
Double.valueOf(jTextField_Length.getText()),
innerDiameter,
pipeRoughness,
massFlow
);
/*
* Write Data to the outputfield for flow.
* If massFlow was specified in the input,
* volFlow is shown and the other way round.
*/
DecimalFormat formatFlow = new DecimalFormat(".##");
formatFlow.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
if (jTextField_MassFlow.isEnabled()) {
jTextField_FlowOutput.setText(formatFlow.format(myPipeDataModel.getVolFlow(myFluidDataModel)*3600));
}
else {
jTextField_FlowOutput.setText(formatFlow.format(myPipeDataModel.getMassFlow()*3600));
}
/*
* Write Data to the outputfield for velocity.
*/
DecimalFormat formatVelcoity = new DecimalFormat(".#");
formatVelcoity.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
jTextField_Velocity.setText(formatVelcoity.format(myPipeDataModel.getVelocity(myFluidDataModel)));
DecimalFormat formatReynolds = new DecimalFormat(".##");
formatReynolds.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
jTextField_Reynolds.setText(formatReynolds.format(FlowEquations.reynolds(myPipeDataModel, myFluidDataModel)));
DecimalFormat formatPressureLoss = new DecimalFormat("0.#####");
formatPressureLoss.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
jTextField_PressureLoss.setText(
formatPressureLoss.format(
FlowEquations.pressureLoss(myPipeDataModel,myFluidDataModel)*(1E-5)));
jTextField_FrictionFactor.setText(formatPressureLoss.format(
FlowEquations.frictionFactorColebrook(myPipeDataModel,myFluidDataModel)));
/*
* test stuff
*/
if (FlowEquations.reynolds(myPipeDataModel, myFluidDataModel) < 2500){
jLabel_Warning_Reynolds.setVisible(true);
}
else {
jLabel_Warning_Reynolds.setVisible(false);
}
}
});
/*
* Call the PipeSizeSelection Dialog
* to determine the innerDiameter.
*/
jButton_Diameter.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
PipeSizeSelection myPipeSizeSelection = new PipeSizeSelection(null);
myPipeSizeSelection.pack();
myPipeSizeSelection.setVisible(true);
if (myPipeSizeSelection.getDiameter()==Double.valueOf(0)){
}
else {
jTextField_Diameter.setText(String.valueOf(myPipeSizeSelection.getDiameter()));
innerDiameter = myPipeSizeSelection.getDiameter()*1E-3;
}
}
});
/*
* Call the PipeRoughnessSelection Dialog
* to determine the pipe rougness.
*/
jButton_Roughness.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
PipeRoughnessSelection myPipeRoughnessSelection = new PipeRoughnessSelection(null);
myPipeRoughnessSelection.pack();
myPipeRoughnessSelection.setVisible(true);
if (myPipeRoughnessSelection.getRoughness()==Double.valueOf(0)){
}
else {
jTextField_Roughness.setText(String.valueOf(myPipeRoughnessSelection.getRoughness()));
pipeRoughness = myPipeRoughnessSelection.getRoughness();
}
}
});
/*
* IF the textfield VolFlow is clicked
* the input field for MassFlow is deactivated
* and the user can input the volume flow
* instead.
*
* The output field for flow has than also be
* adapted.
*/
jTextField_VolFlow.addMouseListener(new MouseListener(){
public void mousePressed(MouseEvent e){};
public void mouseExited(MouseEvent e){};
public void mouseReleased(MouseEvent e){};
public void mouseEntered(MouseEvent e){};
public void mouseClicked(MouseEvent e){
// If the field is active anyway do nothing.
if (jTextField_VolFlow.isEditable()){
}
else {
jLabel_Unit_FlowOutPut.setText("kg/hr");
jLabel_FlowOutput.setText("Mass Flow");
jTextField_MassFlow.setEditable(false);
jTextField_MassFlow.setEnabled(false);
jTextField_VolFlow.requestFocus();
jTextField_MassFlow.setToolTipText("<html>Click here to enter mass flow here.</html>");
jTextField_VolFlow.setToolTipText("<html>Enter volume flow here
or hover on \"Mass Flow\" field and click.</html>");
jTextField_VolFlow.setEditable(true);
jTextField_VolFlow.setEnabled(true);
clearAllResults();
}
}
});
/*
* As the previous just the other way round.
*/
jTextField_MassFlow.addMouseListener(new MouseListener(){
public void mousePressed(MouseEvent e){};
public void mouseExited(MouseEvent e){};
public void mouseReleased(MouseEvent e){};
public void mouseEntered(MouseEvent e){};
public void mouseClicked(MouseEvent e){
// If the field is active anyway do nothing.
if (jTextField_MassFlow.isEditable()){
}
else {
jTextField_VolFlow.setEditable(false);
jTextField_VolFlow.setEnabled(false);
jLabel_Unit_FlowOutPut.setText("<html>m<sup>3</sup>/hr</html>");
jLabel_FlowOutput.setText("Vol. Flow");
jTextField_MassFlow.requestFocus();
jTextField_VolFlow.setToolTipText("<html>Click here to enter volume flow here.</html>");
jTextField_MassFlow.setToolTipText("<html>Enter mass flow here
or hover on \"Vol. Flow\" field and click.</html>");
jTextField_MassFlow.setEditable(true);
jTextField_MassFlow.setEnabled(true);
clearAllResults();
}
}
});
/*
* Fill all input field with some values.
*/
jButton_fill.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jTextField_MassFlow.setText("10000");
jTextField_VolFlow.setText("10");
jTextField_Density.setText("1000");
jTextField_Viscosity.setText("1");
jTextField_Diameter.setText("50");
innerDiameter = 50E-3;
jTextField_Roughness.setText("0.05");
pipeRoughness = 0.05E-3;
}
});
}
/**
* This Method initializes Menu Listeners.
*
*/
private void initializeMenuListeners(){
jMenuItem_Exit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
jMenuItem_About.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
MiscAbout myMiscAbout = new MiscAbout(null);
myMiscAbout.pack();
myMiscAbout.setVisible(true);
}
});
}
/**
* This method initializes jTextField_MassFlow
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_MassFlow() {
if (jTextField_MassFlow == null) {
jTextField_MassFlow = new JTextField();
jTextField_MassFlow.setBounds(new Rectangle(135, 45, 76, 16));
jTextField_MassFlow.setToolTipText("<html>Enter mass flow here
or hover on \"Vol. Flow\" field and click.</html>");
jTextField_MassFlow.setHorizontalAlignment(JTextField.RIGHT);
jTextField_MassFlow.setFont(new Font("Dialog", Font.PLAIN, 10));
jTextField_MassFlow.setText("");
}
return jTextField_MassFlow;
}
/**
* This method initializes jTextField_VolFlow
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_VolFlow() {
if (jTextField_VolFlow == null) {
jTextField_VolFlow = new JTextField();
jTextField_VolFlow.setBounds(new Rectangle(135, 75, 76, 16));
jTextField_VolFlow.setEditable(false);
jTextField_VolFlow.setToolTipText("<html>Click here to enter volume flow here.</html>");
jTextField_VolFlow.setHorizontalAlignment(JTextField.RIGHT);
jTextField_VolFlow.setFont(new Font("Dialog", Font.PLAIN, 10));
jTextField_VolFlow.setEnabled(false);
}
return jTextField_VolFlow;
}
/**
* This method initializes jTextField_Density
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_Density() {
if (jTextField_Density == null) {
jTextField_Density = new JTextField();
jTextField_Density.setBounds(new Rectangle(135, 105, 76, 16));
jTextField_Density.setHorizontalAlignment(JTextField.RIGHT);
jTextField_Density.setFont(new Font("Dialog", Font.PLAIN, 10));
jTextField_Density.setToolTipText("");
}
return jTextField_Density;
}
/**
* This method initializes jTextField_Viscosity
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_Viscosity() {
if (jTextField_Viscosity == null) {
jTextField_Viscosity = new JTextField();
jTextField_Viscosity.setBounds(new Rectangle(135, 135, 76, 16));
jTextField_Viscosity.setFont(new Font("Dialog", Font.PLAIN, 10));
jTextField_Viscosity.setHorizontalAlignment(JTextField.RIGHT);
}
return jTextField_Viscosity;
}
/**
* This method initializes jTextField_Length
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_Length() {
if (jTextField_Length == null) {
jTextField_Length = new JTextField();
jTextField_Length.setBounds(new Rectangle(135, 180, 76, 16));
jTextField_Length.setText("1");
jTextField_Length.setFont(new Font("Dialog", Font.PLAIN, 10));
jTextField_Length.setHorizontalAlignment(JTextField.RIGHT);
}
return jTextField_Length;
}
/**
* This method initializes jTextField_Diameter
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_Diameter() {
if (jTextField_Diameter == null) {
jTextField_Diameter = new JTextField();
jTextField_Diameter.setBounds(new Rectangle(135, 210, 76, 16));
jTextField_Diameter.setFont(new Font("Dialog", Font.PLAIN, 10));
jTextField_Diameter.setHorizontalAlignment(JTextField.RIGHT);
}
return jTextField_Diameter;
}
/**
* This method initializes jSplitPane
*
* @return javax.swing.JSplitPane
*/
private JSplitPane getJSplitPane() {
if (jSplitPane == null) {
jSplitPane = new JSplitPane();
jSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
jSplitPane.setDividerLocation(300);
jSplitPane.setEnabled(false);
jSplitPane.setTopComponent(getJContentPane_Input());
jSplitPane.setBottomComponent(getJPanel_Output());
jSplitPane.setDividerSize(5);
}
return jSplitPane;
}
/**
* This method initializes jPanel_Output
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel_Output() {
if (jPanel_Output == null) {
jLabel_FrictionFactor = new JLabel();
jLabel_FrictionFactor.setBounds(new Rectangle(29, 163, 92, 18));
jLabel_FrictionFactor.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_FrictionFactor.setText("Friction Factor");
jLabel_Warning_Reynolds = new JLabel();
jLabel_Warning_Reynolds.setBounds(new Rectangle(270, 135, 16, 16));
jLabel_Warning_Reynolds.setIcon(new ImageIcon(getClass().getResource("/Icons/software-update-urgent.png")));
jLabel_Warning_Reynolds.setText("JLabel");
jLabel_Warning_Reynolds.setToolTipText("<html>Laminar Flow
Equations not valid!</html>");
jLabel_Warning_Reynolds.setVisible(false);
jLabel_Reynolds = new JLabel();
jLabel_Reynolds.setBounds(new Rectangle(30, 135, 91, 16));
jLabel_Reynolds.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Reynolds.setText("Reynolds Number");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(225, 105, 61, 16));
jLabel1.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel1.setText("m/s");
jLabel_Velocity = new JLabel();
jLabel_Velocity.setBounds(new Rectangle(30, 105, 91, 16));
jLabel_Velocity.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Velocity.setText("Velocity");
jLabel_Unit_FlowOutPut = new JLabel();
jLabel_Unit_FlowOutPut.setBounds(new Rectangle(225, 75, 61, 16));
jLabel_Unit_FlowOutPut.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Unit_FlowOutPut.setText("<html>m<sup>3</sup>/hr</html>");
jLabel_FlowOutput = new JLabel();
jLabel_FlowOutput.setBounds(new Rectangle(30, 75, 91, 16));
jLabel_FlowOutput.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_FlowOutput.setText("Vol. Flow");
jLabel_Unit_Pressure = new JLabel();
jLabel_Unit_Pressure.setBounds(new Rectangle(225, 45, 61, 16));
jLabel_Unit_Pressure.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_Unit_Pressure.setText("bar");
jLabel_PressureLoss = new JLabel();
jLabel_PressureLoss.setBounds(new Rectangle(30, 45, 91, 16));
jLabel_PressureLoss.setFont(new Font("Dialog", Font.PLAIN, 10));
jLabel_PressureLoss.setText("Pressure Loss");
jLabel_Heading_Output = new JLabel();
jLabel_Heading_Output.setBounds(new Rectangle(15, 15, 106, 16));
jLabel_Heading_Output.setText("Output Values:");
jPanel_Output = new JPanel();
jPanel_Output.setLayout(null);
jPanel_Output.add(jLabel_Heading_Output, null);
jPanel_Output.add(jLabel_PressureLoss, null);
jPanel_Output.add(getJTextField_PressureLoss(), null);
jPanel_Output.add(jLabel_Unit_Pressure, null);
jPanel_Output.add(getJTextField_FlowOutput(), null);
jPanel_Output.add(jLabel_FlowOutput, null);
jPanel_Output.add(jLabel_Unit_FlowOutPut, null);
jPanel_Output.add(jLabel_Velocity, null);
jPanel_Output.add(getJTextField_Velocity(), null);
jPanel_Output.add(jLabel1, null);
jPanel_Output.add(jLabel_Reynolds, null);
jPanel_Output.add(getJTextField_Reynolds(), null);
jPanel_Output.add(jLabel_Warning_Reynolds, null);
jPanel_Output.add(getJTextField_FrictionFactor(), null);
jPanel_Output.add(jLabel_FrictionFactor, null);
}
return jPanel_Output;
}
/**
* This method initializes jTextField_PressureLoss
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_PressureLoss() {
if (jTextField_PressureLoss == null) {
jTextField_PressureLoss = new JTextField();
jTextField_PressureLoss.setBounds(new Rectangle(135, 45, 76, 16));
jTextField_PressureLoss.setEnabled(true);
jTextField_PressureLoss.setHorizontalAlignment(JTextField.RIGHT);
jTextField_PressureLoss.setFont(new Font("Dialog", Font.PLAIN, 10));
jTextField_PressureLoss.setEditable(false);
}
return jTextField_PressureLoss;
}
/**
* This method initializes jTextField_FlowOutput
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_FlowOutput() {
if (jTextField_FlowOutput == null) {
jTextField_FlowOutput = new JTextField();
jTextField_FlowOutput.setBounds(new Rectangle(135, 75, 76, 16));
jTextField_FlowOutput.setEnabled(true);
jTextField_FlowOutput.setHorizontalAlignment(JTextField.RIGHT);
jTextField_FlowOutput.setFont(new Font("Dialog", Font.PLAIN, 10));
jTextField_FlowOutput.setEditable(false);
}
return jTextField_FlowOutput;
}
/**
* This method initializes jButton_Calculate
*
* @return javax.swing.JButton
*/
private JButton getJButton_Calculate() {
if (jButton_Calculate == null) {
jButton_Calculate = new JButton();
jButton_Calculate.setBounds(new Rectangle(182, 269, 106, 16));
jButton_Calculate.setText("Calculate");
}
return jButton_Calculate;
}
/**
* This method initializes jButton_Diameter
*
* @return javax.swing.JButton
*/
private JButton getJButton_Diameter() {
if (jButton_Diameter == null) {
jButton_Diameter = new JButton();
jButton_Diameter.setBounds(new Rectangle(105, 210, 16, 16));
jButton_Diameter.setBackground(new Color(238, 238, 238));
jButton_Diameter.setForeground(new Color(238, 238, 238));
jButton_Diameter.setRolloverEnabled(false);
jButton_Diameter.setToolTipText("Input help for pipe size in inches.");
jButton_Diameter.setIcon(new ImageIcon(getClass().getResource("/Icons/go-next.png")));
}
return jButton_Diameter;
}
/**
* This method initializes jButton_Roughness
*
* @return javax.swing.JButton
*/
private JButton getJButton_Roughness() {
if (jButton_Roughness == null) {
jButton_Roughness = new JButton();
jButton_Roughness.setBounds(new Rectangle(105, 240, 16, 16));
jButton_Roughness.setIcon(new ImageIcon(getClass().getResource("/Icons/go-next.png")));
jButton_Roughness.setRolloverEnabled(false);
jButton_Roughness.setForeground(new Color(238, 238, 238));
}
return jButton_Roughness;
}
/**
* This method initializes jTextField_Roughness
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_Roughness() {
if (jTextField_Roughness == null) {
jTextField_Roughness = new JTextField();
jTextField_Roughness.setBounds(new Rectangle(135, 240, 76, 16));
jTextField_Roughness.setHorizontalAlignment(JTextField.RIGHT);
jTextField_Roughness.setFont(new Font("Dialog", Font.PLAIN, 10));
}
return jTextField_Roughness;
}
/**
* This method initializes jTextField_Velocity
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_Velocity() {
if (jTextField_Velocity == null) {
jTextField_Velocity = new JTextField();
jTextField_Velocity.setBounds(new Rectangle(135, 105, 76, 16));
jTextField_Velocity.setEditable(false);
jTextField_Velocity.setHorizontalAlignment(JTextField.RIGHT);
jTextField_Velocity.setFont(new Font("Dialog", Font.PLAIN, 10));
}
return jTextField_Velocity;
}
/**
* This method initializes jTextField_Reynolds
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_Reynolds() {
if (jTextField_Reynolds == null) {
jTextField_Reynolds = new JTextField();
jTextField_Reynolds.setBounds(new Rectangle(135, 135, 76, 16));
jTextField_Reynolds.setEditable(false);
jTextField_Reynolds.setHorizontalAlignment(JTextField.RIGHT);
jTextField_Reynolds.setFont(new Font("Dialog", Font.PLAIN, 10));
}
return jTextField_Reynolds;
}
/**
* This method initializes jButton_fill
*
* @return javax.swing.JButton
*/
private JButton getJButton_fill() {
if (jButton_fill == null) {
jButton_fill = new JButton();
jButton_fill.setBounds(new Rectangle(285, 15, 16, 16));
jButton_fill.setForeground(new Color(238, 238, 238));
jButton_fill.setIcon(new ImageIcon(getClass().getResource("/Icons/software-update-available.png")));
jButton_fill.setRolloverEnabled(false);
jButton_fill.setDisabledIcon(new ImageIcon(getClass().getResource("/Icons/software-update-available.png")));
jButton_fill.setToolTipText("Fill Example");
jButton_fill.setVisible(true);
}
return jButton_fill;
}
/**
* This method shall clear all outputs.
*
*/
private void clearAllResults(){
/*
* Implement with a loop in future!
*/
// Component[] myComponents = jPanel_Output.getComponents();
// for (int i=0; i<myComponents.length;i++ ){
// if (myComponents[i].getClass().getCanonicalName() == "JTextBox"){
//
// }
// }
jTextField_PressureLoss.setText("");
jTextField_FlowOutput.setText("");
jTextField_Velocity.setText("");
jTextField_Reynolds.setText("");
jTextField_FrictionFactor.setText("");
jLabel_Warning_Reynolds.setVisible(false);
}
/**
* This method initializes jJMenuBar
*
* @return javax.swing.JMenuBar
*/
private JMenuBar getJJMenuBar() {
if (jJMenuBar == null) {
jJMenuBar = new JMenuBar();
jJMenuBar.add(getJMenu());
jJMenuBar.add(getJMenu_Options());
jJMenuBar.add(getJMenu1());
}
return jJMenuBar;
}
/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getJMenu() {
if (jMenu_File == null) {
jMenu_File = new JMenu();
jMenu_File.setText("File");
// jMenu_File.add(getJMenuItem_New());
// jMenu_File.addSeparator();
// jMenu_File.add(getJMenuItem_Open());
// jMenu_File.addSeparator();
// jMenu_File.add(getJMenuItem_Save());
// jMenu_File.add(getJMenuItem_SaveAs());
// jMenu_File.addSeparator();
jMenu_File.add(getJMenuItem_Exit());
}
return jMenu_File;
}
/**
* This method initializes jMenu1
*
* @return javax.swing.JMenu
*/
private JMenu getJMenu1() {
if (jMenu_Help == null) {
jMenu_Help = new JMenu();
jMenu_Help.setText("Help");
jMenu_Help.add(getJMenuItem_Help());
jMenu_Help.addSeparator();
jMenu_Help.add(getJMenuItemAbout());
}
return jMenu_Help;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem_New() {
if (jMenuItem_New == null) {
jMenuItem_New = new JMenuItem("New");
}
return jMenuItem_New;
}
/**
* This method initializes jMenuItem1
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem_Open() {
if (jMenuItem_Open == null) {
jMenuItem_Open = new JMenuItem("Open");
}
return jMenuItem_Open;
}
/**
* This method initializes jMenuItem2
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem_Save() {
if (jMenuItem_Save == null) {
jMenuItem_Save = new JMenuItem("Save");
}
return jMenuItem_Save;
}
/**
* This method initializes jMenuItem3
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem_SaveAs() {
if (jMenuItem_SaveAs == null) {
jMenuItem_SaveAs = new JMenuItem("Save As");
jMenuItem_SaveAs.setEnabled(false);
}
return jMenuItem_SaveAs;
}
/**
* This method initializes jMenuItem4
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem_Exit() {
if (jMenuItem_Exit == null) {
jMenuItem_Exit = new JMenuItem("Exit");
}
return jMenuItem_Exit;
}
/**
* This method initializes jMenu2
*
* @return javax.swing.JMenu
*/
private JMenu getJMenu_Options() {
if (jMenu_Options == null) {
jMenu_Options = new JMenu();
jMenu_Options.setText("Calculation Options");
jMenu_Options.add(getJRadioButtonMenuItem_Colebrook());
jMenu_Options.add(getJRadioButtonMenuItem_Prandtl());
jMenu_Options.add(getJRadioButtonMenuItem_Nikuradse());
}
return jMenu_Options;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem_Help() {
if (jMenuItem_Help == null) {
jMenuItem_Help = new JMenuItem("Help");
}
return jMenuItem_Help;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItemAbout() {
if (jMenuItem_About == null) {
jMenuItem_About = new JMenuItem("About");
}
return jMenuItem_About;
}
/**
* This method initializes jRadioButtonMenuItem
*
* @return javax.swing.JRadioButtonMenuItem
*/
private JRadioButtonMenuItem getJRadioButtonMenuItem_Colebrook() {
if (jRadioButtonMenuItem_Colebrook == null) {
jRadioButtonMenuItem_Colebrook = new JRadioButtonMenuItem("Colebrook");
jRadioButtonMenuItem_Colebrook.setSelected(true);
}
return jRadioButtonMenuItem_Colebrook;
}
/**
* This method initializes jRadioButtonMenuItem
*
* @return javax.swing.JRadioButtonMenuItem
*/
private JRadioButtonMenuItem getJRadioButtonMenuItem_Prandtl() {
if (jRadioButtonMenuItem_Prandtl == null) {
jRadioButtonMenuItem_Prandtl = new JRadioButtonMenuItem("Prandtl");
jRadioButtonMenuItem_Prandtl.setEnabled(false);
}
return jRadioButtonMenuItem_Prandtl;
}
/**
* This method initializes jRadioButtonMenuItem
*
* @return javax.swing.JRadioButtonMenuItem
*/
private JRadioButtonMenuItem getJRadioButtonMenuItem_Nikuradse() {
if (jRadioButtonMenuItem_Nikuradse == null) {
jRadioButtonMenuItem_Nikuradse = new JRadioButtonMenuItem("Nikuradse");
jRadioButtonMenuItem_Nikuradse.setEnabled(false);
}
return jRadioButtonMenuItem_Nikuradse;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField_FrictionFactor() {
if (jTextField_FrictionFactor == null) {
jTextField_FrictionFactor = new JTextField();
jTextField_FrictionFactor.setBounds(new Rectangle(135, 165, 76, 16));
jTextField_FrictionFactor.setEditable(false);
jTextField_FrictionFactor.setHorizontalAlignment(JTextField.RIGHT);
jTextField_FrictionFactor.setFont(new Font("Dialog", Font.PLAIN, 10));
}
return jTextField_FrictionFactor;
}
} // @jve:decl-index=0:visual-constraint="10,12"