wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes calcApplet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calcApplet" Watch "calcApplet" New topic
Author

calcApplet

joey_g30
Greenhorn

Joined: Aug 29, 2002
Posts: 4
CalcApplet.java uses or overides a deprecated API
recompile with -deprecation for details?

import java.lang.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;
import java.math.*;
public class CalcApplet extends Applet implements Runnable, ActionListener
{
int Counter;//counts the number of digits entered
double Result;//the answer displayed, as well as the second
//operator taken for an operation
double Operand;//the first number entered for an operation

double Mem;//the variable which holds whatever value the user
//wants kept in "memory"

boolean DecimalFlag;//the 'flag' that will signify whether or not the
//decimal button has been pressed

boolean SignFlag;//the 'flag' that will signify whether or not the
//plus/minus button has been pressed

boolean OperatorKey;//the 'flag' that will signify whether or not any
//operator button has been pressed

boolean FunctionKey;//the 'flag' that will signify whether or not any f
//function button has been pressed

int Operator;//an integer value to indicate which operator
//button was pressed

char currchar;//a character to hold the value of the key most
//recently pressed

String GrStatus;//String to hold the status of various graphic
//operations of the program

String Status;//String to hold the status of various parts
//of the program
Thread timer;//A thread that will count how long user has been
//working with the calculator

int secs = 0;//counts seconds, used by Thread timer
int mins = 0;//counts minutes, used by Thread timer
int hrs = 0;//counts hours, used by Thread timer

//A string to hold the currentCount as indicated by the above variables
String currentCount = "Count started...";

//A Label that will display the current count on the calculator
Label CountTimer = new Label(" ",Label.LEFT);

//A string to hold the currentTime as indicated by the above variables
String currentTime = "Current Time";
//A Canvas that will display the current time on the calculator
Canvas currTime;

//This label will display all error messages
Label DisplError = new Label(" ",Label.CENTER);


Label LabelMem = new Label(" ",Label.RIGHT);

Label lcdDisplay = new Label("0",Label.RIGHT);

// This is the declaration of all numeric buttons to be used in the applet

Button button1 = new Button("1");
Button button2 = new Button("2");
Button button3 = new Button("3");
Button button4 = new Button("4");
Button button5 = new Button("5");
Button button6 = new Button("6");
Button button7 = new Button("7");
Button button8 = new Button("8");
Button button9 = new Button("9");
Button button0 = new Button("0");

Button buttonMinus = new Button("-");
Button buttonMultiply = new Button("x");
Button buttonPlus = new Button("+");
Button buttonEquals = new Button("=");
Button buttonDivide = new Button("�");
Button buttonClear = new Button("C");
Button buttonDecimal = new Button(".");
Button buttonNegative = new Button("�");
Button buttonMPlus = new Button("M+");
Button buttonMClear = new Button("MC");
Button buttonMR = new Button("MR");
Button buttonPercent = new Button("%");
Button buttonOneOverX = new Button("1/X");
Button buttonSqr = new Button("x�");
Button buttonSqrRoot = new Button("sqrt");

public void init()
{
//Allows for configuring a layout with the restraints of a grid or
//something similar
setLayout(null);

//This will resize the applet to the width and height provided
resize(420,368);

//This sets the default font to Helvetica, plain, size 12
setFont(new Font("Helvetica", Font.PLAIN, 12));

lcdDisplay.setBounds(42,15,308,30);
lcdDisplay.setFont(new Font("Helvetica", Font.PLAIN, 20));
lcdDisplay.setForeground(new Color(65280));
lcdDisplay.setBackground(new Color(0));
add(lcdDisplay);


LabelMem.setBounds(350,15,20,30);
LabelMem.setFont(new Font("Helvetica", Font.PLAIN, 16));
LabelMem.setForeground(new Color(65280));
LabelMem.setBackground(new Color(0));
add(LabelMem);

button1.addActionListener(this);
button1.setBounds(42,65,60,34);
button1.setFont(new Font("Dialog", Font.BOLD, 18));
add(button1);
button2.addActionListener(this);
button2.setBounds(106,65,60,34);
button2.setFont(new Font("Dialog", Font.BOLD, 18));
add(button2);
button3.addActionListener(this);
button3.setBounds(170,65,60,34);
button3.setFont(new Font("Dialog", Font.BOLD, 18));
add(button3);
button4.addActionListener(this);
button4.setBounds(42,104,60,34);
button4.setFont(new Font("Dialog", Font.BOLD, 18));
add(button4);
button5.addActionListener(this);
button5.setBounds(106,104,60,34);
button5.setFont(new Font("Dialog", Font.BOLD, 18));
add(button5);
button6.addActionListener(this);
button6.setBounds(170,104,60,34);
button6.setFont(new Font("Dialog", Font.BOLD, 18));
add(button6);
button7.addActionListener(this);
button7.setBounds(42,142,60,34);
button7.setFont(new Font("Dialog", Font.BOLD, 18));
add(button7);
button8.addActionListener(this);
button8.setBounds(106,142,60,34);
button8.setFont(new Font("Dialog", Font.BOLD, 18));
add(button8);
button9.addActionListener(this);
button9.setBounds(170,142,60,34);
button9.setFont(new Font("Dialog", Font.BOLD, 18));
add(button9);
button0.addActionListener(this);
button0.setBounds(42,180,60,34);
button0.setFont(new Font("Dialog", Font.BOLD, 18));
add(button0);

buttonDecimal.addActionListener(this);
buttonDecimal.setBounds(106,180,60,34);
buttonDecimal.setFont(new Font("Dialog", Font.BOLD, 18));
add(buttonDecimal);
buttonNegative.addActionListener(this);
buttonNegative.setBounds(170,180,60,34);
buttonNegative.setFont(new Font("Dialog", Font.BOLD, 18));
add(buttonNegative);
buttonMinus.addActionListener(this);
buttonMinus.setBounds(234,104,60,34);
buttonMinus.setFont(new Font("Dialog", Font.BOLD, 18));
add(buttonMinus);
buttonMultiply.addActionListener(this);
buttonMultiply.setBounds(234,142,60,34);
buttonMultiply.setFont(new Font("Dialog", Font.BOLD, 18));
add(buttonMultiply);
buttonPlus.addActionListener(this);
buttonPlus.setBounds(234,65,60,34);
buttonPlus.setFont(new Font("Dialog", Font.BOLD, 18));
add(buttonPlus);
buttonPercent.addActionListener(this);
buttonPercent.setBounds(42,230,60,34);
buttonPercent.setFont(new Font("Dialog", Font.BOLD, 18));
add(buttonPercent);
buttonOneOverX.addActionListener(this);
buttonOneOverX.setBounds(106,230,60,34);
buttonOneOverX.setFont(new Font("Dialog", Font.BOLD, 18));
add(buttonOneOverX);
buttonSqr.addActionListener(this);
buttonSqr.setBounds(170,230,60,34);
buttonSqr.setFont(new Font("Dialog", Font.BOLD, 18));
add(buttonSqr);
buttonSqrRoot.addActionListener(this);
buttonSqrRoot.setBounds(234,230,60,34);
buttonSqrRoot.setFont(new Font("Dialog", Font.BOLD, 18));
add(buttonSqrRoot);

buttonEquals.addActionListener(this);
buttonEquals.setBounds(309,230,60,34);
buttonEquals.setFont(new Font("Dialog", Font.BOLD, 18));
add(buttonEquals);
buttonDivide.addActionListener(this);
buttonDivide.setBounds(234,180,60,34);
buttonDivide.setFont(new Font("Dialog", Font.BOLD, 18));
add(buttonDivide);
buttonClear.addActionListener(this);
buttonClear.setBounds(309,65,60,34);
buttonClear.setFont(new Font("Dialog", Font.BOLD, 18));
buttonClear.setForeground(new Color(16711680));
buttonClear.setBackground(new Color(12632256));
add(buttonClear);

buttonMPlus.addActionListener(this);
buttonMPlus.setBounds(309,104,60,34);
buttonMPlus.setFont(new Font("Dialog", Font.BOLD, 18));
buttonMPlus.setForeground(Color.blue);
add(buttonMPlus);
buttonMClear.addActionListener(this);
buttonMClear.setBounds(309,142,60,34);
buttonMClear.setFont(new Font("Dialog", Font.BOLD, 18));
buttonMClear.setForeground(Color.blue);
add(buttonMClear);
buttonMR.addActionListener(this);
buttonMR.setBounds(309,180,60,34);
buttonMR.setFont(new Font("Dialog", Font.BOLD, 18));
buttonMR.setForeground(Color.blue);
add(buttonMR);

DisplError.setBounds(42,278,329,15);
DisplError.setFont(new Font("Dialog", Font.BOLD, 12));
DisplError.setForeground(new Color(16711680));
DisplError.setBackground(new Color(0));
add(DisplError);


CountTimer.setBounds(42,309,164,25);
CountTimer.setFont(new Font("Dialog", Font.BOLD, 15));
CountTimer.setForeground(Color.cyan);
CountTimer.setBackground(Color.gray);
CountTimer.setText(currentCount);
add(CountTimer);


currTime = new Canvas();
currTime.setBounds(206,309,165,25);
currTime.setFont(new Font("Dialog", Font.BOLD, 15));
currTime.setForeground(Color.orange);
currTime.setBackground(Color.gray);
add(currTime);

Clicked_Clear();//calls the Clicked_Clear method (C button)

}//end of calc init method


public final static int OpMinus=11,
OpMultiply=12,
OpPlus=13,
OpDivide=15,
OpMPlus=19,
OpMClear=20,
OpMR=21;

void DisplayError(String err_msg)
{

DisplError.setText(err_msg);
}

public void NumericButton(int i)
{
DisplayError(" ");//Clears the error message field


String Display = lcdDisplay.getText();

if (OperatorKey == true)
{
Counter = 0;
}

Counter = Counter + 1;//increments the counter

if ((Display == "0") || (Status == "FIRST"))
{
Display= "";//Do not display any new info
}
if (Counter < 21)//if more than 20 numbers are entered
{
//The number just entered is appended to the string currently displayed
Display = Display + String.valueOf(i);
}
else
{
//call the DisplayError method and send it an error message string
DisplayError("Digit Limit of 20 Digits Reached");
}
lcdDisplay.setText(Display);//sets the text of the lcdDisplay
//Label
Status = "VALID";//sets the Status string to valid
OperatorKey = false;//no operator key was pressed
FunctionKey = false;//no function key was pressed
}

public void OperatorButton(int i)
{
DisplayError(" ");//Clears the error message field


Result = (new Double(lcdDisplay.getText())).doubleValue();

//If no operator key has been pressed OR a function has been pressed
if ((OperatorKey == false) || (FunctionKey = true))
{
switch (Operator)//depending on the operation performed
{

case OpPlus : Result = Operand + Result;
break;


case OpMinus : Result = Operand - Result;
break;


case OpMultiply : Result = Result * Operand;
break;


case OpDivide : if (Result == 0)
{
//set the Status string to indicate an
//an error
Status = "ERROR";

//display the word "ERROR" on the
//lcdDisplay label
lcdDisplay.setText("ERROR");


DisplayError("ERROR: Division by Zero");
}
else
{
//divide the two numbers and put the
//answer in double Result
Result = Operand / Result;
}
}

//if after breaking from the switch the Status string is not set
//to "ERROR"
if (Status != "ERROR")
{
Status = "FIRST";

Operand = Result;//Operand holds the value of Result

Operator = i;

//The lcdDisplay label has the value of double Result
//displayed
lcdDisplay.setText(String.valueOf(Result));

//The boolean decimal flag is set false, indicating that the
//decimal button has not been pressed
DecimalFlag = false;

//The boolean sign flag is set false, indicating that the sign
//button has not been pressed
SignFlag = false;

//The boolean OperatorKey is set true, indicating that a simple
//operation has been performed
OperatorKey = true;

//The boolean FunctionKey is set false, indicating that a
//function key has not been pressed
FunctionKey = false;

DisplayError(" ");//Clears the error message field
}
}

}//end of OperatorButton method

public void DecimalButton()
{
DisplayError(" ");//Clears the error message field


String Display = lcdDisplay.getText();

//if a simple operation was performed successfully
if (Status == "FIRST")
{
Display = "0";//set Display string to character 0
}
//If the decimal button has not already been pressed
if (!DecimalFlag)
{
//appends a decimal to the string Display
Display = Display + ".";
}
else
{

DisplayError("Number already has a Decimal Point");
}


lcdDisplay.setText(Display);
DecimalFlag = true;//the decimal key has been pressed
Status = "VALID";
OperatorKey = false; //no operator key has been pressed

}//end of the DecimalButton method

void PercentButton()
{
DisplayError(" ");//clears the error message field


String Display = lcdDisplay.getText();

if ((Status != "FIRST") || (Display != "0"))
{
Result = (new Double(lcdDisplay.getText())).doubleValue();

//divide the double Result by 100, getting the percentage
Result = Result / 100;


lcdDisplay.setText(String.valueOf(Result));
Status = "FIRST";//
OperatorKey = true;//an operator key has been pressed
FunctionKey = true;//a function key has been pressed
}
}//end of the PercentButton method

void Clicked_Clear()
{
Counter = 0;//sets the counter to zero
Status = "FIRST";//sets Status to FIRST
Operand = 0;//sets Operand to zero
Result = 0;//sets Result to zero
Operator = 0;//sets Operator integer to zero

DecimalFlag = false;//decimal button has not been
//pressed

SignFlag = false;//sign button has not been pressed

OperatorKey = false;//no operator button has been
//pressed

FunctionKey = false;//no function button has been
//pressed


lcdDisplay.setText("0");
DisplayError(" ");//clears the error message field
}

void PlusMinusButton()
{
DisplayError(" ");//clears the error message field


String Display = lcdDisplay.getText();

if ((Status != "FIRST") || (Display != "0"))
{

Result = (new Double(lcdDisplay.getText())).doubleValue();

//sets the double Result to it's negative value
Result = -Result;


lcdDisplay.setText(String.valueOf(Result));
Status = "VALID";//sets Status string to VALID
SignFlag = true;//the sign button has been pressed
DecimalFlag = true;//a decimal has appeared
}
}//end of the PlusMinusButton method

void SqrButton()
{
DisplayError(" ");//clears the error message field


String Display = lcdDisplay.getText();

if ((Status != "FIRST") || (Display != "0"))
{

Result = (new Double(lcdDisplay.getText())).doubleValue();


Result = Result * Result;


lcdDisplay.setText(String.valueOf(Result));

Status = "FIRST";//indicates this is the first time
//this button has been pressed

OperatorKey = true;//an operator button has been pressed
FunctionKey = true;//a function button has been pressed
}
}//end of the SqrButton method


void SqrRootButton()
{
DisplayError(" ");//clears the error message field


String Display = lcdDisplay.getText();

if ((Status != "FIRST") || (Display != "0"))
{

Result = (new Double(lcdDisplay.getText())).doubleValue();


Result = Math.sqrt(Result);


lcdDisplay.setText(String.valueOf(Result));

Status = "FIRST";//indicates this is the first time
//this button has been pressed

OperatorKey = true;//an operator button has been pressed
FunctionKey = true;//a function button has been pressed
}
}//end of the SqrRootButton method
void OneOverXButton()
{
DisplayError(" ");//clears the error message field


String Display = lcdDisplay.getText();

if ((Status != "FIRST") || (Display != "0"))
{

Result = (new Double(lcdDisplay.getText())).doubleValue();

//divides one by the double Result
Result = 1 / Result;


lcdDisplay.setText(String.valueOf(Result));

Status = "FIRST";//indicates that this is the first time
//this button has been pressed

OperatorKey = true;//an operator key has been pressed
FunctionKey = true;//a function key has been pressed
}
}//end of the OneOverXButton method

void MemoryButton(int i)
{
DisplayError(" ");//clears the error message field


String Display = lcdDisplay.getText();

//depending on the value sent representing the buttons
switch (i)
{

case OpMPlus : if (((Display == "0.") || (Display == "0")) && (Mem == 0))
{
//clears the LabelMem label
LabelMem.setText(" ");
}
else
{

double temp = (new Double(lcdDisplay.getText())).doubleValue();

//set the Mem variable with that the sum of what's currently in
//Mem and the temp variable
Mem = Mem + temp;


LabelMem.setText("M");
}
break;


case OpMR : lcdDisplay.setText(String.valueOf(Mem));
break;


case OpMClear : Mem = 0;

//clears the LableMem field
LabelMem.setText(" ");
break;
}
Status = "FIRST";//indicates that this is first time
//button has been pressed

OperatorKey = true;//an operator button has been pressed

//if the Mem variable has the value zero
if (Mem == 0)
{
LabelMem.setText(" ");//clear the LabelMem field
}
}//end of the MemoryButton method


public void update(Graphics g)
{


//Sets the color to white and draw a rectangle around the applet
g.setColor(Color.white);
g.drawRect(0,0,420,368);

//sets the color to black and draws lines down the east and south sides
//of the applet to make it appear three-dimensional
g.setColor(Color.black);
g.drawLine(419,0,419,367);
g.drawLine(0,367,419,367);

//sets the color to gray and draws lines right next to the black lines
//to enhance the three-dimensional effect
g.setColor(Color.gray);
g.drawLine(418,1,418,366);
g.drawLine(1,366,418,366);

//sets the color to gray and draws a rectangle around the lcdDisplay
//label to give it some depth
g.setColor(Color.gray);
g.drawRect(41,14,329,31);

//sets the color to yellow and draws a rectangle around the DisplError
//label to give it some importance and help attract the eye to errors
//displayed there
g.setColor(Color.yellow);
g.drawRect(41,277,330,16);

if (GrStatus == "Timer")//checks for the timer indicator GrStatus
{
++secs;//increment seconds
if(secs == 60)//when they equal 60
{
mins++;//increment minutes
secs = 0;//set seconds to zero
}

if(mins == 60)//when minutes are equal to 60
{
hrs++;//increment hours
secs = 0;//set seconds to zero
mins = 0;//set minutes to zero
}

//if hours are less than ten, put a zero in front of the value,
//otherwise display as is and assign it to string currentCount
if(hrs < 10) { currentCount = "0" + hrs + ":"; }
else { currentCount = hrs + ":"; }

//if minutes are less than ten, put a zero in front of the value,
//otherwise display as is and append it to string currentCount
if(mins < 10) { currentCount = currentCount + "0" + mins + ":"; }
else { currentCount = currentCount + mins + ":"; }

//if seconds are less than ten, put a zero in front of the value,
//otherwise display as is and append it to string currentCount
if(secs < 10) {currentCount = currentCount + "0" + secs; }
else { currentCount = currentCount + secs; }

//sets the Text on CountTimer label to a "Time Used - " portion and
//appends the string currentCount
CountTimer.setText("Time Used - " + currentCount);
}
if (GrStatus == "Error")//when GrStatus indicates an error
{
CountTimer.setText("Error!");//set the text of label CountTimer
//to "Error!"
}
}

public void actionPerformed(ActionEvent event)
{

Object src = event.getSource();


if (src instanceof Button)
{

if ((Status != "ERROR") || (src == buttonClear))
{

if (src == button1)
{
NumericButton(1);
}
if (src == button2)
{
NumericButton(2);
}
if (src == button3)
{
NumericButton(3);
}
if (src == button4)
{
NumericButton(4);
}
if (src == button5)
{
NumericButton(5);
}
if (src == button6)
{
NumericButton(6);
}
if (src == button7)
{
NumericButton(7);
}
if (src == button8)
{
NumericButton(8);
}
if (src == button9)
{
NumericButton(9);
}
if (src == button0)
{
NumericButton(0);
}
if (src == buttonMinus)
{
OperatorButton(11);
}
if (src == buttonMultiply)
{
OperatorButton(12);
}
if (src == buttonPlus)
{
OperatorButton(13);
}
if (src == buttonEquals)
{
OperatorButton(14);
}
if (src == buttonDivide)
{
OperatorButton(15);
}
if (src == buttonDecimal)
{
DecimalButton();
}
if (src == buttonPercent)
{
PercentButton();
}
if (src == buttonClear)
{
Clicked_Clear();
}
if (src == buttonNegative)
{
PlusMinusButton();
}
if (src == buttonSqr)
{
SqrButton();
}
if (src == buttonSqrRoot)
{
SqrRootButton();
}
if (src == buttonOneOverX)
{
OneOverXButton();
}
if (src == buttonMPlus)
{
MemoryButton(19);
}
if (src == buttonMClear)
{
MemoryButton(20);
}
if (src == buttonMR)
{
MemoryButton(21);
}
}
}
}//end of actionPerformed method
public boolean keyDown(Event evt, int key)
{
//assigns key value to currchar through typecasting key to a character
currchar = (char)key;
if (currchar == '0') { NumericButton(0); }
if (currchar == '1') { NumericButton(1); }
if (currchar == '2') { NumericButton(2); }
if (currchar == '3') { NumericButton(3); }
if (currchar == '4') { NumericButton(4); }
if (currchar == '5') { NumericButton(5); }
if (currchar == '6') { NumericButton(6); }
if (currchar == '7') { NumericButton(7); }
if (currchar == '8') { NumericButton(8); }
if (currchar == '9') { NumericButton(9); }

if (currchar == '/') { OperatorButton(15); }
if (currchar == '*') { OperatorButton(12); }
if (currchar == '-') { OperatorButton(11); }
if (currchar == '+') { OperatorButton(13); }

if (currchar == '=') { OperatorButton(14); }

//This condition is different from the others because it tests for the
//Enter key being pressed, and this is pre-built into the Event evt
//object
if (currchar == evt.ENTER) { OperatorButton(14); }


if (currchar == '.') { DecimalButton(); }

return true;//indicate successful operation
}

//overridden start method
public void start()
{
try//try this code
{
if (timer == null)//if the timer doesn't exist
{
timer = new Thread(this);//creates a new Thread, passing the
//applet as the argument

timer.start();//starts the timer Thread
}

//creates a new Clock object, passing it the Canvas currTime
Clock clock1 = new Clock(currTime);
}
//catches a NullPointerException and stops the thread if one occurs
catch (NullPointerException e) { stop(); }
}

//overridden stop method
public void stop()
{
try//try this code
{
if (timer != null)//if the timer Thread exists
{
timer.stop();//stop the timer thread
}
}
//catches a NullPointerException
catch (NullPointerException e) {}
}

//overridden run method
public void run()
{
while (true)//while the thread exists
{
try//try executing this code
{
GrStatus = "Timer";//sets GrStatus

timer.sleep(1000);//puts the timer thread to "sleep" for
//a thousand milliseconds, or one second
}
//catches an InteruptedException if one occurs
catch(InterruptedException e)
{
GrStatus = "Error";//indicates an error has occured
timer.stop();//stops the thread
}
//catches a NullPointerException if one occurs
catch(java.lang.NullPointerException e)
{
GrStatus = "Error";//indicates an error has occured
timer.stop();//stops the thread
}
repaint();//calls the repaint method
}
}

}//end of calc class

class Clock extends Thread
{
//A Canvas that will display the current time on the calculator
Canvas Time;

//A Date object that will access the current time
private Date now;

//A string to hold the current time
private String currentTime;

//The constructor for Clock, accepting a Label as an argument
public Clock(Canvas _Time)
{
Time = _Time;//_Time is passed by reference, so Time
//now refers to the same Canvas

start();//start this thread
}

//The overriden run method of this thread
public void run()
{
//while this thread exists
while (true)
{
try
{
draw_clock();//calls the draw_clock method

sleep(1000);//puts this thread to sleep for one
//second
}
//catches an InterruptedException that the sleep() method might throw
catch (InterruptedException e) { suspend(); }

//catches a NullPointerException and suspends the thread if one occurs
catch (NullPointerException e) { suspend(); }
}
}

//A method to draw the current time onto the Time Canvas on the applet
public void draw_clock()
{
try
{
//Obtains the Graphics object from the Canvas Time so that it can
//be manipulated directly
Graphics g = Time.getGraphics();

g.setColor(Color.gray);//sets the color of the Graphics object
//to gray for the rectangle background

g.fillRect(0,0,165,25);//fills the Canvas area with a rectangle
//starting at 0,0 coordinates of the Canvas
//and extending to the length and width

g.setColor(Color.orange);//sets the color of the Graphics object
//to orange for the text color

get_the_time();//calls the get_the_time() method

//calls the drawString method of the Graphics object g, which will
//draw a string to the screen
//
//Accepts a string and two integers to represent the coordinates
g.drawString("Current Time - " + currentTime, 0, 17);
}
//catches a NullPointerException and suspends the thread if one occurs
catch (NullPointerException e) { suspend(); }
}

//A method to obtain the current time, accurate to the second
public void get_the_time()
{
//creates a new Date object for "now" every time this is called
now = new Date( );

//integers to hold the hours, minutes and seconds of the current time
int a = now.getHours();
int b = now.getMinutes();
int c = now.getSeconds();

if (a == 0) a = 12;//if hours are zero, set them to twelve

if (a > 12) a = a -12;//if hours are greater than twelve, make a
//conversion to civilian time, as opposed to
//24-hour time

if ( a < 10)//if hours are less than 10
//sets the currentTime string to 0, appends a's value and a
//colon
currentTime = "0" + a + ":" ;
else
//otherwise set currentTime string to "a", append a colon
currentTime = a +":";

if (b < 10)//if minutes are less than ten

//append a zero to string currentTime, then append "b" and a colon
currentTime = currentTime + "0" + b + ":" ;
else
//otherwise append "b" and a colon to currentTime string
currentTime = currentTime + b + ":" ;

if (c < 10)//if seconds are less than ten

//append a zero to string currentTime, then append "c" and a colon
currentTime = currentTime + "0" + c ;
else
//otherwise append "c" to currentTime string
currentTime = currentTime + c;
}
}//end of the Clock class
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
firewolfe32,
Please change your display name as requested in a previous post.
Did you mean to ask, "What does it mean that something is deprecated and how do I compile with the suggested switch? And what about my program is deprecated?"


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
1077 lines of code ....
Did you recompile using
javac -deprecation CalcApplet.java
??


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calcApplet