CS3157 Java UI Recitation
-
Upload
harrison-santiago -
Category
Documents
-
view
32 -
download
2
description
Transcript of CS3157 Java UI Recitation
CS3157 Java UI Recitation
• Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI.
• Not covered in recitation: Drawing, Images, Layout Manager
AWT Components
• Containers: Windows (Frame, Dialog, FileDialog) , Panel, Scroll Pane
• Basic Controls: Buttons, Checkbox, Choice, List, MenuItem, TextField
• Others Components: Slider, ScrollBar, TextArea, Label, Canvas
Component Hierarchy
• All components except for menu related components inherit from the AWT Component class.
• Windows, Frames and Dialogs are top level containers.
• Add components to another component.– i.e. Add a panel to a frame– Add a button to a panel
• Add event listeners to component
Event Handling• 1.1 AWT Event Modeling
– Event generated by event sources.– Listeners register to be notified about events
• Event handler implements event listener interface– public class MyEventHandler implements ActionListener { }
• Register listener on a component– myComponent.addActionListener(myEventHandler);
• Implementation of methods in the listener interface– public void actionPerformed(ActionEvent e) { // code that reacts to the action }
Applet• extends java.applet.Applet class• Methods:
– init() // initialize applet– start() // start applet– stop() // stop applet– destroy() // cleanup, unload applet
• Running an applet– Embed applet in an html
<APPLET CODE=AppletSubclass.class WIDTH=anInt
HEIGHT=anInt> </APPLET>
Sample Applet
• See SampleApplet.html