Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

API Error

Status
Not open for further replies.

M626

Programmer
Joined
Mar 13, 2002
Messages
299
I am try to compile this code in jdk1.3.1 and I keep getting a error stating that
"craps.java uses or overrides or depreciated API"
" Recompile with -depreciation"
Any help would be appricated, if you could tell me how to fix the code to work or what this error is.
thanks


HERE IS THE CODE

import java.awt.*;
import java.applet.Applet;
//changed Applet to JApplet
public class Craps extends Applet {
// constant variables for status of game
final byte WON = 0, LOST = 1, CONTINUE = 2;

// other variables used in program
long starttotal;
long betnum=0, total=0;
boolean firstRoll = true, gamestart=true; // true if first roll
int dieSum = 0; // sum of the dice
int myPoint = 0; // point if no win/loss on first roll
short wins=0, losses=0;
byte gameStatus = CONTINUE; // WON, LOST, CONTINUE

// graphical user interface components
Label die1Label, die2Label, sumLabel, pointLabel, betlabel, message, title;
TextField firstDie, secondDie, sum, point, betbox;
Button roll, yes, no, quit;
String longspace=new String(" ");
String longerspace=new String(longspace+" ");

// setup graphical user interface components
public void init()
{
die1Label = new Label( "Die 1" );
firstDie = new TextField( 1 );
firstDie.setEditable( false );
die2Label = new Label( "Die 2" );
secondDie = new TextField( 1 );
secondDie.setEditable( false );
sumLabel = new Label( "Sum is" );
sum = new TextField( 2 );
sum.setEditable( false );
roll = new Button( "Play Craps" );
pointLabel = new Label( "Point is" );
point = new TextField( 2 );
point.setEditable( false );
title=new Label(" Welcome to Java Craps, version 1.2 ");
message=new Label(longspace+"Type in how much money you have."+longerspace);
yes=new Button("Yes");
no=new Button("No");
betbox=new TextField(25);
betlabel=new Label("Total cash: $");
quit=new Button("Quit");

add(title);
add(betlabel);
add(betbox);
add( roll );
add( die1Label );
add( firstDie );
add( die2Label );
add( secondDie );
add( sumLabel );
add( sum );
add( pointLabel );
add( point );
add(message);
add(quit);
add(yes);
add(no);

}public void start(){
quit.hide();
yes.hide();
no.hide();

}
// process one roll of the dice
public void play()
{
if ( firstRoll ) { // first roll of the dice
dieSum = rollDice();

switch( dieSum ) {
case 7: case 11: // win on first roll
gameStatus = WON;
point.setText( "" ); // clear point text field
firstRoll = true; // allow new game to start
break;
case 2: case 3: case 12: // lose on first roll
gameStatus = LOST;
point.setText( "" ); // clear point text field
firstRoll = true; // allow new game to start
break;
default: // remember point
gameStatus = CONTINUE;
myPoint = dieSum;
point.setText( Integer.toString( myPoint ) );
firstRoll = false;
break;
}
}
else {
dieSum = rollDice();

if ( dieSum == myPoint ) // win by making point
gameStatus = WON;
else
if ( dieSum == 7 ) // lose by rolling 7
gameStatus = LOST;
}


total=refresh(gameStatus, betnum, total, betbox);
}

public long refresh(byte gsts, long somecash, long allcash, TextField clear){
long newcash=allcash;
if (gsts==WON){
message.setText(longspace+"Congratulations, you win! Want to play again?"+longerspace);
++wins;
firstRoll=true;
newcash=allcash+somecash;
clear.setText("");
if (newcash>=0) quit.show();
}else if (gsts==LOST){
message.setText(longspace+"Sorry, you lost this one. Better luck next time."+longerspace);
++losses;
firstRoll=true;
clear.setText("");
newcash=allcash-somecash;
if (newcash>=0) quit.show();
}else message.setText(longspace+"Roll again -- you'll win if you get 'Point'."+longerspace);
showStatus(wins+" Win"+plural(wins)+"; "+losses+" Loss"+eplural(losses)+"; "+" Balance: "+balance(newcash));
clear.setEditable(firstRoll);
repaint();
if (firstRoll) betlabel.setText("Place bet: $");
else betlabel.setText("Your bet: $");
return newcash;
}
// call method play when button is clicked
public boolean action( Event e, Object o )
{if (gamestart){
if(!isfloat(betbox.getText())) {
message.setText(longspace+"Really. Enter your starting money."+longerspace);
repaint();
}else game();
}else{
if (e.target==roll || e.target==betbox){

if(!isfloat(betbox.getText())) {
message.setText(longspace+"Oops. You just placed an invalid bet."+longerspace);
repaint();
}
betnum=(long)(100*Float.valueOf(betbox.getText()).floatValue());
if (betnum>0)
play();
else message.setText(longspace+"Oops. You just placed an invalid bet."+longerspace);
repaint();
}if (e.target==quit){
if (total<0) {
message.setText(longspace+&quot;You can't quit -- you still owe us money!&quot;+longerspace);
quit.hide();
repaint();
}else if (!firstRoll){
message.setText(longspace+&quot;But you're in the middle of a game!&quot;+longerspace);
repaint();
}else{
quit.hide();
roll.hide();
betbox.hide();
message.setText(longspace+&quot;Do you really want to quit Java Craps?&quot;+longerspace);
yes.show();
no.show();
}
}if (e.target==no){
betbox.show();
roll.show();
yes.hide();
no.hide();
message.setText(longspace+&quot;We thought you might change your mind.&quot;+longerspace);
repaint();
}
if (e.target==yes) exit();

}return true;
}
// roll the dice
int rollDice()
{
int die1, die2, workSum;

die1 = 1 + (int) ( Math.random() * 6 );
die2 = 1 + (int) ( Math.random() * 6 );
workSum = die1 + die2;

firstDie.setText( Integer.toString( die1 ) );
secondDie.setText( Integer.toString( die2 ) );
sum.setText( Integer.toString( workSum ) );

return workSum;
}
public static boolean isfloat(String s){
char c[]=s.toCharArray();
boolean deci=false;
for (byte aritm=0; aritm<c.length; aritm++){
if ((c[aritm]!='.' && !Character.isDigit(c[aritm]) &&!(aritm==0 && c[aritm]=='-')) || s==&quot;&quot; || (c[aritm]=='.' && deci==true))
return false;
if (c[aritm]=='.') deci=true;
}
return true;
}
public void exit(){
no.hide();
yes.hide();
die1Label.hide();
firstDie.hide();
die2Label.hide();
secondDie.hide();
sumLabel.hide();
sum.hide();
pointLabel.hide();
point.hide();
title.setText(&quot; Thank You for playing Java Craps 1.2 &quot;);
betlabel.setText(longspace+&quot;Please play again sometime!&quot;+longspace);
if (total<=starttotal) message.setText(longspace+&quot;Next time, try harder and win some money!&quot;+longerspace);
else message.setText(longspace+&quot;Don't forget your money! You won &quot;+balance(total-starttotal)+&quot;.&quot;);
repaint();
stop();
destroy();
}
public String balance(long money){
String zero;
if (money%100!=0 && money%10==0) zero=new String(&quot;0&quot;);
else zero=new String (&quot;&quot;);
String returnme=new String(&quot;$&quot;+money/100.0+zero);
return returnme;
}
public String plural(int n){
if (n!=1) return &quot;s&quot;;
else return &quot;&quot;;
}
public String eplural(int n){
if (n!=1) return &quot;es&quot;;
else return &quot;&quot;;
}
public void game(){
starttotal=(long)(100*Float.valueOf(betbox.getText()).floatValue());
total=refresh(gameStatus, betnum, starttotal, betbox);
gamestart=false;
roll.setLabel(&quot;Roll Dice&quot;);
message.setText(longspace+&quot;Bet some money and roll the dice.&quot;+longerspace);
betlabel.setText(&quot;Place bet: $&quot;);
betbox.setText(&quot;&quot;);
}
}
 
It's not an error. It is a warning. It compiled successfully
but gave a warning that some of the methods you are using
are deprecated. That means they a marked to be dropped
from future versions of java.
Do what it says it you want details
recompile whith the deprecation flag.
javac -deprecation someClass
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top