⇒ Creates a paragraph that is separated by lines 15.7 Important Points When Java files are compiled, Java binary code is created in the form of class files For an applet, these files are shipped and executed at the client The client must have the Java Virtual Machine (JVM) software to execute the class files An applet does not have a main method Instead, it overrides the init method of the JApplet class The code of a Java Applet cannot set applet title, size, location, and so on All these parameters are set in the HTML file Only the web browser can close an applet Therefore, an applet should not have code that terminates the applet Use the codebase property to define the directory of the class files Resource files, such as images, can be created in a subdirectory of the codebase directory The HTML code inserts an applet with code base directory classes (relative to the directory that contains the html file) The code of the applet is in the file TicTacToe.class The applet will be displayed in a 350 x 200 pixels rectangular area inside the web browser 360 15.8 Learning Java through Games Exercises Transform the calculator program from Chapter 12 into a Java Applet The applet should appear inside a web browser without a new window being opened You can use the HTML file that is generated by NetBeans Create a Java Applet that converts Celsius to Fahrenheit The applet should appear inside a web browser without a new window being opened You can use the HTML file that is generated by NetBeans Create a Java Applet for the Breakout game The applet should appear inside a web browser without a new window being opened Create your own HTML file 15.9 Lab Modify the Tic-Tac-Toe game by making the AI stronger See if you can make the computer player so good that the program never loses 15.10 Project Extend the Tic-Tac-Toe game to work on a 15 x 15 board, where you need a line of characters to win Your AI will first check if the computer can win Then it will check if the human player can be prevented from winning on the next move Next, check if the computer can make a line of characters that is open at both ends and that can be used to win the game on the next move If such a line does not exist, your program should search to see if it can prevent the human player from creating such a line and so on Your program does not need to be perfect, that is, it is expected that it will lose some games Once the mouse cursor hovers over an empty square of the board, make the square green in order to indicate that the human player can play there Display an appropriate message when the game ends In the unlikely event that the board becomes full without anyone getting a line of characters, the game should be declared a draw THROUGH GAMES THROUGH GAMES Learning Java Through Games teaches you how to use the different features of the Java language as well as how to program The book covers as much material as possible from the latest Java standard while requiring no previous programming experience Taking an application-motivated approach, the text presents an abundance of games You must read through the whole chapter to understand all the features that are needed to implement the game Most chapters start with a description of a game and then introduce different Java constructs for implementing the features of the game on need-to-use bases The first part of the book covers basic programming techniques, such as conditional statements, loops, methods, arrays, and classes The second part focuses on more advanced topics, including class inheritance, recursions, sorting algorithms, GUI programming, exception handling, files, and applets This text explains not only how to write code that works but also how to follow good software practices All sample programs in the text strive to achieve low cohesion and high coupling—the hallmarks of well-designed code Many programs are refactored multiple times to achieve code that is easy to understand, reuse, and maintain K20606 Programming Languages LUBOMIR STANCHEV ... languages include C, C++, and Java An advantage of using a high-level programming language is that the programmer does not need to deal with physical main Learning Java through Games memory addresses... 2.1 2.2 2.3 2.4 Java primitive types Java comparison operators Java operators on Boolean values Comparison of String elements 17 25 28 30 3.1 Increment/decrement Java shortcuts... that can perform simple calculations These include addition, deletion, subtraction, Learning Java through Games FIGURE 1.1: A Colossus Mark computer Artwork created by United Kingdom Government