How to Develop a Tetris Game in Java Without an Applet

Written by darrin koltow
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Develop a Tetris Game in Java Without an Applet
( Images)

The Russian scientist Alexey Pajitnov developed the video game Tetris in 1984. It combines puzzle and action games by requiring players to position puzzle pieces within a time constraint as they fall to the bottom of the playing field. Converting a Java Tetris applet to an application involves replacing each user-event function (e.g. mouse clicks) of an applet with an equivalent function of a Java application. Developing a Java Tetris application, besides delivering the satisfaction of producing the game, will build programming skills that you can apply to develop other games.

Skill level:

Other People Are Reading

Things you need

  • Java development kit

Show MoreHide


  1. 1

    Download the source code for a Java applet implementing a Tetris clone. Compile the code in your integrated development environment (IDE), then run and play the game. Take notes on how you'd like to change the game play.

  2. 2

    Create a new, blank application (not an applet) in your IDE. Then copy those functions of the applet not listed on the Oracle "Building Applets" page. These functions are specific to Java applets.

  3. 3

    Copy into your application the functions from a sample application packaged with your IDE that implements the same event functionality as the Tetris applet you downloaded.

    For example, the code from the sample application that detects and responds to key presses might appear as

    public KeyPressDetected(event Object e) {

    if (e.key = SPACE_KEY) {
        // Respond to press of space bar here



    Copy this code into your Tetris application to replace the applet code "actionperformed," which responds to the user pressing the "Space" key.

  4. 4

    Read the source code in your IDE. Write comments for any code portions you understand. For example, you may see a line of code that reads like this:

    Piece_velocity = Piece_velocity + 0.5;

    You may add the following comment to that statement:

    //Increase the rate the puzzle pieces fall

  5. 5

    Print out the source code, then retype it and compile it. Retyping the code forces you to read it carefully, which is a prerequisite to understanding more of the program. Write more comments describing the purpose of new statements as you understand them.

  6. 6

    Retype, compile and run the game again, but without looking at the source code for one particular function -- recite that function from memory, as best you can. Once you can recite the selected function, choose another to recite and repeat this step. Continue in this way until you've committed each function to memory. Once you've completed this step, your understanding enough of the program sufficient to change it.

  7. 7

    Type the program code for a cosmetic change (e.g. colour of the puzzle pieces, time between new pieces) you wrote down in step 1. For example, to change a piece's colour from yellow to gold, your code may appear as follows:

    Puzzle_color.Red = 192;

    Puzzle_color.Green = 161;

    Puzzle_color.Blue = 4;

  8. 8

    Write the program code for a more significant change on your list, such as logic that determines the velocity of the puzzle pieces. For example, to base the velocity on the number of placed pieces, you may write the following:

    if (nPiecesPlace >= 20) {

    piece_velocity += 0.3;


  9. 9

    Write the program code for each of the remaining items on your list of changes to implement the change. Completing this step produces your own variant of Tetris in a Java application.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.