Help - Running Sudoku Game

I am trying to get this code to work, I am not really sure of the problem with it. I am using JCreator to write/compile/run it. When I compile it, it compiles fine but gives this message. "Note: C:\JFiles\Exercises\Sudoku.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details." I'm kinda new to this, so any help would be appreciated.

import java.awt.*;

import java.applet.Applet;

import java.lang.*;

import java.io.*;

import java.util.*;

import java.net.*;

public class Sudoku extends Applet {

final static int CTRLPANEL_Y =5;

final static int CTRLPANEL_H = 45;

final static int SIZE = 9;

intbd_offx, bd_offy;

Dimension app_size;

intunit = 0;

intfontsize;

intbuttonfontsize;

booleancurChanged = false;

booleanvalChanged = false;

intcurX = -1;

intcurY = -1;

intoldX = -1;

intoldY = -1;

Fontboxfont = null;

PanelcontrolPanel, buttonPanel;

publicHistoryhistory = new History( this );

public int probTable[][] = new int[SIZE][SIZE];

public int ansTable[][]= new int[SIZE][SIZE];

public int guessTable[][] = new int[SIZE][SIZE];

public boolean redTable[][] = new boolean[SIZE][SIZE];

public NumberButton buttons[] = new NumberButton[SIZE+1];

intfillcount[] = new int[SIZE+1];

public void init() {

String filename = getParameter("problemfile");

app_size = this.size();

unit = (int)(app_size.width*0.92)/SIZE;

String str = getParameter("unitsize");

if( str != null ) {

try {

unit = (Integer.valueOf(str)).intValue();

} catch( NoSuchElementException e ) {}

}

fontsize = (unit*16)/20;

buttonfontsize = (unit*15)/20;

setLayout( new BorderLayout() );

setBackground( Color.white );

bd_offx = ( app_size.width - unit * SIZE ) / 2;

bd_offy = CTRLPANEL_H + 15;

controlPanel = new Panel();

controlPanel.setLayout(new FlowLayout());

buttonPanel = new Panel();

buttonPanel.setLayout(new FlowLayout());

controlPanel.add( new ControlButton( this, "Back", " Back " ) );

controlPanel.add( new ControlButton( this, " ", "" ) );

controlPanel.add( new ControlButton( this, "Replay", " Replay " ) );

controlPanel.add( new ControlButton( this, "Check", " Check " ) );

Panel pd = new Panel();

pd.setLayout( new BorderLayout() );

add( "South", pd );

for( int i=1; i<=SIZE; ++i ) {

NumberButton nb = new NumberButton( this, i, buttonfontsize );

buttonPanel.add( nb );

buttons = nb;

}

add( "North", controlPanel );

controlPanel.reshape( 0, CTRLPANEL_Y, app_size.width, CTRLPANEL_H );

pd.add( "Center", buttonPanel );

buttonPanel.reshape( 0, app_size.height-22-50+5, app_size.width, 50 );

Label copyright = new Label("Number Place V0.3" + " " +

"Copyright(C)1996,2000 Hirofumi Fujiwara.",

Label.CENTER );

pd.add( "South", copyright );

copyright.reshape( 0, app_size.height-22, app_size.width, 18 );

loadData( filename );

}

void loadData( String filename ) {

URLurl;

DataInputStream file;

try {

url = new URL( getDocumentBase(), filename );

file = new DataInputStream( url.openStream() );

} catch( MalformedURLException e ) {

showStatus( "file name error : " + filename );

return;

} catch( IOException e ) {

showStatus( "file open error : " + filename );

return;

}

String line;

try {

booleanisproblem = false;

booleanisanswer = false;

int x, y=0, v;

nextline:

for(;;) {

line=file.readLine();

if( line == null )

break;

if( '#' == line.charAt(0) )

continue;

StringTokenizer st = new StringTokenizer(line);

try {

for( x=0; ; ++x ) {

String tk = st.nextToken();

if( tk.equals("problem") ) {

isproblem = true;

y = 0;

continue nextline;

}

if( tk.equals("answer") ) {

isproblem = false;

isanswer = true;

y = 0;

continue nextline;

}

if( tk.equals("end") ) {

break nextline;

}

if( tk.equals("-") )

v = 0;

else

v = (Integer.valueOf(tk)).intValue();

if( isproblem )

probTable[x][y] = v;

if( isanswer )

ansTable[x][y] = v;

}

} catch( NoSuchElementException e ) {}

++y;

}

} catch( IOException e ) {}

initFillCount();

}

void initFillCount() {

for( int i=0; i<fillcount.length; ++i )

fillcount = 0;

for( int i=0; i><SIZE; ++i )

for( int j=0; j><SIZE; ++j ) {

int v = probTable[j];

if( v != 0 )

++fillcount[v];

}

for( int i=1; i><fillcount.length; ++i )

if( fillcount == SIZE )

buttons.hide();

else

buttons.show();

}

boolean isOk( int x, int y, int v ) {

inti, j;

for( i=0; i><SIZE; ++i ) {

if( i == x )

continue;

if( probTable[y]==v || guessTable[y]==v )

returnfalse;

}

for( i=0; i><SIZE; ++i ) {

if( i == y )

continue;

if( probTable[x]==v || guessTable[x]==v )

returnfalse;

}

intbx = (x / 3) * 3;

intby = (y / 3) * 3;

for( i=bx; i><bx+3; ++i ) {

for( j=by; j><by+3; ++j ) {

if( i==x && j==y )

continue;

if( probTable[j]==v || guessTable[j]==v )

returnfalse;

}

}

returntrue;

}

void buttonEnabling( int x, int y ) {

int i, j, v;

booleanisused[] = new boolean[10];

for( i=0; i><isused.length; ++i )

isused = false;

for( i=0; i><SIZE; ++i ) {

if( i == x )

continue;

v = probTable[y];

if( v == 0 )

v = guessTable[y];

if( v > 0 )

isused[v] = true;

}

for( i=0; i<SIZE; ++i ) {

if( i == y )

continue;

v = probTable[x];

if( v == 0 )

v = guessTable[x];

if( v > 0 )

isused[v] = true;

}

intbx = (x / 3) * 3;

intby = (y / 3) * 3;

for( i=bx; i<bx+3; ++i ) {

for( j=by; j><by+3; ++j ) {

if( i==x && j==y )

continue;

v = probTable[j];

if( v == 0 )

v = guessTable[j];

if( v > 0 )

isused[v] = true;

}

}

}

int toXPos( int i ) {

return bd_offx + i * unit + (i/3-1)*3 + 1;

}

int toYPos( int i ) {

return bd_offy + i * unit + (i/3-1)*3 + 1;

}

boolean isInside() {

return isInside( curX, curY );

}

boolean isInside( int i, int j ) {

if( i<0 || i>=SIZE )

return false;

if( j<0 || j>=SIZE )

return false;

returntrue;

}

void drawChecked( Graphics g, int x, int y ) {

g.setColor( Color.black );

g.drawRect( toXPos(x)+2, toYPos(y)+2, unit-6, unit-6 );

}

void drawNumber( Graphics g, Color c, int x, int y ) {

drawNumber( g, c, x, y, guessTable[x][y] );

}

void drawNumber( Graphics g, Color c, int x, int y, int v ) {

if( boxfont == null ) {

boxfont = new java.awt.Font( "Helvetica", 0, fontsize );

}

if( v == 0 )

return;

g.setColor( c );

g.setFont( boxfont );

String s = String.valueOf(v);

FontMetrics fm = g.getFontMetrics();

intsWidth = fm.stringWidth(s);

intsHeight = fm.getHeight();

intsAscent = fm. getAscent();

g.drawString( s, toXPos(x)+(unit-sWidth)/2, toYPos(y)+(unit+sAscent)/2-2 );

}

public void setValue( int i, boolean ispush ) {

if( ! isInside( curX, curY ) )

return;

int ov = guessTable[curX][curY];

if( ov > 0 ) {

if( fillcount[ov] == SIZE )

buttons[ov].show();

--fillcount[ov];

}

if( i > 0 ) {

++fillcount;

if( fillcount == SIZE )

buttons.hide();

}

guessTable[curX][curY] = i;

if( ispush ) {

history.push( curX, curY, ov, i );

}

valChanged = true;

repaint();

}

public void replay() {

history.clean();

initFillCount();

curX = curY = -1;

for( int i=0; i<SIZE; ++i ) {

for( int j=0; j><SIZE; ++j ) {

guessTable[j] = probTable[j];

}

}

repaint();

}

public void check() {

intred = 0;

for( int i=0; i><SIZE; ++i ) {

for( int j=0; j><SIZE; ++j ) {

redTable[j] = false;

if( probTable[j] != 0 )

continue;

if( guessTable[j] == 0 ) {

redTable[j] = true;

++red;

continue;

}

if( ! isOk( i, j, guessTable[j] ) ) {

redTable[j] = true;

++red;

}

}

}

repaint();

Stringmessage;

Colorcol;

if( red!=0 ) {

message = "You are Mistaken!";

col = Color.red;

} else {

message = "Congratulations!";

col = Color.white;

}

InformationDialog diag = new InformationDialog(

this, col, "NumberPlace", message );

diag.popup();

}

public void paint( Graphics g ) {

g.setColor( Color.black );

g.fillRect( bd_offx-6, bd_offy-6, unit*SIZE+13, unit*SIZE+13 );

for( int i=0; i><SIZE; ++i ) {

for( int j=0; j><SIZE; ++j ) {

Color c = (i==curX && j==curY) ? Color.cyan : Color.white;

g.setColor( c );

g.fillRect( toXPos(i), toYPos(j), unit-1, unit-1 );

int v;

v = probTable[j];

if( v != 0 ) {

drawNumber( g, Color.black, i, j, v );

} else {

v = guessTable[j];

c = redTable[j] ? Color.red : Color.blue;

drawNumber( g, c, i, j, v );

}

}

}

}

public void update( Graphics g ) {

if( curChanged || valChanged ) {

if( curChanged && isInside( oldX, oldY ) ) {

g.setColor( Color.white );

g.fillRect( toXPos(oldX), toYPos(oldY), unit-1, unit-1 );

drawNumber( g, Color.blue, oldX, oldY );

}

if( isInside() ) {

g.setColor( Color.cyan );

g.fillRect( toXPos(curX), toYPos(curY), unit-1, unit-1 );

drawNumber( g, Color.blue, curX, curY );

}

valChanged = curChanged = false;

return;

}

paint( g );

}

public boolean mouseDown( Event evt, int x, int y ) {

int cx = x - (bd_offx-4);

int cy = y - (bd_offy-4);

if( cx><0 || cy<0 )

return true;

cx /= unit+1;

cy /= unit+1;

if( cx<0 || SIZE<=cx || cy<0 || SIZE<=cy )

return true;

if( probTable[cx][cy] != 0 )

return true;

changePos( cx, cy );

return true;

}

public void changePos( int cx, int cy ) {

oldX = curX; curX = cx;

oldY = curY; curY = cy;

curChanged = true;

repaint();

}

public boolean action( Event evt, Object arg ) {

returntrue;

}

}

class ControlButton extends Button {

Sudokunp;

Stringname;

ControlButton( Sudoku p, String str, String label ) {

super();

np = p;

name = str;

setLabel( label );

Fontbf = new java.awt.Font( "Helvetica", 0, 20 );

setFont( bf );

}

public boolean action( Event evt, Object obj ) {

if( name.equals(" ") ) {

np.setValue( 0, true );

return true;

}

if( name.equals("Back") ) {

np.history.pop();

return true;

}

if( name.equals("Replay") ) {

np.replay();

return true;

}

if( name.equals("Check") ) {

np.check();

return true;

}

return true;

}

}

class NumberButton extends Button {

Sudokunp;

intid;

NumberButton( Sudoku p, int i, int fontsize ) {

super();

np = p;

id = i;

setLabel( ""+i );

Fontbf = new java.awt.Font( "Helvetica", 0, fontsize );

setFont( bf );

}

public boolean action( Event evt, Object obj ) {

np.setValue( id, true );

return true;

}

}

class History {

Sudokunp;

inthistory[][] = new int[1000][4];

intcurrent;

intlast;

History( Sudoku p ) {

np = p;

clean();

}

publicvoid clean() {

current = last = 0;

}

publicvoid push( int x, int y, int o, int v ) {

if(current >= history.length )

return;

history[current][0] = x;

history[current][1] = y;

history[current][2] = o;

history[current][3] = v;

++current;

if( last < current )

last = current;

}

public void pop() {

if( current <= 0 )

return;

--current;

int x = history[current][0];

int y = history[current][1];

int o = history[current][2];

int v = history[current][3];

np.changePos( x, y );

np.setValue( o, false );

}

}

classInformationDialog extends Frame {

Appletapp;

protectedButtonbutton;

public InformationDialog( Applet a, Color col, String title, String message ){

app = a;

setTitle( title );

setFont(new Font("TimesRoman", Font.BOLD, 32));

this.setLayout( new BorderLayout( 30, 30 ) );

setBackground( col );

Labellabel = new Label( message );

add( "Center", label );

button = new Button( "OK" );

Panel p = new Panel();

p.setLayout( new FlowLayout( FlowLayout.CENTER, 30, 30 ) );

p.add( button );

add( "South", p );

pack();

}

public void popup() {

Frameframe = (Frame)app.getParent();

Pointpos = frame.location();

Dimensionsize = frame.size();

Dimensionmysize = size();

move( pos.x+(size.width-mysize.width)/2,

pos.y+(size.height-mysize.height)/2 );

show();

}

public boolean action( Event e, Object obj ) {

if( e.target == button ) {

hide();

dispose();

returntrue;

} else

returnfalse;

}

publicbooleangetFocus( Event e, Object obj ) {

button.requestFocus();

returntrue;

}

}

[14583 byte] By [.Williama] at [2007-11-26 19:28:23]
# 1

The "deprecated API" message means that you're using a class or library that has been "deprecated," or replaced in a later release. My knowledge of the current APIs is not encyclopedic, but if you compile from command line (using the javac command) with the -Xlint:deprecation argument, it will tell you which deprecated class(es) you're using.

infiniteogrea at 2007-7-9 21:55:47 > top of Java-index,Other Topics,Java Game Development...
# 2
ok, I'll see if this works, thanks
.Williama at 2007-7-9 21:55:47 > top of Java-index,Other Topics,Java Game Development...
# 3
Ew. Split that giant class up into smaller classes. Do you know what OO means?
CaptainMorgan08a at 2007-7-9 21:55:47 > top of Java-index,Other Topics,Java Game Development...