SlideShare a Scribd company logo
 
import java.awt.Color; 
import java.awt.GridLayout; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
 
import javax.swing.BorderFactory; 
import javax.swing.JButton; 
import javax.swing.JLabel; 
import javax.swing.JFrame; 
import javax.swing.JPanel; 
import javax.swing.JTextField; 
import javax.swing.border.Border; 
 
public class FlowRateFinder extends JFrame { // opens main class. 
 
// creates all the Panels needed in the program 
private JPanel labelPanel1; 
private JPanel labelPanel2; 
private JPanel calcPanel; 
private JPanel buttonPanel; 
 
 
// creates all the labels needed in the program 
private JLabel dia; 
private JLabel dens; 
private JLabel len; 
private JLabel visc; 
private JLabel grav; 
private JLabel hF; 
private JLabel flowRateTxt; 
private JLabel calculatedValue; 
private JLabel velocityTxt; 
private JLabel velocityCalc; 
private JLabel fFactor; 
private JLabel roughValue; 
 
// creates all the buttons in the program 
private JButton calcBtn; 
private JButton clearBtn; 
 
// creates all the text fields in the program 
private JTextField diameter; 
private JTextField density; 
private JTextField length; 
private JTextField viscosity; 
private JTextField gravity; 
private JTextField headLoss; 
private JTextField fFactorTxt; 
private JTextField roughValueTxt; 
 
 
 
private Border blackline = BorderFactory.createLineBorder(Color.black); 
 
public FlowRateFinder() { // constructor for the Object 
 
// sets the GUI parameters. 
super("Flow Rate Finder"); 
setDefaultCloseOperation(EXIT_ON_CLOSE); 
setBounds(10, 10, 700, 400); 
setLayout(new GridLayout(4,1)); 
 
// creates the panels and their overall layouts. 
labelPanel1 = new JPanel(new GridLayout(3,2)); 
labelPanel2 = new JPanel(new GridLayout(3,2)); 
calcPanel = new JPanel(new GridLayout(2, 2)); 
 
// block of variable initializers for the variable diameter 
dia = new JLabel("diameter (m)"); 
dia.setHorizontalAlignment(JLabel.CENTER); 
dia.setBorder(blackline); 
diameter = new JTextField("", 10); 
diameter.setHorizontalAlignment(JTextField.CENTER); 
diameter.setBorder(blackline); 
 
// allocates info to the variable density. 
dens = new JLabel("density (kg/m^3)"); 
dens.setHorizontalAlignment(JLabel.CENTER); 
dens.setBorder(blackline); 
density = new JTextField("", 10); 
density.setHorizontalAlignment(JTextField.CENTER); 
density.setBorder(blackline); 
 
// allocates info to the variable length. 
len = new JLabel("length (m)"); 
len.setHorizontalAlignment(JLabel.CENTER); 
len.setBorder(blackline); 
length = new JTextField("", 10); 
length.setHorizontalAlignment(JTextField.CENTER); 
length.setBorder(blackline); 
 
// allocates info to the variable viscosity. 
visc = new JLabel("viscosity (kg/ms)"); 
visc.setHorizontalAlignment(JLabel.CENTER); 
visc.setBorder(blackline); 
viscosity = new JTextField("", 10); 
viscosity.setHorizontalAlignment(JTextField.CENTER); 
viscosity.setBorder(blackline); 
 
// allocates info to the variable gravity. 
grav = new JLabel("gravity (N/kg)"); 
grav.setHorizontalAlignment(JLabel.CENTER); 
grav.setBorder(blackline); 
gravity = new JTextField("", 10); 
gravity.setHorizontalAlignment(JTextField.CENTER); 
gravity.setBorder(blackline); 
 
// allocates info to the variable headloss 
hF = new JLabel("head­loss (ft)"); 
hF.setHorizontalAlignment(JLabel.CENTER); 
hF.setBorder(blackline); 
headLoss = new JTextField("", 10); 
headLoss.setHorizontalAlignment(JTextField.CENTER); 
headLoss.setBorder(blackline); 
 
// allocates info to the calculation field. 
flowRateTxt = new JLabel("Your flow rate is:     (m^3/s)"); 
flowRateTxt.setHorizontalAlignment(JLabel.CENTER); 
flowRateTxt.setBorder(blackline); 
calculatedValue = new JLabel(""); 
calculatedValue.setHorizontalAlignment(JLabel.CENTER); 
calculatedValue.setBorder(blackline); 
velocityTxt = new JLabel("Your average velocity is:      (m/s) "); 
velocityTxt.setHorizontalAlignment(JLabel.CENTER); 
velocityTxt.setBorder(blackline); 
velocityCalc = new JLabel(""); 
velocityCalc.setHorizontalAlignment(JLabel.CENTER); 
velocityCalc.setBorder(blackline); 
 
// adds information to the calculation panel. 
calcPanel.add(flowRateTxt); 
calcPanel.add(calculatedValue); 
calcPanel.add(velocityTxt); 
calcPanel.add(velocityCalc); 
 
// adds information to the initial guess and the roughness level. 
fFactor = new JLabel("friction factor: "); 
fFactor.setHorizontalAlignment(JLabel.CENTER); 
fFactor.setBorder(blackline); 
fFactorTxt = new JTextField("", 10); 
fFactorTxt.setHorizontalAlignment(JTextField.CENTER); 
fFactorTxt.setBorder(blackline); 
roughValue = new JLabel("roughness E/D: "); 
roughValue.setHorizontalAlignment(JLabel.CENTER); 
roughValue.setBorder(blackline); 
roughValueTxt = new JTextField("", 10); 
roughValueTxt.setHorizontalAlignment(JTextField.CENTER); 
roughValueTxt.setBorder(blackline); 
 
 
// adds information to the first label panel. 
labelPanel1.setBackground(Color.cyan); 
labelPanel1.add(dia); 
labelPanel1.add(diameter); 
labelPanel1.add(dens); 
labelPanel1.add(density); 
labelPanel1.add(len); 
labelPanel1.add(length); 
 
// adds information to the second label panel 
labelPanel2.setBackground(Color.cyan); 
labelPanel2.add(visc); 
labelPanel2.add(viscosity); 
labelPanel2.add(grav); 
labelPanel2.add(gravity); 
labelPanel2.add(hF); 
labelPanel2.add(headLoss); 
 
// adds information to the buttons and button panel 
calcBtn = new JButton("Calculate!"); 
clearBtn = new JButton("Clear!"); 
buttonPanel = new JPanel(new GridLayout( 3, 2)); 
buttonPanel.setBackground(Color.cyan); 
buttonPanel.add(fFactor); 
buttonPanel.add(fFactorTxt); 
buttonPanel.add(roughValue); 
buttonPanel.add(roughValueTxt); 
buttonPanel.add(calcBtn); 
buttonPanel.add(clearBtn); 
 
// adds all the panels to the main frame. 
add(labelPanel1); 
add(labelPanel2); 
add(buttonPanel); 
add(calcPanel); 
 
// allows for the buttons to actually initiate calculations. 
ButtonListener btnListn = new ButtonListener(); 
calcBtn.addActionListener(btnListn); 
clearBtn.addActionListener(btnListn); 
 
 
// allows user to see the GUI 
setVisible(true); 
 
} 
 
// action listener that waits for a button to be pressed and performs actions 
// based on the click. 
public class ButtonListener implements ActionListener { 
 
public void actionPerformed(ActionEvent e) { 
 
// does calculations if the calculation button is pressed. 
if(e.getSource() == calcBtn) { 
try{ 
// takes all the strings input by the user and converts them to 
doubles. 
double den = Double.parseDouble(density.getText()); 
double l = Double.parseDouble(length.getText()); 
double hL = Double.parseDouble(headLoss.getText()); 
double g = Double.parseDouble(gravity.getText()); 
double dia = Double.parseDouble(diameter.getText()); 
double mu = Double.parseDouble(viscosity.getText()); 
 
//initializes all other variables needed in the calculation. 
double frictionFactor = Double.parseDouble(fFactorTxt.getText()); 
double ReynoldNum; 
double kinVisc = mu/den; 
double tempFF = 0; 
double roughFact = 
Double.parseDouble(roughValueTxt.getText()); 
double v; 
double area = (Math.PI * Math.pow(dia, 2)) / 4; 
 
do  { // do­while loop that will do the first calculation then initiates a 
while loop 
 
 
// does the calculation 
tempFF = frictionFactor; 
v = Math.sqrt((2 * hL * dia * g)/(frictionFactor * l)); 
ReynoldNum = ((v * dia)/ kinVisc); 
frictionFactor = Math.pow(­1.52 * 
Math.log10((Math.pow((roughFact/7.21), 1.042) + Math.pow((2.731/ReynoldNum), 0.9152))), 
­2.169); 
 
} while((frictionFactor ­ tempFF) > .0001); 
 
double FlowRate = area * v; 
 
// this part takes the calculations and displays them "nicely" 
calculatedValue.setText(Double.toString(FlowRate)); 
calculatedValue.setBackground(Color.green); 
calculatedValue.setOpaque(true); 
velocityCalc.setText(Double.toString(v)); 
velocityCalc.setBackground(Color.green); 
velocityCalc.setOpaque(true); 
} catch (NumberFormatException z) { 
// catches anything that is not a number input. 
calculatedValue.setText("Oops! You entered illegal 
characters, try again!"); 
} 
 
} 
 
 
// clears the GUI if the clear button is pressed. 
if(e.getSource() == clearBtn) { 
 
// sets everything back to the default. 
diameter.setText(""); 
density.setText(""); 
viscosity.setText(""); 
headLoss.setText(""); 
gravity.setText(""); 
length.setText(""); 
fFactorTxt.setText(""); 
roughValueTxt.setText(""); 
calculatedValue.setText(""); 
calculatedValue.setOpaque(false); 
velocityCalc.setText(""); 
velocityCalc.setOpaque(false); 
} 
 
 
 
} 
} 
 
public static void main(String[] args) { 
FlowRateFinder test = new FlowRateFinder(); 
 
} 
 
 
} // closes main class. 
 
 

More Related Content

Viewers also liked

SoftRoboticsProjectReport (6)
SoftRoboticsProjectReport (6)SoftRoboticsProjectReport (6)
SoftRoboticsProjectReport (6)Leon Kim
 
Tugas km 3
Tugas km 3Tugas km 3
Tugas km 3
Tommy Christianto
 
Big lady spanish website clothes
Big lady spanish website clothesBig lady spanish website clothes
Big lady spanish website clothes
Silvia Niko
 
White privilege
White privilegeWhite privilege
White privilege
Spinks97
 
Krig og konflikt2
Krig og konflikt2Krig og konflikt2
Krig og konflikt2
iknoff
 
Promotional package test screening audience feedback
Promotional package test screening audience feedbackPromotional package test screening audience feedback
Promotional package test screening audience feedback
GennaroBonito
 
Rein
ReinRein
Sistemas de Información. Arbi uriel euan chable.
Sistemas de Información. Arbi uriel euan chable.Sistemas de Información. Arbi uriel euan chable.
Sistemas de Información. Arbi uriel euan chable.
arbi_uriel
 

Viewers also liked (10)

SoftRoboticsProjectReport (6)
SoftRoboticsProjectReport (6)SoftRoboticsProjectReport (6)
SoftRoboticsProjectReport (6)
 
Tugas km 3
Tugas km 3Tugas km 3
Tugas km 3
 
Big lady spanish website clothes
Big lady spanish website clothesBig lady spanish website clothes
Big lady spanish website clothes
 
White privilege
White privilegeWhite privilege
White privilege
 
My CV
My CVMy CV
My CV
 
ICIC_JPMC_Incubators_post
ICIC_JPMC_Incubators_postICIC_JPMC_Incubators_post
ICIC_JPMC_Incubators_post
 
Krig og konflikt2
Krig og konflikt2Krig og konflikt2
Krig og konflikt2
 
Promotional package test screening audience feedback
Promotional package test screening audience feedbackPromotional package test screening audience feedback
Promotional package test screening audience feedback
 
Rein
ReinRein
Rein
 
Sistemas de Información. Arbi uriel euan chable.
Sistemas de Información. Arbi uriel euan chable.Sistemas de Información. Arbi uriel euan chable.
Sistemas de Información. Arbi uriel euan chable.
 

Similar to FlowRateGUI

import java.awt.BorderLayout; import java.awt.EventQueue; i.pdf
  import java.awt.BorderLayout;     import java.awt.EventQueue;      i.pdf  import java.awt.BorderLayout;     import java.awt.EventQueue;      i.pdf
import java.awt.BorderLayout; import java.awt.EventQueue; i.pdf
nikhilpopli11
 
correct the error import javaxswingJFrame import javaxs.pdf
correct the error import javaxswingJFrame import javaxs.pdfcorrect the error import javaxswingJFrame import javaxs.pdf
correct the error import javaxswingJFrame import javaxs.pdf
devangmittal4
 
correct the error and add code same in the pic import jav.pdf
correct the error and add code same in the pic   import jav.pdfcorrect the error and add code same in the pic   import jav.pdf
correct the error and add code same in the pic import jav.pdf
devangmittal4
 
From Swing to JavaFX
From Swing to JavaFXFrom Swing to JavaFX
From Swing to JavaFX
Yuichi Sakuraba
 
Chapter iv(modern gui)
Chapter iv(modern gui)Chapter iv(modern gui)
Chapter iv(modern gui)
Chhom Karath
 
I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdf
fashionfolionr
 
APPLETSAPPLETSBINARYADDapplet_frame.htmAPPLETSAPPLETSBI.docx
APPLETSAPPLETSBINARYADDapplet_frame.htmAPPLETSAPPLETSBI.docxAPPLETSAPPLETSBINARYADDapplet_frame.htmAPPLETSAPPLETSBI.docx
APPLETSAPPLETSBINARYADDapplet_frame.htmAPPLETSAPPLETSBI.docx
rossskuddershamus
 
Hands On With Rich Faces 4 - JavaOne 2010
Hands On With Rich Faces 4 - JavaOne 2010Hands On With Rich Faces 4 - JavaOne 2010
Hands On With Rich Faces 4 - JavaOne 2010
Max Katz
 
Java Fx Ajaxworld Rags V1
Java Fx Ajaxworld Rags V1Java Fx Ajaxworld Rags V1
Java Fx Ajaxworld Rags V1rajivmordani
 
CogLab Information.htmlCogLab InformationCogLabs for this
CogLab Information.htmlCogLab InformationCogLabs for this CogLab Information.htmlCogLab InformationCogLabs for this
CogLab Information.htmlCogLab InformationCogLabs for this
WilheminaRossi174
 
Java!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfJava!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdf
arvindarora20042013
 
import java.awt.; victimisation AWTs Graphics and Color impo.pdf
import java.awt.;  victimisation AWTs Graphics and Color impo.pdfimport java.awt.;  victimisation AWTs Graphics and Color impo.pdf
import java.awt.; victimisation AWTs Graphics and Color impo.pdf
apexjaipur
 
in java(netbeans) create a javaFX GUI that can open and display the co.docx
in java(netbeans) create a javaFX GUI that can open and display the co.docxin java(netbeans) create a javaFX GUI that can open and display the co.docx
in java(netbeans) create a javaFX GUI that can open and display the co.docx
mckerliejonelle
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
anushkaent7
 
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code baseSingle Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
Ralf Sternberg
 
Chap1 1 1
Chap1 1 1Chap1 1 1
Chap1 1 1
Hemo Chella
 
Chap1 1.1
Chap1 1.1Chap1 1.1
Chap1 1.1
Hemo Chella
 

Similar to FlowRateGUI (20)

import java.awt.BorderLayout; import java.awt.EventQueue; i.pdf
  import java.awt.BorderLayout;     import java.awt.EventQueue;      i.pdf  import java.awt.BorderLayout;     import java.awt.EventQueue;      i.pdf
import java.awt.BorderLayout; import java.awt.EventQueue; i.pdf
 
DBTool
DBToolDBTool
DBTool
 
correct the error import javaxswingJFrame import javaxs.pdf
correct the error import javaxswingJFrame import javaxs.pdfcorrect the error import javaxswingJFrame import javaxs.pdf
correct the error import javaxswingJFrame import javaxs.pdf
 
Scrollable Demo App
Scrollable Demo AppScrollable Demo App
Scrollable Demo App
 
correct the error and add code same in the pic import jav.pdf
correct the error and add code same in the pic   import jav.pdfcorrect the error and add code same in the pic   import jav.pdf
correct the error and add code same in the pic import jav.pdf
 
From Swing to JavaFX
From Swing to JavaFXFrom Swing to JavaFX
From Swing to JavaFX
 
Chapter iv(modern gui)
Chapter iv(modern gui)Chapter iv(modern gui)
Chapter iv(modern gui)
 
I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdf
 
APPLETSAPPLETSBINARYADDapplet_frame.htmAPPLETSAPPLETSBI.docx
APPLETSAPPLETSBINARYADDapplet_frame.htmAPPLETSAPPLETSBI.docxAPPLETSAPPLETSBINARYADDapplet_frame.htmAPPLETSAPPLETSBI.docx
APPLETSAPPLETSBINARYADDapplet_frame.htmAPPLETSAPPLETSBI.docx
 
Oop lecture2
Oop lecture2Oop lecture2
Oop lecture2
 
Hands On With Rich Faces 4 - JavaOne 2010
Hands On With Rich Faces 4 - JavaOne 2010Hands On With Rich Faces 4 - JavaOne 2010
Hands On With Rich Faces 4 - JavaOne 2010
 
Java Fx Ajaxworld Rags V1
Java Fx Ajaxworld Rags V1Java Fx Ajaxworld Rags V1
Java Fx Ajaxworld Rags V1
 
CogLab Information.htmlCogLab InformationCogLabs for this
CogLab Information.htmlCogLab InformationCogLabs for this CogLab Information.htmlCogLab InformationCogLabs for this
CogLab Information.htmlCogLab InformationCogLabs for this
 
Java!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfJava!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdf
 
import java.awt.; victimisation AWTs Graphics and Color impo.pdf
import java.awt.;  victimisation AWTs Graphics and Color impo.pdfimport java.awt.;  victimisation AWTs Graphics and Color impo.pdf
import java.awt.; victimisation AWTs Graphics and Color impo.pdf
 
in java(netbeans) create a javaFX GUI that can open and display the co.docx
in java(netbeans) create a javaFX GUI that can open and display the co.docxin java(netbeans) create a javaFX GUI that can open and display the co.docx
in java(netbeans) create a javaFX GUI that can open and display the co.docx
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
 
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code baseSingle Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
 
Chap1 1 1
Chap1 1 1Chap1 1 1
Chap1 1 1
 
Chap1 1.1
Chap1 1.1Chap1 1.1
Chap1 1.1
 

FlowRateGUI