TAILIEUCHUNG - Intro to Java Programming phần 4

Xác định vị trí các thành viên dữ liệu ImageButton cắt trong ImageButton thư mục và kéo nó trực tiếp bên dưới dòng cuối cùng của mã Shown trên. Nếu mã của bạn bây giờ trông như thế này | Building the Image Button Part 2 protected void fireActionEvent if actionListener null new ActionEvent this actionCommand This calls the actionPerformed method of all the registered listeners with a new action event describing the details of the event effectively broadcasting the action event to all interested Listeners. Now it s time to implement getPreferredSize . Back to top Step 11 - Implementing getPreferredSize Because our button selects images from an image pool we don t know at design time how big to make the button. Thus we implement a getPreferredSize method. This method will be called by the layout manager of our container in order to calculate the button size. We need to return a size based on the size of the image we are using. Returns the preferred size of this component. @see getMinimumSize @see LayoutManager public Dimension getPreferredSize If the current image is not null then return the size of the image. If it is null defer to the super class. Insert ImageButton getPreferredSize We are overriding the getPreferredSize method from . It returns a Dimension object which specifies the preferred height and width of our button. Locate the ImageButton getPreferredSize clipping in the ImageButton folder and drag it directly below the last line of code shown above. Your code should now look like this Building the Image Button Part 2 Returns the preferred size of this component. @see getMinimumSize @see LayoutManager public Dimension getPreferredSize If the current image is not null then return the size of the image. If it is null defer to the super class. Insert ImageButton getPreferredSize if image null return new Dimension this this return We want to return the size of our current image as the preferred size of the button. The first thing we do is check to see if the image is null. If it is we call getPreferredSize from our

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.