• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

testing or validating for different platforms

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a little applet game that my friends tell me runs well on Windows, but not on Mac.
Is there any software one can use to test a Java applet's compatibilty with various platforms?
What, if anything, tends to cause lack of cross-platform compatibility?
If you're feeling exceptionally generous, please see if you can spot the problem in the actual source code:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class TennisReturnGame extends Applet
{
Graphics offscreen ;
Image imageOffScreen ;
Button newGame;
Choice choice;
String scoreLine, instructions;
static String userscore = "0";
static String proscore = "0";
boolean started = false;
boolean isMoving = false;
boolean gameOver = false;
FontMetrics fm; // needed for centering message
int scoreLoc;
public void init()
{
setBackground( new Color( 0, 120, 0 ) );
setLayout( new BorderLayout( 3, 3 ) );
TennisCanvas court = new TennisCanvas( );
add( court, BorderLayout.CENTER );
Panel controlPanel = new Panel();
controlPanel.setBackground( new Color( 220, 200, 180 ) );
add( controlPanel, BorderLayout.SOUTH );
Panel topPanel = new Panel();
topPanel.setBackground( new Color( 220, 200, 180 ) );
add( topPanel, BorderLayout.NORTH );
fm = getFontMetrics( getFont() );
instructions = "Click once to activate. Spacebar initiates serve. Delays are built in.";
scoreLoc = 240 - ( fm.stringWidth( instructions )/2 );
newGame = new Button( "New Game" );
newGame.addActionListener( court );
newGame.setBackground( Color.lightGray );
topPanel.add( newGame );
choice = new Choice(); // user chooses opponent, which will determine ball speed
choice.addItem( "Greg Rusedski 149 mph" );
choice.addItem( "Venus Williams 127 mph" );
choice.addItem( "Conchita Martinez 98 mph" );
choice.addItem( "PeeWee Phenom 77 mph" );
choice.addItem( "Uncle Seymour 50 mph" );
choice.setBackground( Color.white );
controlPanel.add( new Label( " Opponent:" ) );
controlPanel.add( choice );
imageOffScreen = createImage( getSize().width, getSize().height );
offscreen = imageOffScreen.getGraphics();
court.proChoice = choice;
}

public Insets getInsets()
{
return new Insets( 3, 3, 3, 3 );
}

class TennisCanvas extends Canvas implements ActionListener, Runnable, KeyListener, MouseListener
{
double currX , currY ; // position of ball
double dy = ( Math.random()* 3 ) + 1; // change in ball's y position
double dx = 15;
int speed = 50;
int pointCount;
Thread animator;
Choice proChoice;
TennisCanvas() // constructor
{
setBackground( new Color( 0, 120, 0 ) );
currX = 84;
currY = 125;
addKeyListener( this );
addMouseListener( this );
animator = new Thread( this );
animator.start();
}
public int setSpeed() // speed based on opponenet chosen by user
{
int choiceIndex = proChoice.getSelectedIndex();
switch ( choiceIndex )
{
case 0:
return 75;
case 1:
return 64;
case 2:
return 49;
case 3:
return 39;
case 4:
return 25;
default:
return 50;
}
}

public void actionPerformed( ActionEvent evt ) // New Game button starts new game
{
String command = evt.getActionCommand();
if ( command.equals( "New Game" ) )
startNew();
}
public void startNew() // resets scores and starts new game
{
setBackground( new Color( 0, 120, 0 ) );
pointCount = 0;
isMoving = false;
started = false;
gameOver = false;
userscore = "0";
proscore = "0";
fm = getFontMetrics( getFont() );
scoreLine = "Opponent's score: " + proscore + " Your score: " + userscore;
instructions = "Click once to activate. Spacebar initiates serve.";
scoreLoc = 240 - ( fm.stringWidth( instructions )/2 );
repaint();
}
public void keyPressed( KeyEvent evt ) // hitting space bar initiates serve
{
int code = evt.getKeyCode();
if ( code == KeyEvent.VK_SPACE && isMoving == false && gameOver == false )
{
currX = 84;
if ( pointCount % 2 == 0 )
currY = 125;
else
currY = 110;
animator = new Thread( this );
animator.start();
}
}
public void mousePressed( MouseEvent evt ) // user tries to hit moving ball with mouse click
{
if ( started == false ) // first mouse click activates game but doesn't count as a "swing" at the ball
{
started = true;
newScore();
}
// if user clicks within 20 pixels of ball, user gets the point
else if ( evt.getX() > 324 && Math.abs( evt.getX() - ( currX + 5 ) ) <= 20 && ( Math.abs( evt.getY() - ( currY + 5 ) ) <= 20 ) )
{
dx = -dx;
dy = -dy;
addToUser();
}
else // otherwise, opponent gets the point
{
addToPro();
}
}
public void addToUser() // gives point to user
{
if ( gameOver == false && isMoving == true )
{
if ( userscore.equals( "0" ) )
userscore = "15";
else if ( userscore.equals( "15" ) )
userscore = "30";
else if ( userscore.equals( "30" ) )
userscore = "40";
else if ( userscore.equals( "40" ) ) // user wins game
{
userscore = "GAME!";
gameOver = true;
setBackground( new Color( 204, 102, 0 ) );
}
pointCount++;
newScore();
}
}
public void addToPro() // gives point to opponent
{
if ( isMoving == true && gameOver == false )
{
if ( proscore.equals( "0" ) )
proscore = "15";
else if ( proscore.equals( "15" ) )
proscore = "30";
else if ( proscore.equals( "30" ) )
proscore = "40";
else if ( proscore.equals( "40" ) ) // opponent wins game
{
proscore = "GAME!";
gameOver = true;
setBackground( new Color( 204, 102, 0 ) );
}
pointCount++;
newScore();
}
}
public void newScore() // updates score
{
scoreLine = "Opponent's score: " + proscore + " Your score: " + userscore;
fm = getFontMetrics( getFont() );
scoreLoc = 240 - ( fm.stringWidth( scoreLine )/2 );
repaint();
}

public void run()
{
isMoving = true;
speed = setSpeed();
int cycles = 7000/speed;
dx = ( 15 * speed ) / 100;
double rand = ( Math.random()* 10 ) + 5;
if ( pointCount % 2 == 0 )
dy = -dx/rand;
else
dy = dx/rand;
for ( int i = 0 ; i <= 100 ; i++ ) // delay keeps ball still for a few seconds
{
try
{
Thread.sleep( 10 );
}
catch ( InterruptedException e )
{
}
repaint();
}

for ( int i = 0 ; i <= cycles ; i++ ) // moves ball across tennis court
{
try
{
Thread.sleep( 10 );
}
catch ( InterruptedException e )
{
}
// update the x and y coordinates for the ball
currX = currX + dx;
currY = currY + dy;
repaint();
} //close for loop
isMoving = false;
} //close run
public void update( Graphics g )
{
paint( g );
}
public void paint( Graphics g )
{
offscreen.setColor( getBackground() );
offscreen.fillRect( 0, 0, getSize().width, getSize().height );
offscreen.setColor ( Color.yellow );
offscreen.fillOval( (int)currX , (int)currY , 10, 10 );
offscreen.setColor ( Color.white );
offscreen.drawRect( 84, 66, 312, 108 );
offscreen.drawLine( 240, 66, 240, 174 );
offscreen.drawLine( 156, 120, 324, 120 );
offscreen.drawLine( 156, 66, 156, 174 );
offscreen.drawLine( 324, 66, 324, 174 );
offscreen.setColor( Color.green );
if ( started == true )
offscreen.drawString( scoreLine, scoreLoc, 20 );
else
offscreen.drawString( instructions, scoreLoc, 20 );
g.drawImage( imageOffScreen , 0 , 0 , this );
} // close paint
public void mouseEntered( MouseEvent evt ) { }
public void mouseExited( MouseEvent evt ) { }
public void mouseReleased( MouseEvent evt ) { }
public void mouseClicked( MouseEvent evt ) { }
public void keyTyped( KeyEvent evt ) { }
public void keyReleased( KeyEvent evt ) { }
} // close TennisCanvas
}

 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is usually not the platform. It is the browser that is running on that platform. Since the vendor is responsible for implementing the specifications of the JVM, and they do it in a variety of ways (some more effective than others) you would need to test every browser. Even just keeping IE and Netscape happy is a chore, even running on the same platform .
 
Jeff Cooper
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Cindy.
Is there any way to test for different browsers without installing all of them on my own machine? For example, a few Web sites offer a service where they test your HTML on different browsers and show you any possible incompatibilites.
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not that I know of.
Hey, You could make a FORTUNE out of this idea !
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What we do here is test on both IE and Netscape. Doing so, like Cindy mentioned, will at least assure that it works well for most of your users.
Bosun
 
Jeff Cooper
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Cindy and Bosun.
I tested my applet on IE and Netscape on my own machine, then had several friends test on their machines. All but one of twelve Windows users reported that it ran well. Two of two Mac users reported that it didn't run at all, which is an awfully small sampling, but both of them are tech types who have up-to-date machines.
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try contacting them. I just did last week (about when Mac's will support swing) and they were very prompt with a reply.
Course it would help if you could narrow down the problem. Also you might look for a bug list for Mac's on the apple site.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic