|
|
Writing a Java Applet Unlike applications, Java applets are web-based, that is, they are transferred from server to client via HTTP. To facilitate this, every Java applet requires an HTML wrapper, which depends on a browser or appletviewer for the necessary runtime environment. Whereas Java applications are run at the command line, applets are executed within a web page. To test your applet, load a web page containing it into your browser. Alternatively, an applet may be tested with a handy tool called appletviewer. Your first applet is a modification of the program in
% javac Craps.java bankBalance
to wager .
Check that the wager is less than or equal to bankBalance
and if not have the user reenter the wager until a valid amount is
entered. After a correct wager is entered, let the user play a game of
craps. Increase or decrease the bankBalance by wager ,
as the case may be, and print the new bankBalance . When bankBalance
becomes zero, print the message "Sorry, you are busted!".
You may use the source code of this non-functional version of Craps.java
as a starting point. Note carefully the code that has been commented out. This was done to
make the applet |