Lecture Java programming language: GUIs and Event-Driven programming - Ho Dac Hung

Lecture Java programming language: GUIs and Event-Driven programming provide knowledge about what is a gui, the swing package, the swing package, the Jbutton class, handling events, layout manager, controlling layout, getting input from the user, | GUIs and Event-Driven Programming Ho Dac Hung 1 What is a GUI A GUI is a graphical user interface. 2 What is a GUI Not only does a GUI use components such as frames buttons text fields to communicate with the user but GUIs are event-driven. An event- driven application executed code in response to events. A GUI responds to an event by executing a method called an event handler. 3 The Swing Package The Swing API is part of the Java Foundation Classes and contains numerous components for creating GUIs. A frame is a top-level container for a GUI which holds and displays all the other components of an interface in a content frame. 4 The Swing Package setDefaultLookAndFeelDecorated boolean setDefaultCloseOperation class constant getContentPane setContentPane Container contentPane pack setVisible boolean 5 The Swing Package A Jframe object uses a content pane to hold GUI components A Jpanel object is one choice for a simple content pane. add Component GUIcomponent remove int index 6 The Swing Package The swing package include the JLabel class for creating labels that can be added to a content pane. JLabel String str JLabel String str align constant setText String str 7 The JButton Class A button is commonly used GUI component. A button can be clicked by the user to communicate with the application. 8 The JButton Class JButton String str setActionCommand String cmd getActionCommand addActionListener Object 9 Handling Events Swing components use listeners to determine if an event has occurred. A listener is an object that listen for action events. When an event is heard the listener responds by executing an event handler named actionPerformed . The actionPerformed method has an ActionEvent parameter passed by the GUI when an event occurs. The ActionEnevt parameter passed by the GUI when an event occurs. 10 Controlling Layout Layout refers to the arrangement of components In a Swing GUI the layout of a content pane can be controlled by adding border using a layout manager

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