giáo trình Java By Example phần 4

Tham khảo tài liệu 'giáo trình java by example phần 4', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | public boolean action Event evt Object arg repaint return true 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 ListApplet class from Java s Applet class. Declare the list object. Override the init method. Create the list object. Add items to the list object. Add the list to the applet. Set the applet s size. Override the paint method. Draw a label in the applet s display. Get the selected item from the list box. If there is no item selected set the string to None. Display the selected item. Override the action method. Force the applet to repaint its display. Tell Java that the event was handled okay. When you run ListApplet with Appletviewer you see the window shown in Figure . When you double-click an item in the list Java calls the applet s action method in which the applet calls the repaint method. This forces Java to call the paint method where the applet retrieves the selected item and displays it. Figure The scrolling list in this applet lets you choose a single musical artist. Notice the call to resize in the init method. The resize method enables you to set the applet to any size you wish. This size overrides any size setting that s included in the HTML document that ran the applet. http The TextArea Control Throughout this book you ve been using the TextField control to retrieve information from the user. In most cases the TextField control works great but it does have some limitations the most serious being the fact that it can display only one line of text at a time. There may be situations where you d like to display one or more paragraphs of text in your applet in a control that enables the user to edit existing text as well as enter his or her own text. This is where the TextArea control is useful. The TextArea control is a text box that acts like a simple word processor. When you display a text box the user can type and edit .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
3    61    2    29-04-2024
Đã 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.