Đang chuẩn bị liên kết để tải về tài liệu:
Java By Example PHẦN 8

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Khi bạn chạy applet dưới Appletviewer, bạn sẽ thấy cửa sổ hiển thị trong hình 20,3. Các văn bản trong cửa sổ được hiển thị bằng cách sử dụng màu sắc hiện đang được chọn trong menu lựa chọn. Để thay đổi màu sắc văn bản, chỉ cần chọn một mục trình đơn mới. Hình 20,3 ChoiceApplet hiển thị văn bản trong các màu sắc được lựa chọn từ trình đơn lựa chọn. | parameter s values and supply default values for those parameters that are missing or invalid. For example to make sure that your applet has a text string to display you might use lines like this str getParameter text if str null str Default Text NOTE If you decide to release your applets so other people can use them in their Web pages be sure that you include a separate documentation file that describes the applet s parameters and shows how to use them. Example Using Default Parameters in an Applet You can now extend the ConfigApplet2 so that it provides default values for each parameter. When you ve done this the applet can run without generating errors no matter what parameters the user chooses to include or ignore. Listing 26.7 is the new version called ConfigApplet3. Notice that although the program now checks for missing parameters it doesn t limit the values to any ranges or otherwise check their validity. Because the text parameter will always be a string there s really nothing you need to check for except null . However you may want to limit the font size or make sure that the display location is inside the applet s window. Listing 26.8 is the HTML document used to load and run the applet as it s displayed in Figure 26.4. Figure 26.4 This is ConfigApplet3 running under Appletviewer. Listing 26.7 ConfigApplet3.java This Applet Provides Default Values for All Parameters. import java.awt. import java.applet. public class ConfigApplet3 extends Applet String str Point position public void init HandleTextParam HandleTypeSizeParam HandlePositionParam public void paint Graphics g g.drawString str position.x position.y protected void HandleTextParam str getParameter text if str null str Default Text protected void HandleTypeSizeParam String s getParameter typesize if s null s 24 int typeSize Integer.parseInt s Font font new Font TimesRoman Font.BOLD typeSize setFont font protected void HandlePositionParam String s getParameter xpos if s null s 20 int xpos .

Đã 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.