Danh mục tài liệu

Java Programming for absolute beginner- P15

Số trang: 20      Loại file: pdf      Dung lượng: 394.77 KB      Lượt xem: 20      Lượt tải: 0    
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Java Programming for absolute beginner- P15:Hello and welcome to Java Programming for the Absolute Beginner. You probablyalready have a good understanding of how to use your computer.These days it’s hard to find someone who doesn’t, given the importanceof computers in today’s world. Learning to control your computer intimatelyis what will separate you from the pack! By reading this book, you learnhow to accomplish just that through the magic of programming.
Nội dung trích xuất từ tài liệu:
Java Programming for absolute beginner- P15 JavaProgAbsBeg-07.qxd 2/25/03 8:53 AM Page 238 238 First off, it extends Frame, so it is a Frame. It sets its background color to System- Color.control, which as you might remember from the previous chapter, is the Java Programming for the Absolute Beginner color that your operating system uses for painting windows. Then it adds a Win- dowAdapter object as its WindowListener. Pay close attention to the syntax here. This is actually an inner-class declaration, which you’ll learn about later on in this chapter. Another cool thing it does is center itself, no matter what size it is when it becomes visible. I did this by overriding the setVisible(boolean) method. If the argument passed in is true, I get the screen size by calling Toolkit.getDefault- Toolkit().getScreenSize(), which returns a Dimension object representing the resolution of the computer screen, whether it is 640 by 480, 800 by 600, or what- ever. The Toolkit class is the abstract subclass of all implementations of the AWT, the default of which is different depending on what operating system you are running. To center the GUIFrame on screen I needed to know the screen size and the size of the GUIFrame. The position of the GUIFrame is set with the setLoca- tion(int, int) method, where the first int is the x location and the second int is the y location. The center location is half the difference of the screen width minus the GUIFrame width as the x position, and half the difference of the screen height minus the GUIFrame height as the y position. super.setVisible(visible) is called so that the corresponding method in the Frame class can take care of actually making the GUIFrame visible. Take a look at Figure 7.7 to see what the GUIFrame looks like. Here is a test of the GUIFrame class, GUIFrameTest: /* * GUIFrameTest * Demonstrates the GUIFrame Class */ public class GUIFrameTest { public static void main(String args[]) { GUIFrame frame = new GUIFrame(GUIFrame Test); frame.setSize(400, 300); frame.setVisible(true); } } Using CardLayout The CardLayout layout manager lays out its components as cards. You can think of each card as a card within a deck of playing cards. To make this analogy work, imagine that the cards are face up and only the top card is visible. You can take a card off the top of the deck and add it to the bottom to make the next card vis- ible. Each card is actually a Java component. Only one of the components is visi- TEAM LinG - Live, Informative, Non-cost and Genuine!Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. JavaProgAbsBeg-07.qxd 2/25/03 8:53 AM Page 239 239 Chapter 7 Advanced GUI: Layout Managers and Event Handling FIGURE 7.7 The GUIFrame class tested here is used throughout this chapter. ...

Tài liệu được xem nhiều:

Tài liệu có liên quan: