CS3157 Java UI Recitation

8
CS3157 Java UI Recitation

description

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 - PowerPoint PPT Presentation

Transcript of CS3157 Java UI Recitation

Page 1: CS3157  Java UI Recitation

CS3157 Java UI Recitation

Page 2: 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

Page 3: CS3157  Java UI Recitation

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

Page 4: CS3157  Java UI Recitation

Component Hierarchy

• All components except for menu related components inherit from the AWT Component class.

Page 5: CS3157  Java UI Recitation

• 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

Page 6: CS3157  Java UI Recitation

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 }

Page 7: CS3157  Java UI Recitation

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>

Page 8: CS3157  Java UI Recitation

Sample Applet

• See SampleApplet.html