How do I convert an applet to a standalone application.

Hi Everyone,
I am currently working on this Applet, I have tried putting the main in and building a frame to hold the applet but everytime I try something I just get new errors, What I conclusively want to do is put the applet in a frame and add menus to the frame. I have listed the code below, its quite a lot, I hope someone can help though, am pulling hair out.
Many Thanks. Chris
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
  public class SciCalc extends Applet implements ActionListener
  // Entered a UID due to String conversion
    private static final long serialVersionUID = 1;
       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
                    //function button has been pressed
       boolean Rad,Grad,Deg;     //The 'flags' that will signify that Rad, Grad or
                    //deg 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
//     LABEL DECLARATIONS 
     //This label will display all error messages
       Label DisplError = new Label(" ",Label.CENTER);
       //This label is just to the left of the Display Label lcdDisplay, and will
       //indicate whether or not a value is being held in the calculator's "memory"
       Label LabelMem = new Label(" ",Label.LEFT);
       Label LabelRad = new Label(" ",Label.CENTER);
       Label LabelDeg = new Label(" ",Label.CENTER);
       Label LabelGrad = new Label(" ",Label.CENTER);
     //This is the Display Label, which is declared as a label so the user will not
        //be able to enter any text into it to possibly crash the calculator
       Label lcdDisplay = new Label("0",Label.RIGHT);
       Label SciCalc = new Label ("Sci Calc V1.0",Label.CENTER);
//      END OF LABEL DECLARATIONS 
public void surround (Graphics g){
    g.setColor(new Color(0,0,0));
    g.drawRect(0,0,350,400);
//      DELCLARATION OF NUMERIC BUTTONS
       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");
//      END OF NUMERIC BUTTON DECLARATION
//     DECLARATION OF OPERATOR BUTTONS
       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 buttonMPlus      = new Button("M+");
       Button buttonMClear     = new Button("MC");
       Button buttonMRecall       = new Button("MR");
//     END OF OPERATOR BUTTON DECLARATION 
//     SCIENTIFIC BUTTON DECLARATION
       Button buttonPi            = new Button("Pi");
       Button buttonSqrt       = new Button("Sqrt");
       Button buttonCbrt       = new Button("Cbrt");
       Button buttonx2            = new Button("x2");
       Button buttonyX         = new Button("yX");
       Button buttonPlusMinus  = new Button("+-");
       Button buttonRad        = new Button("RAD");
       Button buttonGrad       = new Button("GRAD");
       Button buttonDeg        = new Button("DEG");
       Button buttonSin        = new Button("SIN");
       Button buttonCos           = new Button("COS");
       Button buttonTan        = new Button("TAN");
       Button buttonExp        = new Button("EXP");
       Button buttonLogn           = new Button("Ln");
       Button buttonOpenBracket  = new Button("(");
       Button buttonLog        = new Button("log");
//     END OF SCIENTIFIC BUTTON DECLARATION
//     START OF INIT METHOD
//This the only method that is called explicitly -- every other method is
//called depending on the user's actions.
public void init()
//Allows for configuring a layout with the restraints of a grid or
//something similar
     setLayout(null);
         //APPLET DEFAULTS
    //This will resize the applet to the width and height provided
         resize(350,400);
    //This sets the default font to Helvetica, plain, size 12
              setFont(new Font("Helvetica", Font.PLAIN, 12));
    //This sets the applet background colour
                   setBackground(new Color(219,240,219));
     //END OF APPLET DEFAULTS
     //LABEL INITIALISATION     
//Display Panel, which appears at the top of the screen. The label is
//placed and sized with the setBounds(x,y,width,height) method, and the
//font, foreground color and background color are all set. Then the
//label is added to the layout of the applet.
         lcdDisplay.setBounds(42,15,253,30);
         lcdDisplay.setFont(new Font("Helvetica", Font.PLAIN, 14));
         lcdDisplay.setForeground(new Color(0,0,0));
         lcdDisplay.setBackground(new Color(107,128,128));
         add(lcdDisplay);
//Memory Panel, which appears just to the right of the Display Panel.
//The label is placed and sized with the setBounds(x,y,width,height)
//method, and the font, foreground color and background color are all
//set. Then the label is added to the layout of the applet.
         LabelMem.setBounds(20,15,20,30);
         LabelMem.setFont(new Font("Helvetica", Font.BOLD, 16));
         LabelMem.setForeground(new Color(193,0,0));
         LabelMem.setBackground(new Color(0,0,0));
         add(LabelMem);
//Rad,Grad and Deg panels,which appear below the memory panel.
         LabelRad.setBounds(20,50,20,15);
         LabelRad.setFont(new Font("Helvetica", Font.BOLD, 8));
         LabelRad.setForeground(new Color(193,0,0));
         LabelRad.setBackground(new Color(0,0,0));
         add(LabelRad);
         LabelDeg.setBounds(20,70,20,15);
         LabelDeg.setFont(new Font("Helvetica", Font.BOLD, 8));
         LabelDeg.setForeground(new Color(193,0,0));
         LabelDeg.setBackground(new Color(0,0,0));
         add(LabelDeg);
         LabelGrad.setBounds(20,90,20,15);
         LabelGrad.setFont(new Font("Helvetica", Font.BOLD, 8));
         LabelGrad.setForeground(new Color(193,0,0));
         LabelGrad.setBackground(new Color(0,0,0));
         add(LabelGrad);
//SciCalc v1.0 Label, this merely indicates the name.        
         SciCalc.setBounds(60,350,200,50);
         SciCalc.setFont(new Font("papyrus", Font.BOLD, 25));
         SciCalc.setForeground(new Color(0,50,191));
         SciCalc.setBackground(new Color(219,219,219));
         add(SciCalc);
     //END OF LABEL INITIALISATION
     //NUMERIC BUTTON INITIALISATION
         button1.addActionListener(this);
         button1.setBounds(42,105,60,34);
         button1.setForeground(new Color(0,0,0));
         button1.setBackground(new Color(128,128,128));
         button1.setFont(new Font("Dialog", Font.BOLD, 18));
         add(button1);
         button2.addActionListener(this);
         button2.setBounds(106,105,60,34);
         button2.setForeground(new Color(0,0,0));
         button2.setBackground(new Color(128,128,128));
         button2.setFont(new Font("Dialog", Font.BOLD, 18));
         add(button2);
         button3.addActionListener(this);
         button3.setBounds(170,105,60,34);
         button3.setForeground(new Color(0,0,0));
         button3.setBackground(new Color(128,128,128));
         button3.setFont(new Font("Dialog", Font.BOLD, 18));
         add(button3);
         button4.addActionListener(this);
         button4.setBounds(42,145,60,34);
         button4.setForeground(new Color(0,0,0));
         button4.setBackground(new Color(128,128,128));
         button4.setFont(new Font("Dialog", Font.BOLD, 18));
         add(button4);
         button5.addActionListener(this);
         button5.setBounds(106,145,60,34);
         button5.setForeground(new Color(0,0,0));
         button5.setBackground(new Color(128,128,128));
         button5.setFont(new Font("Dialog", Font.BOLD, 18));
         add(button5);
         button6.addActionListener(this);
         button6.setBounds(170,145,60,34);
         button6.setForeground(new Color(0,0,0));
         button6.setBackground(new Color(128,128,128));
         button6.setFont(new Font("Dialog", Font.BOLD, 18));
         add(button6);
         button7.addActionListener(this);
         button7.setBounds(42,185,60,34);
         button7.setForeground(new Color(0,0,0));
         button7.setBackground(new Color(128,128,128));
         button7.setFont(new Font("Dialog", Font.BOLD, 18));
         add(button7);
         button8.addActionListener(this);
         button8.setBounds(106,185,60,34);
         button8.setForeground(new Color(0,0,0));
         button8.setBackground(new Color(128,128,128));
         button8.setFont(new Font("Dialog", Font.BOLD, 18));
         add(button8);
         button9.addActionListener(this);
         button9.setBounds(170,185,60,34);
         button9.setForeground(new Color(0,0,0));
         button9.setBackground(new Color(128,128,128));
         button9.setFont(new Font("Dialog", Font.BOLD, 18));
         add(button9);
         button0.addActionListener(this);
         button0.setBounds(106,225,60,34);
         button0.setForeground(new Color(0,0,0));
         button0.setBackground(new Color(128,128,128));
         button0.setFont(new Font("Dialog", Font.BOLD, 18));
         add(button0);
     //END OF NUMERIC BUTTON INITIALISATION        
     //OPERATOR BUTTON INITIALISATION         
         buttonDecimal.addActionListener(this);
         buttonDecimal.setBounds(42,225,60,34);
         buttonDecimal.setForeground(new Color(0,0,0));
         buttonDecimal.setBackground(new Color(254,204,82));
         buttonDecimal.setFont(new Font("Dialog", Font.BOLD, 18));
         add(buttonDecimal);
         buttonPlusMinus.addActionListener(this);
         buttonPlusMinus.setBounds(106,325,60,17);
         buttonPlusMinus.setForeground(new Color(0,0,0));
         buttonPlusMinus.setBackground(new Color(0,118,191));
         buttonPlusMinus.setFont(new Font("Dialog", Font.BOLD, 16));
         add(buttonPlusMinus);
         buttonMinus.addActionListener(this);
         buttonMinus.setBounds(234,145,60,34);
         buttonMinus.setForeground(new Color(0,0,0));
         buttonMinus.setBackground(new Color(254,204,82));
         buttonMinus.setFont(new Font("Dialog", Font.BOLD, 18));
         add(buttonMinus);
         buttonMultiply.addActionListener(this);
         buttonMultiply.setBounds(234,225,60,34);
         buttonMultiply.setForeground(new Color(0,0,0));
         buttonMultiply.setBackground(new Color(254,204,82));
         buttonMultiply.setFont(new Font("Dialog", Font.BOLD, 18));
         add(buttonMultiply);
         buttonPlus.addActionListener(this);
         buttonPlus.setBounds(234,105,60,34);
         buttonPlus.setForeground(new Color(0,0,0));
         buttonPlus.setBackground(new Color(254,204,82));
         buttonPlus.setFont(new Font("Dialog", Font.BOLD, 18));
         add(buttonPlus);
         buttonEquals.addActionListener(this);
         buttonEquals.setBounds(170,225,60,34);
         buttonEquals.setForeground(new Color(0,0,0));
         buttonEquals.setBackground(new Color(254,204,82));
         buttonEquals.setFont(new Font("Dialog", Font.BOLD, 18));
         add(buttonEquals);
         buttonDivide.addActionListener(this);
         buttonDivide.setBounds(234,185,60,34);
         buttonDivide.setForeground(new Color(0,0,0));
         buttonDivide.setBackground(new Color(254,204,82));
         buttonDivide.setFont(new Font("Dialog", Font.BOLD, 18));
         add(buttonDivide);
         buttonClear.addActionListener(this);
         buttonClear.setBounds(234,65,60,34);
         buttonClear.setFont(new Font("Dialog", Font.BOLD, 18));
         buttonClear.setForeground(new Color(0,0,0));
         buttonClear.setBackground(new Color(193,0,0));
         add(buttonClear);
         buttonMPlus.addActionListener(this);
         buttonMPlus.setBounds(170,65,60,34);
         buttonMPlus.setFont(new Font("Dialog", Font.BOLD, 18));
         buttonMPlus.setForeground(new Color(0,0,0));
         buttonMPlus.setBackground(new Color(254,204,82));
         add(buttonMPlus);
         buttonMClear.addActionListener(this);
         buttonMClear.setBounds(42,65,60,34);
         buttonMClear.setForeground(new Color(193,0,0));
         buttonMClear.setBackground(new Color(254,204,82));
         buttonMClear.setFont(new Font("Dialog", Font.BOLD, 18));
         add(buttonMClear);
         buttonMRecall.addActionListener(this);
         buttonMRecall.setBounds(106,65,60,34);
         buttonMRecall.setForeground(new Color(0,0,0));
         buttonMRecall.setBackground(new Color(254,204,82));
         buttonMRecall.setFont(new Font("Dialog", Font.BOLD, 18));
         add(buttonMRecall);
     //END OF OPERATOR BUTTON INITIALISATION
     // SCIENTIFIC BUTTONS INITIALISATION   
         buttonPi.addActionListener(this);
         buttonPi.setBounds(42,265,60,17);
         buttonPi.setForeground(new Color(0,0,0));
         buttonPi.setBackground(new Color(0,118,191));
         buttonPi.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonPi);
         buttonSqrt.addActionListener(this);
         buttonSqrt.setBounds(106,265,60,17);
         buttonSqrt.setForeground(new Color(0,0,0));
         buttonSqrt.setBackground(new Color(0,118,191));
         buttonSqrt.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonSqrt);
         buttonCbrt.addActionListener(this);
         buttonCbrt.setBounds(170,265,60,17);
         buttonCbrt.setForeground(new Color(0,0,0));
         buttonCbrt.setBackground(new Color(0,118,191));
         buttonCbrt.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonCbrt);
         buttonyX.addActionListener(this);
         buttonyX.setBounds(42,285,60,17);
         buttonyX.setForeground(new Color(0,0,0));
         buttonyX.setBackground(new Color(0,118,191));
         buttonyX.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonyX);
         buttonx2.addActionListener(this);
         buttonx2.setBounds(234,265,60,17);
         buttonx2.setForeground(new Color(0,0,0));
         buttonx2.setBackground(new Color(0,118,191));
         buttonx2.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonx2);
         buttonRad.addActionListener(this);
         buttonRad.setBounds(170,285,60,17);
         buttonRad.setForeground(new Color(0,0,0));
         buttonRad.setBackground(new Color(0,118,191));
         buttonRad.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonRad);
         buttonGrad.addActionListener(this);
         buttonGrad.setBounds(234,285,60,17);
         buttonGrad.setForeground(new Color(0,0,0));
         buttonGrad.setBackground(new Color(0,118,191));
         buttonGrad.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonGrad);
         buttonDeg.addActionListener(this);
         buttonDeg.setBounds(106,285,60,17);
         buttonDeg.setForeground(new Color(0,0,0));
         buttonDeg.setBackground(new Color(0,118,191));
         buttonDeg.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonDeg);
         buttonSin.addActionListener(this);
         buttonSin.setBounds(42,305,60,17);
         buttonSin.setForeground(new Color(0,0,0));
         buttonSin.setBackground(new Color(0,118,191));
         buttonSin.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonSin);
         buttonCos.addActionListener(this);
         buttonCos.setBounds(106,305,60,17);
         buttonCos.setForeground(new Color(0,0,0));
         buttonCos.setBackground(new Color(0,118,191));
         buttonCos.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonCos);
         buttonTan.addActionListener(this);
         buttonTan.setBounds(170,305,60,17);
         buttonTan.setForeground(new Color(0,0,0));
         buttonTan.setBackground(new Color(0,118,191));
         buttonTan.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonTan);
         buttonExp.addActionListener(this);
         buttonExp.setBounds(234,305,60,17);
         buttonExp.setForeground(new Color(193,0,0));
         buttonExp.setBackground(new Color(0,118,191));
         buttonExp.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonExp);
         buttonLogn.addActionListener(this);
         buttonLogn.setBounds(234,325,60,17);
         buttonLogn.setForeground(new Color(0,0,0));
         buttonLogn.setBackground(new Color(0,118,191));
         buttonLogn.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonLogn);
         buttonOpenBracket.addActionListener(this);
         buttonOpenBracket.setBounds(42,325,60,17);
         buttonOpenBracket.setForeground(new Color(0,0,0));
         buttonOpenBracket.setBackground(new Color(0,118,191));
         buttonOpenBracket.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonOpenBracket);
         buttonLog.addActionListener(this);
         buttonLog.setBounds(170,325,60,17);
         buttonLog.setForeground(new Color(0,0,0));
         buttonLog.setBackground(new Color(0,118,191));
         buttonLog.setFont(new Font("Dialog", Font.BOLD, 10));
         add(buttonLog);
     //END OF SCIENTIFIC BUTTON INITIALISATION     
     //DISPLERROR INITIALISATION      
         DisplError.setBounds(42,45,253,15);
         DisplError.setFont(new Font("Dialog", Font.BOLD, 8));
         DisplError.setForeground(new Color(16711680));
         DisplError.setBackground(new Color(0));
         add(DisplError);
     //END OF DISPLERROR INITIALISATION
         Clicked_Clear();      //calls the Clicked_Clear method (C button)
     } //END OF INIT METHOD
//The following integers are declared as final as they will
//be used for determining which button has been pushed
     public final static int OpMinus=11,
                                 OpMultiply=12,
                                 OpPlus=13,
                                 OpDivide=15,
                                 OpMPlus=19,
                                 OpMClear=20,
                                 OpMR=21,
                                 OpyX=22,
                                 OpExp=23;
//This method is called whenever anything needs to be displayed
//in the error message field at the bottom of the calculator,
//accepting a String as an argument
  void DisplayError(String err_msg)
//Calls the setText method of the Label DisplError, sending
//whatever string it received initially
    DisplError.setText(err_msg);
//This method is called whenever a numeric button (0-9) is pushed.
public void NumericButton(int i)
     DisplayError(" ");      //Clears the error message field
//Declares a String called Display that will initialize to whatever
//is currently displayed in the lcdDisplay of the calculator
    String Display = lcdDisplay.getText();
//Checks if an operator key has just been pressed, and if it has,
//then the limit of 20 digits will be reset for the user so that
//they can enter in up to 20 new numbers
         if (OperatorKey == true)
           Counter = 0;
         Counter = Counter + 1;    //increments the counter
//This is a condition to see if the number currently displayed is zero OR
//an operator key other than +, -, *, or / has been pressed.
         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
//This method is called whenever an operator button is pressed, and is   
//sent an integer value representing the button pressed.
       public void OperatorButton(int i)
     DisplayError(" ");      //Clears the error message field
//Creates a new Double object with the specific purpose of retaining
//the string currently on the lcdDisplay label, and then immediately
//converts that string into a double-precision real number and then
//gives that number to the variable Result.
         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
//if the user pressed the addition button, add the two numbers
//and put them in double Result
        case OpPlus     : Result = Operand + Result;
                  break;
//if the user pressed the subtraction button, subtract the two
//numbers and put them in double Result
     case OpMinus    : Result = Operand - Result;
                  break;
//if the user pressed the multiplication button, multiply
//the two numbers and put them in double Result
        case OpMultiply : Result = Result * Operand;
                  break;
//if the user pressed the yX button, take first number
//and multiply it to the power of the second number                 
     case OpyX : double temp1=Operand;
                    for (int loop=0; loop<Result-1; loop++){
                          temp1= temp1*Operand;
                    Result=temp1;
                  break;
//if the user pressed the Exp button -----------------Find out what this does-------------         
     case OpExp :  temp1=10;
                      for(int loop=0; loop<Result-1; loop++)
                      temp1=temp1*10;
                       Result=Result*temp1;
                 break;
//if the user pressed the division button, check to see if
//the second number entered is zero to avoid a divide-by-zero
//exception
        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");
                    //call the DisplayError method and
                    //send it a string indicating an error
                    //has occured and of what type
                    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";      //set the Status string to "FIRST" to
                             //indicate that a simple operation was
                             //not performed
        Operand = Result; //Operand holds the value of Result
        Operator = i;   //the integer value representing the
                        //operation being performed is stored
                        //in the integer Operator
        //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
  //This is a method that is called whenever the decimal button is
  //pressed.
  public void DecimalButton()
    DisplayError(" ");    //Clears the error message field
  //Declares a String called Display that will initialize to whatever
  //is currently displayed in the lcdDisplay of the calculator
    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
           //calls the DisplayError method, sending a string
           //indicating that the number already has a decimal
      DisplayError("Number already has a Decimal Point");
         //calls the setText method of the Label lcdDisplay and
          //sends it the string Display
    lcdDisplay.setText(Display);
     DecimalFlag = true;        //the decimal key has been pressed
         Status = "VALID";        //Status string indicates a valid
                           //operation has been performed
    OperatorKey = false;         //no operator key has been pressed
  } //end of the DecimalButton method
  /* This method is called whenever the percent button is pressed
  void Open_Bracket(){
    String Display = "(";
    lcdDisplay.setText(Display);//-----------Change this--------------
//This method is called first when the calculator is initialized
//with the init() method, and is called every time the "C" button
//is pressed
  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
//calls the setText method of Label lcdDisplay and sends
//it the character "0"
    lcdDisplay.setText("0"); 
    DisplayError(" ");           //clears the error message field
//This method is called whenever the sign button is pressed
     void PlusMinusButton()
    DisplayError(" ");           //clears the error message field
//Declares a String called Display that will initialize to whatever
//is currently displayed in the lcdDisplay of the calculator
    String Display = lcdDisplay.getText();
//if Status is not set to FIRST and the Display string does not
//hold the value "0"
    if ((Status != "FIRST") || (Display != "0"))
//Creates a new Double object with the specific purpose of retaining
//the string currently on the lcdDisplay label, and then immediately
//converts that string into a double-precision real number and then
//gives that number to the variable Result.
      Result = (new Double(lcdDisplay.getText())).doubleValue();
      //sets the double Result to it's negative value
      Result = -Result;
      //call the setText method of Label lcdDisplay and send it the string
      //that represents the value in 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
//This method is called whenever the square button is pressed */
     void SqrButton()
    DisplayError(" ");      //clears the error message field
//Declares a String called Display that will initialize to whatever
//is currently displayed in the lcdDisplay of the calculator
    String Display = lcdDisplay.getText();
//if Status is not set to FIRST and the Display string does not
//hold the value "0"
    if ((Status != "FIRST") || (Display != "0"))
//Creates a new Double object with the specific purpose of retaining
//the string currently on the lcdDisplay label, and then immediately
//converts that string into a double-precision real number and then
//gives that number to the variable Result.
      Result = (new Double(lcdDisplay.getText())).doubleValue();
//multiply the double Result by itself, effectively squaring
//the number
      Result = Result * Result;
//call the setText method of Label lcdDisplay and send it the string
//that represents the value in Result
     lcdDisplay.setText(                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                &

Chris,
Two issues:
1) Applet has init(), start(), etc. Application has main().
2) Applet is a container and you can add stuff to it. With application, you need to create your own container.
What you want to do is code so that you can run either way. In the applet, create a Panel or JPanel and add everything to the panel. Then add the panel to the applet. Get that working as an applet.
Now add a main(). All it has to do is create a Frame or JFrame, add the panel to the frame and then call init().
On another subject, your code looks very good, except for the method length getting out of hand. Try breaking init() into pieces in a bunch of methods:
public void init() {
   doThis();
   doThat();
   doTheOther();
private void doThis() {
   // maybe a couple dozen lines here
// etc.

Similar Messages

  • How to use JDBC Connection Pools in a standalone application?

    Hi, there,
    I have a question about how to use JDBC Connection Pools in an application. I know well about connection pool itself, but I am not quite sure how to keep the pool management object alive all the time to avoid being destroyed by garbage collection.
    for example, at the website: http://www.developer.com/java/other/article.php/626291, there is a simple connection pool implementation. there are three classes:JDBCConnection, the application's gateway to the database; JDBCConnectionImpl, the real class/object to provide connection; and JDBCPool, the management class to manage connection pool composed by JDBCConnectionImpl. JDBCPool is designed by Singleton pattern to make sure only one instance. supposing there is only one client to use connection for many times, I guess it's ok because this client first needs instantiate JDBCPool and JDBCConnectionImpl and then will hold the reference to JDBCPool all the time. but how about many clients want to use this JDBCPool? supposing client1 finishes using JDBCPool and quits, then JDBCPool will be destroyed by garbage collection since there is no reference to it, also all the connections of JDBCConnectionImpl in this pool will be destroyed too. that means the next client needs recreate pool and connections! so my question is that if there is a way to keep pool management instance alive all the time to provide connection to any client at any time. I guess maybe I can set the pool management class as daemon thread to solve this problem, but I am not quite sure. besides, there is some other problems about daemon thread, for example, how to make sure there is only one daemon instance? how to quit it gracefully? because once the whole application quits, the daemon thread also quits by force. in that case, all the connections in the pool won't get chance to close.
    I know there is another solution by JNDI if we develop servlet application. Tomcat provides an easy way to setup JNDI database pooling source that is available to JSP and Servlet. but how about a standalone application? I mean there is no JNDI service provider. it seems a good solution to combine Commons DBCP with JNID or Apache's Naming (http://jakarta.apache.org/commons/dbcp/index.html). but still, I don't know how to keep pool management instance alive all the time. once we create a JNDI enviroment or naming, if it will save in the memory automatically all the time? or we must implement it as a daemon thread?
    any hint will be great apprieciated!
    Sam

    To my knoledge the pool management instance stays alive as long as the pool is alive. What you have to figure out is how to keep a reference to it if you need to later access it.

  • How do I convert this Applet to launch from a JFrame instead??

       A simple program where the user can sketch curves and shapes in a
       variety of colors on a variety of background colors.  The user selects
       a drawing color form a pop-up menu at the top of the
       applet.  If the user clicks "Set Background", the background
       color is set to the current drawing color and the drawing
       area is filled with that color.  If the user clicks "Clear",
       the drawing area is just filled with the current background color.
       The user selects the shape to draw from another pop-up menu at the
       top of the applet.  The user can draw free-hand curves, straight
       lines, and one of six different types of shapes.
       The user's drawing is saved in an off-screen image, which is
       used to refresh the screen when repainting.  The picture is
       lost if the applet changes size, however.
       This file defines two classes, SimplePaint3,class, and
       class, SimplePaint3$Display.class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SimplePaint3 extends JApplet {
            // The main applet class simply sets up the applet.  Most of the
            // work is done in the Display class.
       JComboBox colorChoice, figureChoice;  // Pop-up menus, defined as instance
                                             // variables so that the Display
                                             // class can see them.
       public void init() {
          setBackground(Color.gray);
          getContentPane().setBackground(Color.gray);
          Display canvas = new Display();  // The drawing area.
          getContentPane().add(canvas,BorderLayout.CENTER);
          JPanel buttonBar = new JPanel();       // A panel to hold the buttons.
          buttonBar.setBackground(Color.gray);
          getContentPane().add(buttonBar, BorderLayout.SOUTH);
          JPanel choiceBar = new JPanel();       // A panel to hole the pop-up menus
          choiceBar.setBackground(Color.gray);
          getContentPane().add(choiceBar, BorderLayout.NORTH);
          JButton fill = new JButton("Set Background");  // The first button.
          fill.addActionListener(canvas);
          buttonBar.add(fill);
          JButton clear = new JButton("Clear");   // The second button.
          clear.addActionListener(canvas);
          buttonBar.add(clear);
          colorChoice = new JComboBox();  // The pop-up menu of colors.
          colorChoice.addItem("Black");
          colorChoice.addItem("Red");
          colorChoice.addItem("Green");
          colorChoice.addItem("Blue");
          colorChoice.addItem("Cyan");
          colorChoice.addItem("Magenta");
          colorChoice.addItem("Yellow");
          colorChoice.addItem("White");
          colorChoice.setBackground(Color.white);
          choiceBar.add(colorChoice);
          figureChoice = new JComboBox();  // The pop-up menu of shapes.
          figureChoice.addItem("Curve");
          figureChoice.addItem("Straight Line");
          figureChoice.addItem("Rectangle");
          figureChoice.addItem("Oval");
          figureChoice.addItem("RoundRect");
          figureChoice.addItem("Filled Rectangle");
          figureChoice.addItem("Filled Oval");
          figureChoice.addItem("Filled RoundRect");
          figureChoice.setBackground(Color.white);
          choiceBar.add(figureChoice);
       }  // end init()
       public Insets getInsets() {
              // Specify how wide a border to leave around the edges of the applet.
          return new Insets(3,3,3,3);
       private class Display extends JPanel
                  implements MouseListener, MouseMotionListener, ActionListener {
               // Nested class Display represents the drawing surface of the
               // applet.  It lets the user use the mouse to draw colored curves
               // and shapes.  The current color is specified by the pop-up menu
               // colorChoice.  The current shape is specified by another pop-up menu,
               // figureChoice.  (These are instance variables in the main class.)
               // The panel also listens for action events from buttons
               // named "Clear" and "Set Background".  The "Clear" button fills
               // the panel with the current background color.  The "Set Background"
               // button sets the background color to the current drawing color and
               // then clears.  These buttons are set up in the main class.
          private final static int
                      BLACK = 0,
                      RED = 1,            // Some constants to make
                      GREEN = 2,          // the code more readable.
                      BLUE = 3,           // These numbers code for
                      CYAN = 4,           // the different drawing colors.
                      MAGENTA = 5,
                      YELLOW = 6,
                      WHITE = 7;
          private final static int
                     CURVE = 0,
                     LINE = 1,
                     RECT = 2,               // Some constants that code
                     OVAL = 3,               // for the different types of
                     ROUNDRECT = 4,          // figure the program can draw.
                     FILLED_RECT = 5,
                     FILLED_OVAL = 6,
                     FILLED_ROUNDRECT = 7;
          /* Some variables used for backing up the contents of the panel. */
          Image OSI;  // The off-screen image (created in checkOSI()).
          int widthOfOSI, heightOfOSI;  // Current width and height of OSI.  These
                                        // are checked against the size of the applet,
                                        // to detect any change in the panel's size.
                                        // If the size has changed, a new OSI is created.
                                        // The picture in the off-screen image is lost
                                        // when that happens.
          /* The following variables are used when the user is sketching a
             curve while dragging a mouse. */
          private int mouseX, mouseY;   // The location of the mouse.
          private int prevX, prevY;     // The previous location of the mouse.
          private int startX, startY;   // The starting position of the mouse.
                                        // (Not used for drawing curves.)
          private boolean dragging;     // This is set to true when the user is drawing.
          private int figure;    // What type of figure is being drawn.  This is
                                 //    specified by the figureChoice menu.
          private Graphics dragGraphics;  // A graphics context for the off-screen image,
                                          // to be used while a drag is in progress.
          private Color dragColor;  // The color that is used for the figure that is
                                    // being drawn.
          Display() {
                 // Constructor.  When this component is first created, it is set to
                 // listen for mouse events and mouse motion events from
                 // itself.  The initial background color is white.
             addMouseListener(this);
             addMouseMotionListener(this);
             setBackground(Color.white);
          private void drawFigure(Graphics g, int shape, int x1, int y1, int x2, int y2) {
                // This method is called to do ALL drawing in this applet!
                // Draws a shape in the graphics context g.
                // The shape paramter tells what kind of shape to draw.  This
                // can be LINE, RECT, OVAL, ROUNTRECT, FILLED_RECT,
                // FILLED_OVAL, or FILLED_ROUNDRECT.  (Note that a CURVE is
                // drawn by drawing multiple LINES, so the shape parameter is
                // never equal to CURVE.)  For a LINE, a line is drawn from
                // the point (x1,y1) to (x2,y2).  For other shapes,  the
                // points (x1,y1) and (x2,y2) give two corners of the shape
                // (or of a rectangle that contains the shape).
             if (shape == LINE) {
                   // For a line, just draw the line between the two points.
                g.drawLine(x1,y1,x2,y2);
                return;
             int x, y;  // Top left corner of rectangle that contains the figure.
             int w, h;  // Width and height of rectangle that contains the figure.
             if (x1 >= x2) {  // x2 is left edge
                x = x2;
                w = x1 - x2;
             else {          // x1 is left edge
                x = x1;
                w = x2 - x1;
             if (y1 >= y2) {  // y2 is top edge
                y = y2;
                h = y1 - y2;
             else {          // y1 is top edge.
                y = y1;
                h = y2 - y1;
             switch (shape) {   // Draw the appropriate figure.
                case RECT:
                   g.drawRect(x, y, w, h);
                   break;
                case OVAL:
                   g.drawOval(x, y, w, h);
                   break;
                case ROUNDRECT:
                   g.drawRoundRect(x, y, w, h, 20, 20);
                   break;
                case FILLED_RECT:
                   g.fillRect(x, y, w, h);
                   break;
                case FILLED_OVAL:
                   g.fillOval(x, y, w, h);
                   break;
                case FILLED_ROUNDRECT:
                   g.fillRoundRect(x, y, w, h, 20, 20);
                   break;
          private void repaintRect(int x1, int y1, int x2, int y2) {
                // Call repaint on a rectangle that contains the points (x1,y1)
                // and (x2,y2).  (Add a 1-pixel border along right and bottom
                // edges to allow for the pen overhang when drawing a line.)
             int x, y;  // top left corner of rectangle that contains the figure
             int w, h;  // width and height of rectangle that contains the figure
             if (x2 >= x1) {  // x1 is left edge
                x = x1;
                w = x2 - x1;
             else {          // x2 is left edge
                x = x2;
                w = x1 - x2;
             if (y2 >= y1) {  // y1 is top edge
                y = y1;
                h = y2 - y1;
             else {          // y2 is top edge.
                y = y2;
                h = y1 - y2;
             repaint(x,y,w+1,h+1);
          private void checkOSI() {
               // This method is responsible for creating the off-screen image.
               // It should be called before using the OSI.  It will make a new OSI if
               // the size of the panel changes.
             if (OSI == null || widthOfOSI != getSize().width || heightOfOSI != getSize().height) {
                    // Create the OSI, or make a new one if panel size has changed.
                OSI = null;  // (If OSI already exists, this frees up the memory.)
                OSI = createImage(getSize().width, getSize().height);
                widthOfOSI = getSize().width;
                heightOfOSI = getSize().height;
                Graphics OSG = OSI.getGraphics();  // Graphics context for drawing to OSI.
                OSG.setColor(getBackground());
                OSG.fillRect(0, 0, widthOfOSI, heightOfOSI);
                OSG.dispose();
          public void paintComponent(Graphics g) {
               // Copy the off-screen image to the screen,
               // after checking to make sure it exists.  Then,
               // if a shape other than CURVE is being drawn,
               // draw it on top of the image from the OSI.
             checkOSI();
             g.drawImage(OSI, 0, 0, this);
             if (dragging && figure != CURVE) {
                g.setColor(dragColor);
                drawFigure(g,figure,startX,startY,mouseX,mouseY);
          public void actionPerformed(ActionEvent evt) {
                  // Respond when the user clicks on a button.  The
                  // command must be either "Clear" or "Set Background".
             String command = evt.getActionCommand();
             checkOSI();
             if (command.equals("Set Background")) {
                    // Set background color before clearing.
                    // Change the selected color so it is different
                    // from the background color.
                setBackground(getCurrentColor());
                if (colorChoice.getSelectedIndex() == BLACK)
                   colorChoice.setSelectedIndex(WHITE);
                else
                   colorChoice.setSelectedIndex(BLACK);
             Graphics g = OSI.getGraphics();
             g.setColor(getBackground());
             g.fillRect(0,0,getSize().width,getSize().height);
             g.dispose();
             repaint();
          private Color getCurrentColor() {
                   // Check the colorChoice menu to find the currently
                   // selected color, and return the appropriate color
                   // object.
             int currentColor = colorChoice.getSelectedIndex();
             switch (currentColor) {
                case BLACK:
                   return Color.black;
                case RED:
                   return Color.red;
                case GREEN:
                   return Color.green;
                case BLUE:
                   return Color.blue;
                case CYAN:
                   return Color.cyan;
                case MAGENTA:
                   return Color.magenta;
                case YELLOW:
                   return Color.yellow;
                default:
                   return Color.white;
          public void mousePressed(MouseEvent evt) {
                  // This is called when the user presses the mouse on the
                  // panel.  This begins a draw operation in which the user
                  // sketches a curve or draws a shape.  (Note that curves
                  // are handled differently from other shapes.  For CURVE,
                  // a new segment of the curve is drawn each time the user
                  // moves the mouse.  For the other shapes, a "rubber band
                  // cursor" is used.  That is, the figure is drawn between
                  // the starting point and the current mouse location.)
             if (dragging == true)  // Ignore mouse presses that occur
                 return;            //    when user is already drawing a curve.
                                    //    (This can happen if the user presses
                                    //    two mouse buttons at the same time.)
             prevX = startX = evt.getX();  // Save mouse coordinates.
             prevY = startY = evt.getY();
             figure = figureChoice.getSelectedIndex();
             dragColor = getCurrentColor();        
             dragGraphics = OSI.getGraphics();
             dragGraphics.setColor(dragColor);
             dragging = true;  // Start drawing.
          } // end mousePressed()
          public void mouseReleased(MouseEvent evt) {
                  // Called whenever the user releases the mouse button.
                  // If the user was drawing a shape, we make the shape
                  // permanent by drawing it to the off-screen image.
              if (dragging == false)
                 return;  // Nothing to do because the user isn't drawing.
              dragging = false;
              mouseX = evt.getX();
              mouseY = evt.getY();
              if (figure == CURVE) {
                     // A CURVE is drawn as a series of LINEs
                  drawFigure(dragGraphics,LINE,prevX,prevY,mouseX,mouseY);
                  repaintRect(prevX,prevY,mouseX,mouseY);
              else if (figure == LINE) {
                 repaintRect(startX,startY,prevX,prevY);
                 if (mouseX != startX || mouseY != startY) {
                       // Draw the line only if it has non-zero length.
                    drawFigure(dragGraphics,figure,startX,startY,mouseX,mouseY);
                    repaintRect(startX,startY,mouseX,mouseY);
              else {
                 repaintRect(startX,startY,prevX,prevY);
                 if (mouseX != startX && mouseY != startY) {
                       // Draw the shape only if both its height
                       // and width are both non-zero.
                    drawFigure(dragGraphics,figure,startX,startY,mouseX,mouseY);
                    repaintRect(startX,startY,mouseX,mouseY);
              dragGraphics.dispose();
              dragGraphics = null;
          public void mouseDragged(MouseEvent evt) {
                   // Called whenever the user moves the mouse while a mouse button
                   // is down.  If the user is drawing a curve, draw a segment of
                   // the curve on the off-screen image, and repaint the part
                   // of the panel that contains the new line segment.  Otherwise,
                   // just call repaint and let paintComponent() draw the shape on
                   // top of the picture in the off-screen image.
              if (dragging == false)
                 return;  // Nothing to do because the user isn't drawing.
              mouseX = evt.getX();   // x-coordinate of mouse.
              mouseY = evt.getY();   // y=coordinate of mouse.
              if (figure == CURVE) {
                     // A CURVE is drawn as a series of LINEs.
                 drawFigure(dragGraphics,LINE,prevX,prevY,mouseX,mouseY);
                 repaintRect(prevX,prevY,mouseX,mouseY);
              else {
                    // Repaint two rectangles:  The one that contains the previous
                    // version of the figure, and the one that will contain the
                    // new version.  The first repaint is necessary to restore
                    // the picture from the off-screen image in that rectangle.
                 repaintRect(startX,startY,prevX,prevY);
                 repaintRect(startX,startY,mouseX,mouseY);
              prevX = mouseX;  // Save coords for the next call to mouseDragged or mouseReleased.
              prevY = mouseY;
          } // end mouseDragged.
          public void mouseEntered(MouseEvent evt) { }   // Some empty routines.
          public void mouseExited(MouseEvent evt) { }    //    (Required by the MouseListener
          public void mouseClicked(MouseEvent evt) { }   //    and MouseMotionListener
          public void mouseMoved(MouseEvent evt) { }     //    interfaces).
       } // end nested class Display
    } // end class SimplePaint3

    Im quite the novice, how exactly do I go about doing that. What I did was to put both in diff files but I got errors saying that they cant find colorChoice, figureChoice in the Display class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Simple extends JFrame implements Display{
            // The main applet class simply sets up the applet.  Most of the
            // work is done in the Display class.
       JComboBox colorChoice, figureChoice;  // Pop-up menus, defined as instance
                                             // variables so that the Display
                                             // class can see them.
       public void init() {
          setBackground(Color.gray);
          getContentPane().setBackground(Color.gray);
          Display canvas = new Display();  // The drawing area.
          getContentPane().add(canvas,BorderLayout.CENTER);
          JPanel buttonBar = new JPanel();       // A panel to hold the buttons.
          buttonBar.setBackground(Color.gray);
          getContentPane().add(buttonBar, BorderLayout.SOUTH);
          JPanel choiceBar = new JPanel();       // A panel to hole the pop-up menus
          choiceBar.setBackground(Color.gray);
          getContentPane().add(choiceBar, BorderLayout.NORTH);
          JButton fill = new JButton("Set Background");  // The first button.
          fill.addActionListener(canvas);
          buttonBar.add(fill);
          JButton clear = new JButton("Clear");   // The second button.
          clear.addActionListener(canvas);
          buttonBar.add(clear);
          colorChoice = new JComboBox();  // The pop-up menu of colors.
          colorChoice.addItem("Black");
          colorChoice.addItem("Red");
          colorChoice.addItem("Green");
          colorChoice.addItem("Blue");
          colorChoice.addItem("Cyan");
          colorChoice.addItem("Magenta");
          colorChoice.addItem("Yellow");
          colorChoice.addItem("White");
          colorChoice.setBackground(Color.white);
          choiceBar.add(colorChoice);
          figureChoice = new JComboBox();  // The pop-up menu of shapes.
          figureChoice.addItem("Curve");
          figureChoice.addItem("Straight Line");
          figureChoice.addItem("Rectangle");
          figureChoice.addItem("Oval");
          figureChoice.addItem("RoundRect");
          figureChoice.addItem("Filled Rectangle");
          figureChoice.addItem("Filled Oval");
          figureChoice.addItem("Filled RoundRect");
          figureChoice.setBackground(Color.white);
          choiceBar.add(figureChoice);
       }  // end init()
    } // end class SimplePaint3
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Display extends JPanel
                  implements MouseListener, MouseMotionListener, ActionListener {
               // Nested class Display represents the drawing surface of the
               // applet.  It lets the user use the mouse to draw colored curves
               // and shapes.  The current color is specified by the pop-up menu
               // colorChoice.  The current shape is specified by another pop-up menu,
               // figureChoice.  (These are instance variables in the main class.)
               // The panel also listens for action events from buttons
               // named "Clear" and "Set Background".  The "Clear" button fills
               // the panel with the current background color.  The "Set Background"
               // button sets the background color to the current drawing color and
               // then clears.  These buttons are set up in the main class.
          private final static int
                      BLACK = 0,
                      RED = 1,            // Some constants to make
                      GREEN = 2,          // the code more readable.
                      BLUE = 3,           // These numbers code for
                      CYAN = 4,           // the different drawing colors.
                      MAGENTA = 5,
                      YELLOW = 6,
                      WHITE = 7;
          private final static int
                     CURVE = 0,
                     LINE = 1,
                     RECT = 2,               // Some constants that code
                     OVAL = 3,               // for the different types of
                     ROUNDRECT = 4,          // figure the program can draw.
                     FILLED_RECT = 5,
                     FILLED_OVAL = 6,
                     FILLED_ROUNDRECT = 7;
          /* Some variables used for backing up the contents of the panel. */
          Image OSI;  // The off-screen image (created in checkOSI()).
          int widthOfOSI, heightOfOSI;  // Current width and height of OSI.  These
                                        // are checked against the size of the applet,
                                        // to detect any change in the panel's size.
                                        // If the size has changed, a new OSI is created.
                                        // The picture in the off-screen image is lost
                                        // when that happens.
          /* The following variables are used when the user is sketching a
             curve while dragging a mouse. */
          private int mouseX, mouseY;   // The location of the mouse.
          private int prevX, prevY;     // The previous location of the mouse.
          private int startX, startY;   // The starting position of the mouse.
                                        // (Not used for drawing curves.)
          private boolean dragging;     // This is set to true when the user is drawing.
          private int figure;    // What type of figure is being drawn.  This is
                                 //    specified by the figureChoice menu.
          private Graphics dragGraphics;  // A graphics context for the off-screen image,
                                          // to be used while a drag is in progress.
          private Color dragColor;  // The color that is used for the figure that is
                                    // being drawn.
          Display() {
                 // Constructor.  When this component is first created, it is set to
                 // listen for mouse events and mouse motion events from
                 // itself.  The initial background color is white.
             addMouseListener(this);
             addMouseMotionListener(this);
             setBackground(Color.white);
          private void drawFigure(Graphics g, int shape, int x1, int y1, int x2, int y2) {
                // This method is called to do ALL drawing in this applet!
                // Draws a shape in the graphics context g.
                // The shape paramter tells what kind of shape to draw.  This
                // can be LINE, RECT, OVAL, ROUNTRECT, FILLED_RECT,
                // FILLED_OVAL, or FILLED_ROUNDRECT.  (Note that a CURVE is
                // drawn by drawing multiple LINES, so the shape parameter is
                // never equal to CURVE.)  For a LINE, a line is drawn from
                // the point (x1,y1) to (x2,y2).  For other shapes,  the
                // points (x1,y1) and (x2,y2) give two corners of the shape
                // (or of a rectangle that contains the shape).
             if (shape == LINE) {
                   // For a line, just draw the line between the two points.
                g.drawLine(x1,y1,x2,y2);
                return;
             int x, y;  // Top left corner of rectangle that contains the figure.
             int w, h;  // Width and height of rectangle that contains the figure.
             if (x1 >= x2) {  // x2 is left edge
                x = x2;
                w = x1 - x2;
             else {          // x1 is left edge
                x = x1;
                w = x2 - x1;
             if (y1 >= y2) {  // y2 is top edge
                y = y2;
                h = y1 - y2;
             else {          // y1 is top edge.
                y = y1;
                h = y2 - y1;
             switch (shape) {   // Draw the appropriate figure.
                case RECT:
                   g.drawRect(x, y, w, h);
                   break;
                case OVAL:
                   g.drawOval(x, y, w, h);
                   break;
                case ROUNDRECT:
                   g.drawRoundRect(x, y, w, h, 20, 20);
                   break;
                case FILLED_RECT:
                   g.fillRect(x, y, w, h);
                   break;
                case FILLED_OVAL:
                   g.fillOval(x, y, w, h);
                   break;
                case FILLED_ROUNDRECT:
                   g.fillRoundRect(x, y, w, h, 20, 20);
                   break;
          private void repaintRect(int x1, int y1, int x2, int y2) {
                // Call repaint on a rectangle that contains the points (x1,y1)
                // and (x2,y2).  (Add a 1-pixel border along right and bottom
                // edges to allow for the pen overhang when drawing a line.)
             int x, y;  // top left corner of rectangle that contains the figure
             int w, h;  // width and height of rectangle that contains the figure
             if (x2 >= x1) {  // x1 is left edge
                x = x1;
                w = x2 - x1;
             else {          // x2 is left edge
                x = x2;
                w = x1 - x2;
             if (y2 >= y1) {  // y1 is top edge
                y = y1;
                h = y2 - y1;
             else {          // y2 is top edge.
                y = y2;
                h = y1 - y2;
             repaint(x,y,w+1,h+1);
          private void checkOSI() {
               // This method is responsible for creating the off-screen image.
               // It should be called before using the OSI.  It will make a new OSI if
               // the size of the panel changes.
             if (OSI == null || widthOfOSI != getSize().width || heightOfOSI != getSize().height) {
                    // Create the OSI, or make a new one if panel size has changed.
                OSI = null;  // (If OSI already exists, this frees up the memory.)
                OSI = createImage(getSize().width, getSize().height);
                widthOfOSI = getSize().width;
                heightOfOSI = getSize().height;
                Graphics OSG = OSI.getGraphics();  // Graphics context for drawing to OSI.
                OSG.setColor(getBackground());
                OSG.fillRect(0, 0, widthOfOSI, heightOfOSI);
                OSG.dispose();
          public void paintComponent(Graphics g) {
               // Copy the off-screen image to the screen,
               // after checking to make sure it exists.  Then,
               // if a shape other than CURVE is being drawn,
               // draw it on top of the image from the OSI.
             checkOSI();
             g.drawImage(OSI, 0, 0, this);
             if (dragging && figure != CURVE) {
                g.setColor(dragColor);
                drawFigure(g,figure,startX,startY,mouseX,mouseY);
          public void actionPerformed(ActionEvent evt) {
                  // Respond when the user clicks on a button.  The
                  // command must be either "Clear" or "Set Background".
             String command = evt.getActionCommand();
             checkOSI();
             if (command.equals("Set Background")) {
                    // Set background color before clearing.
                    // Change the selected color so it is different
                    // from the background color.
                setBackground(getCurrentColor());
                if (colorChoice.getSelectedIndex() == BLACK)
                   colorChoice.setSelectedIndex(WHITE);
                else
                   colorChoice.setSelectedIndex(BLACK);
             Graphics g = OSI.getGraphics();
             g.setColor(getBackground());
             g.fillRect(0,0,getSize().width,getSize().height);
             g.dispose();
             repaint();
          private Color getCurrentColor() {
                   // Check the colorChoice menu to find the currently
                   // selected color, and return the appropriate color
                   // object.
             int currentColor = colorChoice.getSelectedIndex();
             switch (currentColor) {
                case BLACK:
                   return Color.black;
                case RED:
                   return Color.red;
                case GREEN:
                   return Color.green;
                case BLUE:
                   return Color.blue;
                case CYAN:
                   return Color.cyan;
                case MAGENTA:
                   return Color.magenta;
                case YELLOW:
                   return Color.yellow;
                default:
                   return Color.white;
          public void mousePressed(MouseEvent evt) {
                  // This is called when the user presses the mouse on the
                  // panel.  This begins a draw operation in which the user
                  // sketches a curve or draws a shape.  (Note that curves
                  // are handled differently from other shapes.  For CURVE,
                  // a new segment of the curve is drawn each time the user
                  // moves the mouse.  For the other shapes, a "rubber band
                  // cursor" is used.  That is, the figure is drawn between
                  // the starting point and the current mouse location.)
             if (dragging == true)  // Ignore mouse presses that occur
                 return;            //    when user is already drawing a curve.
                                    //    (This can happen if the user presses
                                    //    two mouse buttons at the same time.)
             prevX = startX = evt.getX();  // Save mouse coordinates.
             prevY = startY = evt.getY();
             figure = figureChoice.getSelectedIndex();
             dragColor = getCurrentColor();        
             dragGraphics = OSI.getGraphics();
             dragGraphics.setColor(dragColor);
             dragging = true;  // Start drawing.
          } // end mousePressed()
          public void mouseReleased(MouseEvent evt) {
                  // Called whenever the user releases the mouse button.
                  // If the user was drawing a shape, we make the shape
                  // permanent by drawing it to the off-screen image.
              if (dragging == false)
                 return;  // Nothing to do because the user isn't drawing.
              dragging = false;
              mouseX = evt.getX();
              mouseY = evt.getY();
              if (figure == CURVE) {
                     // A CURVE is drawn as a series of LINEs
                  drawFigure(dragGraphics,LINE,prevX,prevY,mouseX,mouseY);
                  repaintRect(prevX,prevY,mouseX,mouseY);
              else if (figure == LINE) {
                 repaintRect(startX,startY,prevX,prevY);
                 if (mouseX != startX || mouseY != startY) {
                       // Draw the line only if it has non-zero length.
                    drawFigure(dragGraphics,figure,startX,startY,mouseX,mouseY);
                    repaintRect(startX,startY,mouseX,mouseY);
              else {
                 repaintRect(startX,startY,prevX,prevY);
                 if (mouseX != startX && mouseY != startY) {
                       // Draw the shape only if both its height
                       // and width are both non-zero.
                    drawFigure(dragGraphics,figure,startX,startY,mouseX,mouseY);
                    repaintRect(startX,startY,mouseX,mouseY);
              dragGraphics.dispose();
              dragGraphics = null;
          public void mouseDragged(MouseEvent evt) {
                   // Called whenever the user moves the mouse while a mouse button
                   // is down.  If the user is drawing a curve, draw a segment of
                   // the curve on the off-screen image, and repaint the part
                   // of the panel that contains the new line segment.  Otherwise,
                   // just call repaint and let paintComponent() draw the shape on
                   // top of the picture in the off-screen image.
              if (dragging == false)
                 return;  // Nothing to do because the user isn't drawing.
              mouseX = evt.getX();   // x-coordinate of mouse.
              mouseY = evt.getY();   // y=coordinate of mouse.
              if (figure == CURVE) {
                     // A CURVE is drawn as a series of LINEs.
                 drawFigure(dragGraphics,LINE,prevX,prevY,mouseX,mouseY);
                 repaintRect(prevX,prevY,mouseX,mouseY);
              else {
                    // Repaint two rectangles:  The one that contains the previous
                    // version of the figure, and the one that will contain the
                    // new version.  The first repaint is necessary to restore
                    // the picture from the off-screen image in that rectangle.
                 repaintRect(startX,startY,prevX,prevY);
                 repaintRect(startX,startY,mouseX,mouseY);
              prevX = mouseX;  // Save coords for the next call to mouseDragged or mouseReleased.
              prevY = mouseY;
          } // end mouseDragged.
          public void mouseEntered(MouseEvent evt) { }   // Some empty routines.
          public void mouseExited(MouseEvent evt) { }    //    (Required by the MouseListener
          public void mouseClicked(MouseEvent evt) { }   //    and MouseMotionListener
          public void mouseMoved(MouseEvent evt) { }     //    interfaces).
       } // end nested class Display

  • How can I convert an int to a string?

    Hi
    How can I convert an int to a string?
    /ad87geao

    Here is some the code:
    public class GUI
        extends Applet {
      public GUI() { 
        lastValue = 5;
        String temp = Integer.toString(lastValue);
        System.out.println(temp);
        showText(temp);
      private void showText(final String text) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            tArea2.setText(text + "\n");
    }

  • How can I convert an InputStream to a FileInputStream ???

    How can I convert an InputStream to a FileInputStream ???

    Thanks for you reply, however, I am still stuck.
    I am trying to convert my application (which runs smoothly) to a signed applet. The following is the original (application) code:
    private void loadConfig() {
    String fileName = "resources/groupconfig";
    File name = new File(fileName);
    if(name.isFile()) {
    try {
         ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName));
         pAndGConfig = (PAGroupsConfig)in.readObject();
         in.close();
         return;
    } catch(ClassNotFoundException e) {
         System.err.println("++ERROR: "+e);
    } catch(IOException e) {
         System.err.println("++ERROR: "+e);
    System.out.println("Can't find file: " + fileName);
    Because all code and resources now reside in a Jar file (for the signed applet), I must use the following line to access the resources:
    InputStream is = this.getClass().getResourceAsStream(fileName);
    I then need to convert the 'InputStream' to 'ObjectInputStream' or 'FileInputStream' so that I can work with it.
    I would be very grateful if you could help shed some light on the matter - Cobram

  • Converting an applet into a frame

    hello.
    this is james mcfadden. I am developing a 2-player BlackJack card game in java. how do i convert the following 2 pieces of code from an applet into a frame?
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    public class Blackjack extends Applet implements ActionListener,Runnable{
         private Deck deck;     //The deck...
         private Hand player_hand;//player hand
         private Hand dealer_hand;//dealer hand.
         private Button bHit=new Button("Hit");
         private Button bStay=new Button("Stay");
         private Button bRestart=new Button("New Game");
         //lets do some double buffering.
         Image offIm=null;
         Graphics offGraphics=null;
         Dimension offDimension=null;
         Image[] card_images = new Image[52];
         private boolean cards_loaded = false;
         private int current_card_loading = 0;
         String message;                         //print a message...
         int width;          //The width of the applet
         int height;          //The height of the applet
         int card_width = -1;
         int card_padding = -1;     //How much should we pad the cards by..?
         private int games=-1;     //How many games have been played?
         public void init() {
              Thread card_loader = new Thread(this);
              card_loader.start();
         public void newGame(){
              bHit.setEnabled(true);
              bStay.setEnabled(false);
              player_hand = new Hand();     //Create new hands...
              dealer_hand = new Hand();
              //shuffle the deck.
              deck.shuffleCards();
              games++;
         public void hit(){
              bStay.setEnabled(true);
              player_hand.addCard(deck.dealCard());
              if(player_hand.getValue() > 21){
                   message = "You loose! (score:"+player_hand.getValue()+")";
                   //disable the hit and stay buttons...
                   bHit.setEnabled(false);
                   bStay.setEnabled(false);
                   return;
              message = "Score: "+player_hand.getValue();     
         public void stay(){
              while(dealer_hand.getValue() < 17){
                   dealer_hand.addCard(deck.dealCard());
              if(dealer_hand.getValue() <= 21 && player_hand.getValue() < dealer_hand.getValue())
                   message = "You loose! (" + player_hand.getValue()+
                             " - "+dealer_hand.getValue()+")";
              }else if (player_hand.getValue() == dealer_hand.getValue())
                   message = "You draw! (" + player_hand.getValue()+")";
              }else {
                   message = "You win! (" + player_hand.getValue()+
                             " - "+dealer_hand.getValue()+")";
              bHit.setEnabled(false);
              bStay.setEnabled(false);
         public void actionPerformed(ActionEvent e) {
              if(e.getSource() == bRestart)
                   newGame();
              }else if (e.getSource() == bHit)
                   hit();
              }else if (e.getSource() == bStay)
                   stay();
              repaint();
         public void paint(Graphics g) {
              update(g);
         public void update(Graphics g) {
              //lets sord out double buffering
              if(offGraphics==null){
                   offIm=createImage(getSize().width,getSize().height);
                   offGraphics=offIm.getGraphics();
              if(!cards_loaded){
                   //display a message saying we're loading the cards...
                   offGraphics.setFont(new Font("Arial",Font.PLAIN,14));
                   offGraphics.setColor(new Color(171,205,239));
                   offGraphics.fillRect(0,0,getSize().width,getSize().height);
                   offGraphics.setColor(Color.black);
                   offGraphics.drawString("Loading cards... ",5,20);
                   offGraphics.drawRect(15,40, 102 ,10);
                   offGraphics.drawRect(13,38, 106 ,14);
                   offGraphics.setColor(new Color(171,205,239));
                   offGraphics.fillRect(0,0,150,35);
                   offGraphics.setColor(Color.black);
                   offGraphics.fillRect(15,40, (current_card_loading)*2 ,10);
                   offGraphics.drawString("Loading card: "+current_card_loading+1,15,20);
              }else{
                   Image currentCard;
                   while(card_width == -1)
                        card_width = deck.getCard(0).getImage().getWidth(this);
                   if(card_padding == -1)
                        card_padding = (width - (card_width * 2) - 4) / 4;
                   //clear the background...
                   offGraphics.setColor(Color.blue);
                   offGraphics.fillRect(0,0,width,height);
                   offGraphics.setColor(Color.black);
                   offGraphics.fillRect(1,1,width-2,height-2);
                   offGraphics.setColor(Color.white);
                   offGraphics.drawString("PLAYER:",card_padding,40);
                   offGraphics.drawString("DEALER:",(width/2) + card_padding,40);
                   offGraphics.drawString(message,5,height - 20);
                   if(games > 0)
                        offGraphics.drawString(games + " game(s) played...",5,height - 10);
                   //Draw the players hand...
                   for(int i=0;i<player_hand.getCardCount();i++){
                        currentCard = player_hand.getCards().getImage();
                        offGraphics.drawImage(currentCard, card_padding, 70+(20*(i-1)), this);
                   //now draw the dealers hand...
                   for(int i=0;i<dealer_hand.getCardCount();i++){
                        currentCard = dealer_hand.getCards()[i].getImage();
                        offGraphics.drawImage(currentCard, (width/2 ) + card_padding, 70+(20*(i-1)), this);
              //draw buffered image.
              g.drawImage(offIm,0,0,this);
    public void run(){
              MediaTracker t=new MediaTracker(this);
              System.out.println("Applet getting cards...");
              for(current_card_loading=0; current_card_loading < 52; current_card_loading++){
              //try{
                   card_images[current_card_loading] = getImage(getCodeBase(),
                                                                "cards/" + (current_card_loading+1) + ".gif");
                   if(card_images[current_card_loading] == null){
                        System.out.println("Null card... ["+current_card_loading+"]");
                   }else{
                        t.addImage(card_images[current_card_loading],0);
                   try{
                        t.waitForID(0);
                   }catch(InterruptedException e){
                        System.err.println("Interrupted waiting for images..>");
                   //lets show our new status.
                   repaint();
              //create the deck object now
              deck = new Deck(this,card_images);     //Create a new deck object.
              card_width = deck.getCard(0).getImage().getWidth(this);
              bHit.addActionListener(this);
              bStay.addActionListener(this);
              bRestart.addActionListener(this);
              bHit.setEnabled(false);
              bStay.setEnabled(false);
              width = getSize().width;
              height = getSize().height;
              this.add(bHit);
              this.add(bStay);
              this.add(bRestart);
              player_hand = new Hand();     //Create the hands...
              dealer_hand = new Hand();
              //make sure that the buttons appear properly.
              this.validate();
              message = "";
              cards_loaded = true;
              System.out.println("End of thread...");
              repaint();
    import java.awt.*;
    import java.applet.*;
    import java.net.*;
    import java.io.*;
    class Deck {
         Card[] cards = new Card[52];
         int currCard;
         public Deck(Blackjack myApplet,Image[] card_images) {
              // These are the (initial) values of all the cards
              int[] values = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10};
              // Make all the cards, getting the images individually
              for (int i=0; i<52; i++) {
    //               Image image = myApplet.getImage(myApplet.getCodeBase(), "cards/" + (i+1) + ".gif");
                   cards[i] = new Card(card_images, values[i]);
              // Shuffle the cards.
              shuffleCards();
         public void shuffleCards(){
              Card temp;
              //loop through each card in the deck and swap it with some random card.
              for (int i=0; i<52; i++) {
                   int rand = (int)(Math.random()*52);
                   temp = cards[51-i];//take the current card...
                   cards[51-i] = cards[rand];//and swap it with some random card...
                   cards[rand] = temp;
              //now, reset the currentCard to deal...
              currCard = 0;
         public Card dealCard() {
              Card card = cards[currCard];
              currCard++;
              return card;
         public Card getCard(int i) {
              return cards[i];

    thanks for the advice.
    i've done what you suggested. but when i went try to compile the 2 programs i get error messages (shown below along with the modified code). do you know what are causing these error messages?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class Blackjack extends JFrame implements ActionListener,MouseListener{
         private Deck deck;     //The deck...
         private Hand player_hand;//player hand
         private Hand dealer_hand;//dealer hand.
         //private Button bHit=new Button("Hit");
         JButton bHit=new JButton("Hit");
         //private Button bStay=new Button("Stay");
         JButton bStay=new JButton("Stay");
         //private Button bRestart=new Button("New Game");
         JButton bRestart=new JButton("New Game");
         //lets do some double buffering.
         Image offIm=null;
         Graphics offGraphics=null;
         Dimension offDimension=null;
         Image[] card_images = new Image[52];
         private boolean cards_loaded = false;
         private int current_card_loading = 0;
         String message;                         //print a message...
         int width;          //The width of the applet
         int height;          //The height of the applet
         int card_width = -1;
         int card_padding = -1;     //How much should we pad the cards by..?
         private int games=-1;     //How many games have been played?
         public static void main(String[] args){
               Blackjack bj =new Blackjack(); 
              bj.pack();
              bj.setVisible(true);
         public Blackjack(){
            Thread card_loader = new Thread(this);
              card_loader.start();
              bHit.addMouseListener(this);
          bHit.addActionListener(this);
          //bHit.addMouseMotionListener(this);
              add(bHit);
              bStay.addMouseListener(this);
          bStay.addActionListener(this);
          //bStay.addMouseMotionListener(this);
              add(bStay);
              bRestart.addMouseListener(this);
          bRestart.addActionListener(this);
          //bRestart.addMouseMotionListener(this);
              add(bRestart);
              JFrame frame=new JFrame("BlackJack");
              frame.setSize(400,200);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.add(this);
            frame.pack();
            frame.setVisible(true);
         public void newGame(){
              bHit.setEnabled(true);
              bStay.setEnabled(false);
              player_hand = new Hand();     //Create new hands...
              dealer_hand = new Hand();
              //shuffle the deck.
              deck.shuffleCards();
              games++;
         public void hit(){
              bStay.setEnabled(true);
              player_hand.addCard(deck.dealCard());
              if(player_hand.getValue() > 21){
                   message = "You loose! (score:"+player_hand.getValue()+")";
                   //disable the hit and stay buttons...
                   bHit.setEnabled(false);
                   bStay.setEnabled(false);
                   return;
              message = "Score: "+player_hand.getValue();     
         public void stay(){
              while(dealer_hand.getValue() < 17){
                   dealer_hand.addCard(deck.dealCard());
              if(dealer_hand.getValue() <= 21 && player_hand.getValue() < dealer_hand.getValue()){
                   message = "You loose! (" + player_hand.getValue()+" - "+dealer_hand.getValue()+")";
              else if (player_hand.getValue() == dealer_hand.getValue()){
                   message = "You draw! (" + player_hand.getValue()+")";
              else{
                   message = "You win! (" + player_hand.getValue()+" - "+dealer_hand.getValue()+")";
              bHit.setEnabled(false);
              bStay.setEnabled(false);
         public void actionPerformed(ActionEvent e){
              if(e.getSource() == bRestart){
                   newGame();
              else if (e.getSource() == bHit){
                   hit();
              else if (e.getSource() == bStay){
                   stay();
              repaint();
         public void paint(Graphics g){
              update(g);
         public void update(Graphics g){
              //lets sord out double buffering
              if(offGraphics==null){
                   offIm=createImage(getSize().width,getSize().height);
                   offGraphics=offIm.getGraphics();
              if(!cards_loaded){
                   //display a message saying we're loading the cards...
                   offGraphics.setFont(new Font("Arial",Font.PLAIN,14));
                   offGraphics.setColor(new Color(171,205,239));
                   offGraphics.fillRect(0,0,getSize().width,getSize().height);
                   offGraphics.setColor(Color.black);
                   offGraphics.drawString("Loading cards... ",5,20);
                   offGraphics.drawRect(15,40, 102 ,10);
                   offGraphics.drawRect(13,38, 106 ,14);
                   offGraphics.setColor(new Color(171,205,239));
                   offGraphics.fillRect(0,0,150,35);
                   offGraphics.setColor(Color.black);
                   offGraphics.fillRect(15,40, (current_card_loading)*2 ,10);
                   offGraphics.drawString("Loading card: "+current_card_loading+1,15,20);
              else{
                   Image currentCard;
                   while(card_width == -1){
                        card_width = deck.getCard(0).getImage().getWidth(this);
                   if(card_padding == -1){
                        card_padding = (width - (card_width * 2) - 4) / 4;
                   //clear the background...
                   offGraphics.setColor(Color.blue);
                   offGraphics.fillRect(0,0,width,height);
                   offGraphics.setColor(Color.black);
                   offGraphics.fillRect(1,1,width-2,height-2);
                   offGraphics.setColor(Color.white);
                   offGraphics.drawString("PLAYER:",card_padding,40);
                   offGraphics.drawString("DEALER:",(width/2) + card_padding,40);
                   offGraphics.drawString(message,5,height - 20);
                   if(games > 0){
                        offGraphics.drawString(games + " game(s) played...",5,height - 10);
                   //Draw the players hand...
                   for(int i=0;i<player_hand.getCardCount();i++){
                        currentCard = player_hand.getCards().getImage();
                        offGraphics.drawImage(currentCard, card_padding, 70+(20*(i-1)), this);
                   //now draw the dealers hand...
                   for(int i=0;i<dealer_hand.getCardCount();i++){
                        currentCard = dealer_hand.getCards()[i].getImage();
                        offGraphics.drawImage(currentCard, (width/2 ) + card_padding, 70+(20*(i-1)), this);
              //draw buffered image.
              g.drawImage(offIm,0,0,this);
    public void run(){
              MediaTracker t=new MediaTracker(this);
              System.out.println("Frame getting cards...");
              for(current_card_loading=0; current_card_loading < 52; current_card_loading++){
              //try{
                   card_images[current_card_loading] = getImage(getCodeBase(),"cards/" + (current_card_loading+1) + ".gif");
                   if(card_images[current_card_loading] == null){
                        System.out.println("Null card... ["+current_card_loading+"]");
                   else{
                        t.addImage(card_images[current_card_loading],0);
                   try{
                        t.waitForID(0);
                   catch(InterruptedException e){
                        System.err.println("Interrupted waiting for images..>");
                   //lets show our new status.
                   repaint();
              //create the deck object now
              deck = new Deck(this,card_images);     //Create a new deck object.
              card_width = deck.getCard(0).getImage().getWidth(this);
              bHit.addActionListener(this);
              bStay.addActionListener(this);
              bRestart.addActionListener(this);
              bHit.setEnabled(false);
              bStay.setEnabled(false);
              width = getSize().width;
              height = getSize().height;
              this.add(bHit);
              this.add(bStay);
              this.add(bRestart);
              player_hand = new Hand();     //Create the hands...
              dealer_hand = new Hand();
              //make sure that the buttons appear properly.
              this.validate();
              message = "";
              cards_loaded = true;
              System.out.println("End of thread...");
              repaint();
    ----jGRASP exec: javac -g X:\NETPROG\Assignment2\Blackjack.java
    Blackjack.java:7: Blackjack is not abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener
    public class Blackjack extends JFrame /*Applet*/ implements ActionListener,MouseListener/*,Runnable*/{
    ^
    Blackjack.java:53: cannot find symbol
    symbol : constructor Thread(Blackjack)
    location: class java.lang.Thread
         Thread card_loader = new Thread(this);
    ^
    Blackjack.java:209: cannot find symbol
    symbol : method getCodeBase()
    location: class Blackjack
                   card_images[current_card_loading] = getImage(getCodeBase(),"cards/" + (current_card_loading+1) + ".gif");
    ^
    3 errors
    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.
    import java.awt.*;
    import javax.swing.JFrame;
    import java.net.*;
    import java.io.*;
    class Deck {
         Card[] cards = new Card[52];
         int currCard;
         public Deck(/*Blackjack myApplet*/Blackjack myFrame,Image[] card_images) {
              // These are the (initial) values of all the cards
              int[] values = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10};
              // Make all the cards, getting the images individually
              for (int i=0; i<52; i++) {
                   cards[i] = new Card(card_images, values[i]);
              // Shuffle the cards.
              shuffleCards();
         public void shuffleCards(){
              Card temp;
              //loop through each card in the deck and swap it with some random card.
              for (int i=0; i<52; i++) {
                   int rand = (int)(Math.random()*52);
                   temp = cards[51-i];//take the current card...
                   cards[51-i] = cards[rand];//and swap it with some random card...
                   cards[rand] = temp;
              //now, reset the currentCard to deal...
              currCard = 0;
         public Card dealCard() {
              Card card = cards[currCard];
              currCard++;
              return card;
         public Card getCard(int i) {
              return cards[i];
    ----jGRASP exec: javac -g X:\NETPROG\Assignment2\Deck.java
    Blackjack.java:6: Blackjack is not abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener
    public class Blackjack extends JFrame implements ActionListener,MouseListener{
    ^
    Blackjack.java:45: cannot find symbol
    symbol : constructor Thread(Blackjack)
    location: class java.lang.Thread
         Thread card_loader = new Thread(this);
    ^
    Blackjack.java:201: cannot find symbol
    symbol : method getCodeBase()
    location: class Blackjack
                   card_images[current_card_loading] = getImage(getCodeBase(),"cards/" + (current_card_loading+1) + ".gif");
    ^
    3 errors
    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

  • Converting an Applet into an Application

    I think I understand the basics of converting an Applet into an Application but Iam unsure on how you would go about passing the parameters that are normally stored in the HTML tag into the application.

    Basically you'll need to provide your own getParameter
    method. It's easy with a java.util.HashTable -- the
    parameter name as the key.that means that i would have to go back and change the old code, correct?

  • How can I sign My applet for IE and Netscape without JavaPlugIn?

    I think we can sign our applets with Javasigner.exe but this certificate is not being
    supported by IE and Netscape. If you want to use this certificate with IE and Nets.
    you must install JavaPlugIn to all users. I dont want to choose this way.
    I think we have one alternative for this purpose.
    For Netscape: Signing Tool
    For IE: The program that included SDK-Java
    But I could not find SDK-Java any where.
    I think Microsoft have gave up to support the Java certification...
    I am not sure.
    How can I prepare signed applet that can be run on IE and Netscape?
    This applet will have some permissions.

    The tool you need for signing cab files for the MS JVM is signtool.exe. I beleive that the .NET version of this tool can be used, as the signing process was not Java specific. You do need certificates in a different format than for jarsigner or the netscape signing tool. Verisign will happily sell you two different certificates, but there is probably a way to convert between formats using openssl or similar.
    You'll also need to package your files in a cab instead of a jar. cabarc.exe is what we use here. Again, it does not seem to be Java specific, so you can probably still find it despite Microsoft no longer making their Java tools available.

  • I need to convert PDF file to Word Document, so it can be edited. But the recognizing text options do not have the language that I need. How I can convert the file in the desired of me language?

    I need to convert PDF file to Word Document, so it can be edited. But the recognizing text options do not have the language that I need. How I can convert the file in the desired of me language?

    The application Acrobat provides no language translation capability.
    If you localize the language for OS, MS Office applications, Acrobat, etc to the desired language try again.
    Alternative: transfer a copy of content into a web based translation service (Bing or Google provides a free service).
    Transfer the output into a word processing program that is localized to the appropriate language.
    Do cleanup.
    Be well...

  • How can I convert an audio file (speech) into a text?

    Hello everybody!
      Can someone explain how I can convert a garageband file (voice speech) into a text? My Mac is a Mac OS X 10.5.8 version, so I don't have programs such as mountain Lion. I thought to use googlevoice. Is this option available? If yes, how can I use it?
    Thanks.

    Hello, I only find google voice available for Abdroid!?
    http://www.ehow.com/info_10033225_google-voice-system-requirements-android.html
    Some possibilitities, not sure if they have 10.5.8 compatble versions anymore...
    http://atmac.org/speech-to-text-dictation-software-for-os-x
    Some reviews of later Dragon Speak...
    http://www.finetunedmac.com/forums/ubbthreads.php?ubb=showflat&Number=22962

  • How do I convert my existing iTunes account to a .mac account?

    I am trying to convert my existing iTunes account which uses an Earthlink address. The following is the INSTRUCTIONS from the Apple web site on how to do this.
    "I just signed up for .Mac. How do I convert my existing iTunes account to
    my new .Mac account?
    We'll be happy to convert your account for you. Please provide your old account name, your new .Mac account name and your billing address in your email. We will also need your explicit permission to reset your password to complete the conversion."
    This is the URL where I found those INSTRUCTIONS:
    http://www.apple.com/support/itunes/musicstore/email/
    I FOLLOWED THE INSTRUCTIONS ABOVE!
    I am now on my fifth exchange of emails with iTunes support.
    HAS ANYBODY SUCCESSFULLY EXECUTED THESE INSTRUCTIONS? I don't want to lose the ability to play my existing purchased music, but I want to close down Earthlink as my ISP.
    17" G4 Powerbook   Mac OS X (10.4.6)  
    17" G4 Powerbook   Mac OS X (10.4.6)  

    On any page in the iTunes Store, click the flag icon at the lower right.  This brings up a page saying "Choose your country or region."  Click Canada.
    Before you can buy anything, you will need to enter your Canadian credit card.

  • How can I convert an OVM vm (.img) to VDI (virtualbox)?

    Hi,
    how can I convert an OVM vm (.img) to VDI (virtualbox)?
    Is .img format a raw image? If yes can I use "VBoxManage convertdd" to convert from .img to vdi?
    tnx & regards,
    S.

    Hi,
    "VBoxManage convertdd" solved.
    Regards,
    S.

  • How can I convert an AUDIO MPEG-4 to an MPEG3 format? I need it for a Powerpoint Presentation

    How can I convert an AUDIO  MPEG-4 to another type of file, such as MPEG3  or mp3

    Use Handbrake.
    You can download it for free from this site:
    http://www.macupdate.com/info.php/id/12987/handbrake
    Good luck

  • How do I convert a pdf in Adobe Acrobat 9 to Microsoft Word document?

    How do I convert a pdf in Acrobat 9 to a Microsoft Word document?

    Hi fireatty,
    In Acrobat 9, you can use the Export command (File > Export) to export your PDF to Word format.
    Please let us know if you need additional assistance.
    Best,
    Sara

  • I changed from i iphone 5 back to a iphone 4.. now my itunes does not recognise that i have a iphone 4! how do i convert my last back up (on iphone 5) to my new iphone 4?

    i changed from i iphone 5 back to a iphone 4.. now my itunes does not recognise that i have a iphone 4! how do i convert my last back up (on iphone 5) to my new iphone 4?

    In your case you can only restore from a backup that has been created with the same iOS version. An iPhone 4 can only run 7.1.2, and, unless your iPhone 5 did not run the same version, you can't use a newer iOS backup of the 5 on the iPhone 4

Maybe you are looking for

  • Converting XML to Spreadsheet - Problem with Accented Characters

    I have a program that uses an external program to gathers user account information from Active Directory. The external program is .Net, and I execute it from my Java app, which then collects the XML output and saves it in a String variable. So far so

  • Help needed selecting phone to use as a internet m...

    I want to buy a nokia phone that I can use as an internet modem by connecting to the computer by USB. How do i know which models in nokia will allow me to do this ? What will be the data rates ? how do i compare the data rates between phones. how do

  • Derivation in PCA

    We want profit center per Company Code, Plant and Material. In Trans. Code: 3KEH, we have Company Code and Valuation area which is not working in FI entry (plant). Can we add new condition for Derivation in 3KEH ? If yes, how?  Is there any other way

  • Barchart in java swing

    Hi; can i get the sample codes for line chart and candle stick chart?

  • ReturnListener not invoked

    Dear all, I use Oracle ADF 10g. I have a commandButton that upon clicking it opens up a dialog box. I have set LaunchListener and ReturnLinstener functions on this command button. The LaunchListener executes normally. However the ReturnListener is no