
Java Programming for absolute beginner- P15
Thông tin tài liệu:
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ìm kiếm theo từ khóa liên quan:
Nhập môn lập trình lập trình website lập trình ngôn ngữ html giáo trình php lập trình C++Tài liệu có liên quan:
-
Đề cương chi tiết học phần Cấu trúc dữ liệu và giải thuật (Data structures and algorithms)
10 trang 357 0 0 -
Bài tập lập trình Windows dùng C# - Bài thực hành
13 trang 204 0 0 -
Bài giảng Nhập môn về lập trình - Chương 1: Giới thiệu về máy tính và lập trình
30 trang 188 0 0 -
Giáo trình nhập môn lập trình - Phần 22
48 trang 143 0 0 -
[Thảo luận] Học PHP như thế nào khi bạn chưa biết gì về lập trình?
5 trang 137 0 0 -
8 trang 99 0 0
-
Bài giảng Nhập môn lập trình - Chương 12: Quản lý bộ nhớ
23 trang 69 0 0 -
Giáo trình Lập trình Website (Nghề Tin học ứng dụng - Trình độ Cao đẳng) - CĐ GTVT Trung ương I
156 trang 62 2 0 -
Báo cáo đồ án môn học II: Thiết kế website bán đồng hồ
25 trang 55 0 0 -
42 trang 53 0 0
-
Tạo mạng xã hội với PHP - part 43
10 trang 46 0 0 -
4 trang 43 0 0
-
Bài giảng Nhập môn lập trình: Bài 2 - Thuật toán
32 trang 42 0 0 -
Nhập môn lập trình (Đặng Bình Phương) - Các khái niệm cơ bản về hệ điều hành
17 trang 39 0 0 -
MỘT SỐ KHÁI NIỆM CƠ BẢN CỦA NGÔN NGỮ C
49 trang 38 0 0 -
Một số giải pháp lập trình ASP.NET 2.0
82 trang 38 0 0 -
LẬP TRÌNH C ++ QUẢN LÝ NHÀ TRỌ
12 trang 38 0 0 -
Câu hỏi bài tập nhập môn lập trình
11 trang 37 0 0 -
CÁC KHÁI NIỆM CƠ BẢN VỀ LẬP TRÌNH
21 trang 36 0 0 -
142 trang 35 0 0