|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| 01/04/2009 at 04:05AM PST, ID: 24023462 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: |
package Assignment2;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class pkgshapes extends java.applet.Applet implements ActionListener
{
// Define Labels, Text Fields and Buttons to be used in Applet
Label displayLabel, enterLabel, radiusLabel, lengthLabel, heightLabel ;
Label areaCircleLabel, circumCircleLabel;
TextField displayBox, enterBox, radiusBox, lengthBox, heightBox ;
TextField areaCircleBox, circumCircleBox;
Button drawCircle = new Button("Draw A Circle");
Button drawRectangle = new Button("Draw A Rectangle");
Button calculate = new Button("Calculate");
// Define String's used to determine which button pressed
String isCircle="N", isRectangle="N", isCal = "N", calCircle = "N", calRectangle = "N";
String inputString;
// Define variables to hold radius, length and height values
// Define variables to hold caluclated values
int radius, length, height, areaRectangle, premRectangle;
double areaCircle, circumCircle;
final double pi = 3.14;
/************************************************************************/
/** Initialisation Function **/
/************************************************************************/
public void init() {
// Add circle button with action listener
add(drawCircle);
drawCircle.addActionListener(this);
// Add Rectangle button with action listener
add(drawRectangle);
drawRectangle.addActionListener(this);
// Add Label for Radius Text Box
enterLabel = new Label ( "Enter Radius" ) ;
enterBox = new TextField (12 ) ;
radiusLabel = new Label ( "Enter Radius of Circle" ) ;
radiusLabel.setVisible(false);
add ( radiusLabel ) ;
radiusBox = new TextField ( 12 ) ;
// Hide radius box
radiusBox.setVisible(false);
add ( radiusBox ) ;
lengthLabel = new Label ( "Enter Length of Rectangle" ) ;
lengthLabel.setVisible(false);
add ( lengthLabel ) ;
lengthBox = new TextField ( 12 ) ;
lengthBox.setVisible(false);
add ( lengthBox ) ;
heightLabel = new Label ( "Enter Height of Rectangle" ) ;
heightLabel.setVisible(false);
add ( heightLabel ) ;
heightBox = new TextField ( 12 ) ;
heightBox.setVisible(false);
add ( heightBox ) ;
calculate.setVisible(false);
add(calculate);
calculate.addActionListener(this);
}
/************************************************************************/
/** Paint Function **/
/************************************************************************/
public void paint(Graphics gscreen)
{
inputString = "";
// Circle Button Pressed, display box to accept radius
if( isCircle== "Y" ){
isCircle = "N";
calCircle = "Y";
// Display box to accept radius
radiusBox.setText ( "" ) ;
radiusLabel.setVisible(true);
radiusBox.setVisible(true);
radiusBox.requestFocus();
// Hide Length and height boxes
lengthLabel.setVisible(false);
lengthBox.setVisible(false);
heightLabel.setVisible(false);
heightBox.setVisible(false);
// Display Calculate Button
calculate.setVisible(true);
// Re-set value of Calculate Circle
calRectangle = "N";
}
else if (isRectangle == "Y"){
lengthBox.setText ( "" ) ;
lengthLabel.setVisible(true);
lengthBox.setVisible(true);
heightBox.setText ( "" ) ;
heightLabel.setVisible(true);
heightBox.setVisible(true);
radiusLabel.setVisible(false);
radiusBox.setVisible(false);
lengthBox.requestFocus();
isRectangle = "N";
calRectangle = "Y";
// Re-set value of Calculate Circle
calCircle = "N";
calculate.setVisible(true);
}
// Calculate Button Pressed
else if (isCal == "Y" ){
// Calculate Dimensions and Draw a Circle
if (calCircle == "Y" ){
inputString = radiusBox.getText() ;
radius = Integer.valueOf( inputString ).intValue();
// Calculate the area of the Circle 3.14 * radius * radius
areaCircle = radius * radius * pi;
circumCircle = (radius * 2) * pi;
gscreen.drawString("Area of the Circle is " + areaCircle,80, radius + 130);
gscreen.drawString("Circumference of the Circle is " + circumCircle,80,radius + 150);
// Draw Circle with parameter given
gscreen.setColor(Color.red);
gscreen.drawOval(85,105,radius,radius);
}
// Calculate Dimensions and Draw a Rectangle
if (calRectangle == "Y" ){
inputString = lengthBox.getText() ;
length = Integer.valueOf( inputString ).intValue();
inputString = heightBox.getText() ;
height = Integer.valueOf( inputString ).intValue();
// Calculate the area of the Rectangle length * breadth
areaRectangle = length * height;
premRectangle = 2 * ( length * height );
gscreen.drawString("Area of the Rectangle is " + areaRectangle,80, height + 120);
gscreen.drawString("Perimeter of the Rectangle is " + premRectangle,80,height + 130);
// Draw Rectangle with length and Height given
gscreen.setColor(Color.red);
gscreen.fillRect(85, 105, length,height);
}
}
}
/************************************************************************/
/** Actioned Performed Function **/
/************************************************************************/
public void actionPerformed ( ActionEvent event )
{
// Deal with the button click event Find out which Button generated the event
String arg = event.getActionCommand() ;
if ( arg.equals( "Clear" ) ){
// Re-set Boxes when clear button selected
}
// Clear not selected, Check if Pound or Euro selected
else
{
try
{
// Draw Circle button pressed
if (event.getSource()==drawCircle){
isCircle = "Y";
isRectangle = "N";
repaint();
}
// Draw Rectangle button pressed
if (event.getSource()==drawRectangle){
isCircle = "N";
isRectangle = "Y";
repaint();
}
// Caluclate button pressed
if (event.getSource() == calculate){
isCal = "Y";
repaint();
}
}
/**********************************************************************/
/** Value entered by user was not an integer **/
/**********************************************************************/
catch ( NumberFormatException entry ){
showStatus ( "Error: Invalid Input - please enter a valid number" ) ;
}
}
}
}
|
Advertisement