/* A basic extension of the com.sun.java.swing.JApplet class */ import com.sun.java.swing.*; import java.awt.*; import symantec.itools.awt.shape.Rect; import symantec.itools.awt.shape.Ellipse;

mammetlizardlickSoftware and s/w Development

Nov 3, 2013 (3 years and 9 months ago)

125 views

/*

A basic extension of the com.sun.java.swing.JApplet class

*/


import com.sun.java.swing.*;

import java.awt.*;

import symantec.itools.awt.shape.Rect;

import symantec.itools.awt.shape.Ellipse;

import symantec.itools.awt.shape.VerticalLine;

import symantec
.itools.awt.shape.HorizontalLine;

import java.lang.*;


public class head_manometer extends JApplet

{


public void new_ht()


{


yellow_fluid_left.setSize(24,left_ht
-

change_ht());


yellow_fluid_left.setLocation(276,yellow_left_loc + cha
nge_ht());


horizontalLine4.setBounds(300,yellow_left_loc + change_ht()
-
1,36,1);




yellow_fluid_right.setSize(24,right_ht+change_ht());


yellow_fluid_right.setLocation(372,yellow_right_loc
-
change_ht());


horizontalLine3.
setBounds(336,yellow_right_loc
-

change_ht(),38,1);




verticalLine5.setBounds(336,yellow_right_loc
-

change_ht(),2,Math.abs(change_ht()*2));




blue_fluid.setLocation(276,(int) bhead());


h_label.setBounds(324,yellow_rig
ht_loc
-
12
-
change_ht(),12,24);




if(h_diff()>1)


{


h_label.setVisible(true);


verticalLine5.setBounds(336,yellow_right_loc
-
change_ht(),2,Math.abs(change_ht()*2));


}


else




h_la
bel.setVisible(false);




if(h_diff() < 0)


{


h_label.setVisible(true);


verticalLine5.setBounds(336,yellow_left_loc + change_ht()
-
1,2,Math.abs(change_ht()*2)+1);


}


}



public int change_ht()



{


ht_adder = (int) h_diff()*in_pix/2;


return ht_adder;


}



int blue_loc = 188, blue_ht=105, yellow_left_loc = 293,


left_ht = 112, yellow_right_loc = 293, right_ht = 112;


int in_pix = 7;


int blue_bottom = 40;


in
t ht_adder;




public int bhead()


{


blue_bottom=yellow_left_loc + ht_adder;




int blue_top = blue_bottom
-

head_slider.getValue()*in_pix;


blue_fluid.setSize(24,head_slider.getValue()*in_pix);


blue_fluid.setLo
cation(276,blue_top);




return blue_top;


}



public double h_diff()


{


double cfp = 175.125, cfh = 0.645, g = 9.807, p_ambient=13.0, yellow_dens=20.0;




double h = ((bulb_press()*cfp + blue_density()*g*blue_h
d()*cfh
-

p_ambient*cfp)/(yellow_dens*g*cfh));


return h;


}



public double blue_hd()


{


return (double) head_slider.getValue();


}



public double blue_density()


{


return (double) density_slider.getValue();


}



public double bulb_press()


{


return (double) bulb_slider.getValue();


}



public void init()


{



// Take out this line if you don't use symantec.itools.net.RelativeURL or
symantec.itools.awt.util.StatusScroller



symantec.itools.lang.
Context.setApplet(this);






// This line prevents the "Swing: checked access to system event queue" message seen in
some browsers.



getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);






// This code is automatically generate
d by Visual Cafe when you add



// components to the visual environment. It instantiates and initializes



// the components. To modify the code, only use code syntax that matches



// what Visual Cafe can generate, or Visual Cafe may be unable to back



/
/ parse your Java file into its visual environment.



//{{INIT_CONTROLS



getContentPane().setLayout(null);



setSize(434,430);



Pbulb.setHorizontalAlignment(com.sun.java.swing.SwingConstants.CENTER);



Pbulb.setText("10 psi");



getContentPane().add(Pbul
b);



Pbulb.setForeground(new java.awt.Color(128,0,0));



Pbulb.setFont(new Font("Dialog", Font.BOLD, 25));



Pbulb.setBounds(228,12,120,73);



getContentPane().add(verticalLine5);



verticalLine5.setForeground(new java.awt.Color(128,128,0));



verticalLin
e5.setBounds(336,293,2,1);



getContentPane().add(verticalLine3);



verticalLine3.setBounds(372,168,2,228);



getContentPane().add(verticalLine4);



verticalLine4.setBounds(396,168,2,252);



getContentPane().add(horizontalLine3);



horizontalLine3.setForeg
round(new java.awt.Color(128,128,0));



horizontalLine3.setBounds(336,293,38,1);



getContentPane().add(horizontalLine4);



horizontalLine4.setForeground(new java.awt.Color(128,128,0));



horizontalLine4.setBounds(300,293,36,1);



getContentPane().add(vert
icalLine1);



verticalLine1.setBounds(276,82,2,338);



getContentPane().add(verticalLine2);



verticalLine2.setBounds(300,82,2,314);



getContentPane().add(horizontalLine1);



horizontalLine1.setBounds(276,420,122,2);



getContentPane().add(horizontalLine2
);



horizontalLine2.setBounds(300,396,74,2);



try {




blue_fluid.setFillColor(java.awt.Color.blue);



}



catch(java.beans.PropertyVetoException e) { }



try {




blue_fluid.setFillMode(true);



}



catch(java.beans.PropertyVetoException e) { }



getCon
tentPane().add(blue_fluid);



blue_fluid.setForeground(java.awt.Color.blue);



blue_fluid.setBounds(276,174,24,119);



try {




yellow_fluid_left.setFillColor(java.awt.Color.yellow);



}



catch(java.beans.PropertyVetoException e) { }



try {




yellow_flu
id_left.setFillMode(true);



}



catch(java.beans.PropertyVetoException e) { }



getContentPane().add(yellow_fluid_left);



yellow_fluid_left.setForeground(java.awt.Color.yellow);



yellow_fluid_left.setBounds(276,293,24,112);



try {




yellow_fluid_botto
m.setFillColor(java.awt.Color.yellow);



}



catch(java.beans.PropertyVetoException e) { }



try {




yellow_fluid_bottom.setFillMode(true);



}



catch(java.beans.PropertyVetoException e) { }



getContentPane().add(yellow_fluid_bottom);



yellow_fluid_bot
tom.setForeground(java.awt.Color.yellow);



yellow_fluid_bottom.setBounds(276,396,120,24);



try {




yellow_fluid_right.setFillColor(java.awt.Color.yellow);



}



catch(java.beans.PropertyVetoException e) { }



try {




yellow_fluid_right.setFillMode(true
);



}



catch(java.beans.PropertyVetoException e) { }



getContentPane().add(yellow_fluid_right);



yellow_fluid_right.setForeground(java.awt.Color.yellow);



yellow_fluid_right.setBounds(372,293,24,112);



try {




white_behind_blue.setFillColor(java.awt
.Color.white);



}



catch(java.beans.PropertyVetoException e) { }



try {




white_behind_blue.setFillMode(true);



}



catch(java.beans.PropertyVetoException e) { }



getContentPane().add(white_behind_blue);



white_behind_blue.setForeground(java.awt.Col
or.white);



white_behind_blue.setBounds(276,60,24,276);



try {




bulb.setFillColor(java.awt.Color.white);



}



catch(java.beans.PropertyVetoException e) { }



try {




bulb.setFillMode(true);



}



catch(java.beans.PropertyVetoException e) { }



getCon
tentPane().add(bulb);



bulb.setForeground(java.awt.Color.black);



bulb.setBounds(228,12,120,72);



JLabel1.setText("Interactive Manometer");



getContentPane().add(JLabel1);



JLabel1.setForeground(java.awt.Color.black);



JLabel1.setFont(new Font("Dialo
g", Font.BOLD, 20));



JLabel1.setBounds(12,6,252,49);



JLabel2.setText("Bulb Pressure");



getContentPane().add(JLabel2);



JLabel2.setForeground(new java.awt.Color(128,0,0));



JLabel2.setBounds(12,60,144,26);



JLabel3.setText("Blue Fluid Density");



getContentPane().add(JLabel3);



JLabel3.setForeground(java.awt.Color.blue);



JLabel3.setBounds(12,120,132,12);



JLabel4.setText("Blue Fluid Head");



getContentPane().add(JLabel4);



JLabel4.setForeground(java.awt.Color.blue);



JLabel4.setBounds(12,168
,134,15);



JLabel5.setText("Calculate the yellow fluid head (h) at");



getContentPane().add(JLabel5);



JLabel5.setForeground(new java.awt.Color(102,102,153));



JLabel5.setBounds(12,264,252,12);



JLabel6.setText("at the selected conditions");



getCont
entPane().add(JLabel6);



JLabel6.setBounds(12,276,220,14);



JLabel7.setText("Enter here:");



getContentPane().add(JLabel7);



JLabel7.setBounds(48,300,96,24);



getContentPane().add(answer_label);



answer_label.setForeground(java.awt.Color.black);



an
swer_label.setBounds(12,396,229,14);



JLabel10.setHorizontalAlignment(com.sun.java.swing.SwingConstants.CENTER);



JLabel10.setText("Ambient Pressure");



getContentPane().add(JLabel10);



JLabel10.setForeground(new java.awt.Color(128,128,64));



JLabel10
.setBounds(312,132,120,12);



JLabel11.setHorizontalAlignment(com.sun.java.swing.SwingConstants.CENTER);



JLabel11.setText("(13.0 psi)");



getContentPane().add(JLabel11);



JLabel11.setForeground(new java.awt.Color(128,128,64));



JLabel11.setBounds(324,
144,106,13);



bulb_slider.setMinimum(3);



bulb_slider.setMinorTickSpacing(1);



bulb_slider.setValue(10);



bulb_slider.setMaximum(26);



getContentPane().add(bulb_slider);



bulb_slider.setBounds(12,84,228,24);



density_slider.setMinimum(3);



density_
slider.setValue(5);



density_slider.setMaximum(6);



getContentPane().add(density_slider);



density_slider.setForeground(new java.awt.Color(153,153,204));



density_slider.setBounds(12,132,144,24);



head_slider.setMinimum(10);



head_slider.setValue(17)
;



head_slider.setMaximum(20);



getContentPane().add(head_slider);



head_slider.setBounds(12,180,145,26);



JLabel12.setText("Yellow Fluid Density:");



getContentPane().add(JLabel12);



JLabel12.setForeground(java.awt.Color.yellow);



JLabel12.setBound
s(12,216,156,12);



JLabel13.setText("20 g/cc");



getContentPane().add(JLabel13);



JLabel13.setForeground(java.awt.Color.yellow);



JLabel13.setFont(new Font("Dialog", Font.BOLD, 15));



JLabel13.setBounds(180,216,88,15);



head_label.setText("17");



ge
tContentPane().add(head_label);



head_label.setForeground(java.awt.Color.blue);



head_label.setFont(new Font("Dialog", Font.BOLD, 15));



head_label.setBounds(180,180,24,24);



JLabel15.setText("5");



getContentPane().add(JLabel15);



JLabel15.setForegr
ound(java.awt.Color.blue);



JLabel15.setFont(new Font("Dialog", Font.BOLD, 15));



JLabel15.setBounds(180,132,24,24);



JLabel16.setText("g/cc");



getContentPane().add(JLabel16);



JLabel16.setForeground(java.awt.Color.blue);



JLabel16.setFont(new Font(
"Dialog", Font.BOLD, 14));



JLabel16.setBounds(216,132,48,24);



JLabel17.setText("in");



getContentPane().add(JLabel17);



JLabel17.setForeground(java.awt.Color.blue);



JLabel17.setFont(new Font("Dialog", Font.BOLD, 14));



JLabel17.setBounds(216,180,2
4,24);



h_label.setText("h");



getContentPane().add(h_label);



h_label.setForeground(new java.awt.Color(102,102,153));



h_label.setBounds(324,288,12,24);



h_label.setVisible(false);



getContentPane().add(guess_field);



guess_field.setBounds(156,300,
60,24);



check_button.setText("Check Calculation");



check_button.setActionCommand("Check Calculation");



getContentPane().add(check_button);



check_button.setBounds(24,348,193,27);



try {




rect1.setFillColor(java.awt.Color.lightGray);



}



catch(j
ava.beans.PropertyVetoException e) { }



try {




rect1.setFillMode(true);



}



catch(java.beans.PropertyVetoException e) { }



getContentPane().add(rect1);



rect1.setBounds(5,252,228,168);



//}}





//{{REGISTER_LISTENERS



SymChange lSymChange = new S
ymChange();



bulb_slider.addChangeListener(lSymChange);



density_slider.addChangeListener(lSymChange);



head_slider.addChangeListener(lSymChange);



SymMouse aSymMouse = new SymMouse();



bulb_slider.addMouseListener(aSymMouse);



density_slider.addMous
eListener(aSymMouse);



head_slider.addMouseListener(aSymMouse);



check_button.addMouseListener(aSymMouse);



//}}


}



//{{DECLARE_CONTROLS


com.sun.java.swing.JLabel Pbulb = new com.sun.java.swing.JLabel();


symantec.itools.awt.shape.VerticalLine vertic
alLine5 = new
symantec.itools.awt.shape.VerticalLine();


symantec.itools.awt.shape.VerticalLine verticalLine3 = new
symantec.itools.awt.shape.VerticalLine();


symantec.itools.awt.shape.VerticalLine verticalLine4 = new
symantec.itools.awt.shape.VerticalLine
();


symantec.itools.awt.shape.HorizontalLine horizontalLine3 = new
symantec.itools.awt.shape.HorizontalLine();


symantec.itools.awt.shape.HorizontalLine horizontalLine4 = new
symantec.itools.awt.shape.HorizontalLine();


symantec.itools.awt.shape.VerticalL
ine verticalLine1 = new
symantec.itools.awt.shape.VerticalLine();


symantec.itools.awt.shape.VerticalLine verticalLine2 = new
symantec.itools.awt.shape.VerticalLine();


symantec.itools.awt.shape.HorizontalLine horizontalLine1 = new
symantec.itools.awt.shap
e.HorizontalLine();


symantec.itools.awt.shape.HorizontalLine horizontalLine2 = new
symantec.itools.awt.shape.HorizontalLine();


symantec.itools.awt.shape.Rect blue_fluid = new symantec.itools.awt.shape.Rect();


symantec.itools.awt.shape.Rect yellow_fluid_
left = new symantec.itools.awt.shape.Rect();


symantec.itools.awt.shape.Rect yellow_fluid_bottom = new symantec.itools.awt.shape.Rect();


symantec.itools.awt.shape.Rect yellow_fluid_right = new symantec.itools.awt.shape.Rect();


symantec.itools.awt.shape.R
ect white_behind_blue = new symantec.itools.awt.shape.Rect();


symantec.itools.awt.shape.Ellipse bulb = new symantec.itools.awt.shape.Ellipse();


com.sun.java.swing.JLabel JLabel1 = new com.sun.java.swing.JLabel();


com.sun.java.swing.JLabel JLabel2 = new
com.sun.java.swing.JLabel();


com.sun.java.swing.JLabel JLabel3 = new com.sun.java.swing.JLabel();


com.sun.java.swing.JLabel JLabel4 = new com.sun.java.swing.JLabel();


com.sun.java.swing.JLabel JLabel5 = new com.sun.java.swing.JLabel();


com.sun.java.swi
ng.JLabel JLabel6 = new com.sun.java.swing.JLabel();


com.sun.java.swing.JLabel JLabel7 = new com.sun.java.swing.JLabel();


com.sun.java.swing.JLabel answer_label = new com.sun.java.swing.JLabel();


com.sun.java.swing.JLabel JLabel10 = new com.sun.java.swi
ng.JLabel();


com.sun.java.swing.JLabel JLabel11 = new com.sun.java.swing.JLabel();


com.sun.java.swing.JSlider bulb_slider = new com.sun.java.swing.JSlider();


com.sun.java.swing.JSlider density_slider = new com.sun.java.swing.JSlider();


com.sun.java.swi
ng.JSlider head_slider = new com.sun.java.swing.JSlider();


com.sun.java.swing.JLabel JLabel12 = new com.sun.java.swing.JLabel();


com.sun.java.swing.JLabel JLabel13 = new com.sun.java.swing.JLabel();


com.sun.java.swing.JLabel head_label = new com.sun.jav
a.swing.JLabel();


com.sun.java.swing.JLabel JLabel15 = new com.sun.java.swing.JLabel();


com.sun.java.swing.JLabel JLabel16 = new com.sun.java.swing.JLabel();


com.sun.java.swing.JLabel JLabel17 = new com.sun.java.swing.JLabel();


com.sun.java.swing.JLabe
l h_label = new com.sun.java.swing.JLabel();


com.sun.java.swing.JTextField guess_field = new com.sun.java.swing.JTextField();


com.sun.java.swing.JButton check_button = new com.sun.java.swing.JButton();


symantec.itools.awt.shape.Rect rect1 = new symantec
.itools.awt.shape.Rect();


//}}



class SymChange implements com.sun.java.swing.event.ChangeListener


{



public void stateChanged(com.sun.java.swing.event.ChangeEvent event)



{




Object object = event.getSource();




if (object == bulb_slider)





bulbS
lider_stateChanged(event);




else if (object == density_slider)





densitySlider_stateChanged(event);




else if (object == head_slider)





headSlider_stateChanged(event);



}


}



void bulbSlider_stateChanged(com.sun.java.swing.event.ChangeEvent event)


{



// to do: code goes here.








bulb_slider_stateChanged_Interaction1(event);


}



void bulb_slider_stateChanged_Interaction1(com.sun.java.swing.event.ChangeEvent event)


{



try {




// Pbulb Set the JLabel's text; convert int
-
>class java.lang.Stri
ng; bulb_slider Get
the JSlider's current value




Pbulb.setText(java.lang.String.valueOf(bulb_slider.getValue()+" psi"));



} catch (Exception e) {



}


}



void densitySlider_stateChanged(com.sun.java.swing.event.ChangeEvent event)


{



// to do: code go
es here.








density_slider_stateChanged_Interaction1(event);


}



void density_slider_stateChanged_Interaction1(com.sun.java.swing.event.ChangeEvent event)


{



try {




// JLabel15 Set the JLabel's text; convert int
-
>class java.lang.String;
density_sl
ider Get the JSlider's current value




JLabel15.setText(java.lang.String.valueOf(density_slider.getValue()));



} catch (Exception e) {



}


}



void headSlider_stateChanged(com.sun.java.swing.event.ChangeEvent event)


{



// to do: code goes here.








head_slider_stateChanged_Interaction1(event);








head_slider_stateChanged_Interaction2(event);


}



void head_slider_stateChanged_Interaction1(com.sun.java.swing.event.ChangeEvent event)


{



try {




// head_label Set the JLabel's text; convert int
-
>
class java.lang.String;
head_slider Get the JSlider's current value




head_label.setText(java.lang.String.valueOf(head_slider.getValue()));



} catch (Exception e) {



}


}



void head_slider_stateChanged_Interaction2(com.sun.java.swing.event.ChangeEvent
event)


{



try {




// Resize the blue rectangle according to the head_slider's value




bhead();







} catch (Exception e) {



}


}



class SymMouse extends java.awt.event.MouseAdapter


{



public void mouseClicked(java.awt.event.MouseEvent event)



{




Object object = event.getSource();




if (object == check_button)





checkButton_mouseClicked(event);



}




public void mouseReleased(java.awt.event.MouseEvent event)



{




Object object = event.getSource();




if (object == bulb_slider)





bulbSlid
er_mouseReleased(event);




else if (object == density_slider)





densitySlider_mouseReleased(event);




else if (object == head_slider)





headSlider_mouseReleased(event);



}


}



void bulbSlider_mouseReleased(java.awt.event.MouseEvent event)


{



// T
his recalculates and relocates the manometer fluids.



new_ht();




}



void densitySlider_mouseReleased(java.awt.event.MouseEvent event)


{



// recalculates the heights



new_ht();







}



void headSlider_mouseReleased(java.awt.event.MouseEvent event)


{



// recalculates the heights



new_ht();







}



void checkButton_mouseClicked(java.awt.event.MouseEvent event)


{



// This takes the value from guess_field and compares it to the correct value



// it then gives the corresponding message.



















check_button_mouseClicked_Interaction1(event);


}



void check_button_mouseClicked_Interaction1(java.awt.event.MouseEvent event)


{



try {











double guess1 =
java.lang.Double.valueOf(guess_field.getText()).doubleValue();








if(Math.ab
s(guess1
-
h_diff()) > 0.05)




{





answer_label.setText("Wrong!! Correct value = " +
java.lang.String.valueOf(h_diff()).substring(0,5));




}




else





answer_label.setText("Good Job!!");















} catch (Exception e) {



}


}

}