Chapter 14: Java Part II
pages 1 - 31
Applets
- Programs embedded in HTML pages
- In contrast, an application is a stand-alone program
Relevant HTML Tags
- Look at the source code of this example
- Notice the applet tag
- Notice the code, height, width and
codebase attributes
Java GUI Classes
- JLabel
- JTextField
- JButton
Event Handling
Example
Applet Life Cycle
- public void init()
- public void start()
- public void stop()
- public void destroy()
Friday Exercises
- Understand and be able to explain the above code
and html file to John
or Jack - 2 questions, 2 points.
- Modify the above code so that it can detect wins and print
an appropriate message when the win occurs. When a win occurs,
no further moves are allowed. Demo the above program to
Jack or John - 3 points.
Monday Exercises
- Modify the program so that a user can enter the size of
the n by n board. Legal values for n range from 1 through 10.
You may assume that only legal values will be entered.
- Modify the program so that it can detect a win on an n by n board.
A win consists of n 'X's or n 'O's in a row, a column or a diagonal.
- Modify the program so that at the end of a game (win for X, win
for O, cat's game) the user has the option to either play
again or quit.
- When you are finished, copy your relevant Java files into an
appropriate folder on John's memory stick. Your program will be
graded on functionality, correctness and elegance of solution.
No comments are necessary.
Sample Solution to Monday's Exercise