|
Today we will finish discussing the Interface.java code. Specifically, we will discuss the "setMessages" method, the "placeComponent" method, the various "display" methods, and the general variables used by the "Interface" class. Today's lesson marks the last lesson that involves the user interface. Beginning with the next lesson, we shall start the final unit in the tutorial; a unit that adds server/client capabilities to the Color Belot application. The "setMessages" method is a simple one. It accepts two strings as parameters and sets "message1" and "message2" to these messages. These messages are displayed by the "paint" routine. They provide a relevant message to the user, based on the current situation. The "placeComponent" method accepts a component (such as a "Button") and a row and a column to place it in. (Recall that the display surface is divided into three rows and ten columns.) The method calculates the coordinates of the upper left hand corner of the component, as well as its height and width. These calculations result in the component being located in the appropriate cell in the display surface. The "displayString" method is passed the "row" and "column" of the cell where some "text" should be displayed. A total of "howMany" strings will be displayed centered in the middle of the display window and the particular "text" number is given by "whichOne". The lower the "whichOne" value, the higher the location in the cell where the string will be displayed. The routine does several mathematical calculations to place the string in its desired location. The "displayStringTop" method is very similar to the previous one. In this method, though, strings are displayed centered at the top of the display window. The "displayStrings" method is an overloaded method. The first "displayStrings" method calls the "displayString" method twice to display two strings. The second "displayStrings" method calls the "displayString" method three times to display three strings. The "displayStringsTop" method calls the "displayStringTop" method twice to display two strings at the top of the appropriate cell. The "displayCard" method is used to draw the image of a card. The image is drawn if the "getDisplay" method for the "card" returns a true. The "drawImage" method is given the card image, the coordinates of the upper left corner, the width of the image, and the height of the image. The variables for the "Interface" class are fairly straight forward. First, ten "Button"s and two "Choice"s are declared. The "cards" array is used to store images of the player's cards that are to be drawn on the display surface. "cardOne" is the image of the card that the player last played. "cardTwo" is the image of the card that the opponent last played. "cardThree" is the image of the flipped card. "opponentCard" is the actual card that the opponent last played. "cardBackImage" is the image of the back of a card. "belotGame" contains all of the information about the current game of Color Belot. "clickableImages" is true if the player can currently select one of her cards by clicking on it and false otherwise. "dealer" indicates who dealt, "trickLeader" indicates who led the last trick, "height" is the height of the applet in pixels, "width" is the width of the applet in pixels. The current message to be displayed is stored in "message1" and "message2". Finally, "fm" is information about the font metrics being used. Congratulations, you are now finished with the user interface portion of this tutorial! |