internalFrame.close ();
}
private void createTetrisFrame ( final WebDesktopPane desktopPane )
{
final Tetris tetris = new Tetris ();
tetris.setUseInternalHotkeys ( false );
final WebInternalFrame tetrisFrame = new WebInternalFrame ( "Tetris frame", false, true, false, true )
{
@Override
public void setVisible ( boolean aFlag )
{
if ( !aFlag )
{
tetris.pauseGame ();
}
super.setVisible ( aFlag );
}
};
tetrisFrame.setFrameIcon ( loadIcon ( "game.png" ) );
tetrisFrame.add ( tetris );
WebMenuBar tetrisMenu = new WebMenuBar ();
tetrisMenu.add ( new JMenu ( "Game" )
{
{
add ( new JMenuItem ( "New game", loadIcon ( "tetris/new.png" ) )
{
{
setAccelerator ( KeyStroke.getKeyStroke ( KeyEvent.VK_F2, 0 ) );
addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
tetris.newGame ();
}
} );
}
} );
add ( new JMenuItem ( "Unpause game", loadIcon ( "tetris/unpause.png" ) )
{
{
tetris.addTetrisListener ( new TetrisListener ()
{
@Override
public void newGameStarted ()
{
setEnabled ( true );
setIcon ( loadIcon ( "tetris/pause.png" ) );
setText ( "Pause game" );
}
@Override
public void gamePaused ()
{
setIcon ( loadIcon ( "tetris/unpause.png" ) );
setText ( "Unpause game" );
}
@Override
public void gameUnpaused ()
{
setIcon ( loadIcon ( "tetris/pause.png" ) );
setText ( "Pause game" );
}
@Override
public void gameOver ()
{
setEnabled ( false );
setIcon ( loadIcon ( "tetris/pause.png" ) );
setText ( "Pause game" );
}
} );
setAccelerator ( KeyStroke.getKeyStroke ( KeyEvent.VK_P, 0 ) );
addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
if ( tetris.isPaused () )
{
tetris.unpauseGame ();
}
else
{
tetris.pauseGame ();
}
}
} );
}
} );
addSeparator ();
add ( new JMenuItem ( "Close", loadIcon ( "tetris/exit.png" ) )
{
{
setAccelerator ( KeyStroke.getKeyStroke ( KeyEvent.VK_F4, KeyEvent.SHIFT_MASK ) );
addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
tetris.pauseGame ();
tetrisFrame.close ();
}
} );
}
} );