TAILIEUCHUNG - Java By Example PHẦN 7

Bằng cách so sánh các văn bản cho các mục bạn đã thêm vào trình đơn, bạn có thể xác định mục trình đơn cho người sử dụng đã chọn. Applet ChoiceApplet, có mã nguồn được thể hiện trong bảng liệt kê 20,2, chứng minh việc tạo ra và đáp ứng trình đơn lựa chọn trong một applet. Liệt kê 20,3 là tài liệu HTML của Applet. | public class FrameApplet2 extends Applet CustomFrame frame Button button public void init frame new CustomFrame Custom Frame Window button new Button Show Window add button public boolean action Event evt Object arg boolean visible if visible Show Window else Hide Window return true class CustomFrame extends Frame CustomFrame String title super title public void paint Graphics g resize 200 100 This is a custom window. 30 30 Tell Java that the applet uses the classes in the awt package. Tell Java that the applet uses the classes in the applet package. Derive the FrameApplet2 class from Java s Applet class. Declare the custom frame-window and button objects. Override the init method. Create the custom frame window. Create the button component. Add the button to the applet. Override the action method. Determine whether the window is visible. If the window is visible. Hide the window. Change the button s label to Show Window. Else if the window is hidden. Show the window. Change the button s label to Hide Window. Tell Java that the message was handled okay. Derive the CustomFrame class from Java s Frame class. Define the class s constructor. Pass the title string on to the Frame class. Override the window s paint method. Resize the window. Display a message in the window. NOTE When you compile FrameApplet2 notice that although both the FrameApplet2 and CustomFrame classes are defined in the same file the Java compiler creates two class files called and . Example Adding Components to a Window Frame windows are just like any other window you see when you create an applet. That is you can add components organized into a variety of layouts and respond to the user s selections of these components. In fact adding layouts and components to a frame window is not unlike doing the same thing with your applet s main window which you did in the previous chapter. .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.