JTet
JTet running as an application

Tetris

When Java was first designed, it was unique in that it could produce both standalone aps and applets that could be placed on web pages. But unfortunately over the years it determined that the web technology allowing applet on web pages could be used for malware. As a consequence, web browsers started placing increasing restrictions on that technology. Today, almost all browsers have dropped support for it. This unfortunately means that Java applets rarely, if ever, will work on web pages any more.

This page was designed before it became impossible to use applets on web pages. So, unfortunately, you will probably be unable to run the program on the web page. Instead you will need to download the zip file. You can run the applet using this command at a DOS prompt in the subfolder:
appletviewer JTet.html

Alternatively, you can run it as an application using its jar file by typing the following at a DOS prompt:
java JTet -jar
In Windows, you may be able to run the ap by just double clicking on the JTet.bat file in the folder holding the files.

James Brink, July 28, 2018

Applet failed to run. No Java plug-in was found.

Click on the applet area and keep the mouse pointer inside applet's area.
Control keys:

Adapted from http://jtet.sourceforge.net/

Compiling and running JTet

Because JTet requires numerous source and class files, the class files have been grouped in two .jar files, JAppletFrame.jar and JTet.jar. You can download and explode the JTet.zip file which includes the code, jar, bat, and documentation files.


To run the file as an application use the DOS command:
java JTet -jar

Should you want to recompile JTet, use the DOS commands:
javac JTet.java
jar -cfe JTet.jar JTet *.class

For M.S. Windows users there is a .bat file that simplifies working with JTet. Double clicking the JTet.bat in a My Computer listing runs JTet as an application. In a DOS window, the following commands can be used:

jtet compile--- compile JTet and create a new JTet.jar file
jtet appletviewer--- run in the AppletViewer
jtet--- run as an application
jtet ?--- print complete usage instructions

There is one difference between running JTet as an applet and as an application. As shown in the image, when run as an application, the list of control is shown. That list is hidden when it is run as an applet under the assumption that the applet would be on a web page that would show the control keys for the game. Unfortunately, that isn't the case any more because it can be run on a web page and one can't show the direction when it is run in the appletviewer.

Modifications made to allow use as an application

The original JApplet used 6 classes each having the own file. But after making sure that JTet would run as an applet on my computer, opnly the following changes to the JTet.java file were needed in order to convert it to a JAppletFrame:

Old codeNew code
public final class JTet extends JApplet implements FocusListener, MouseListener { public final class JTet extends JAppletFrame implements FocusListener, MouseListener {
New method and panel

The applet assumes the .html page
provides the instructions. This is not
the case running as an application. So
main method adds a JTextArea in a
JPanelto provide the instructions. The
game would run perfectly without the
panel providing the user already knew
the how to use it.

public static void main(String [] args) {
    JPanel instPnl = new JPanel();
    JTextArea instArea = new JTextArea(9, 40);
    JTet applet = new JTet();
    JFrame a = applet.displayJFrame(applet, "Tetris", 450, 456, args);
    instPnl.add(instArea);
    instArea.append("Click game and keep mouse inside it.n");
    instArea.append("\nControl keys");
    instArea.append("\n N - Start new game(This may take some time)");
    instArea.append("\n P - Pause game");
    instArea.append("\n Down arrow - Move tetramino down");
    instArea.append("\n Left arrow - Move tetramino left");
    instArea.append("\n Right arrow - Move tetramino right");
    instArea.append("\n A - Rotate tetramino left");
    instArea.append("\n S - Rotate tetramino right");
    instArea.append("\n ");
    applet.add(instPnl, "South");
    a.pack();
}

Files Included in the Zip File

Send comments, questions, or suggestions to
James Brink, brinkje@plu.edu Pacific Lutheran University,
July 8, 2013, revised July 28, 2018