lec18 - 1.00 Lecture 18 Swing Event Model Reading for next...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1.00 Lecture 18 Swing Event Model Reading for next time: Big Java: sections 10.1-10.6, 9.5 GUI Event Model: Paradigm Shift Operating system (Windows, JVM) runs the show: Monitors keystroke, mouse, other I/O events from sources Dispatches event messages to programs that need to know Each program decides what to do when the event occurs This is the reverse of console-oriented programming, where the program runs the show, and asks the operating system (OS) to get input when it wants it Event sources: menus, buttons, scrollbars, etc. Have methods allowing event listeners to register with them When event occurs, source sends message (an event object) to all registered listener objects EventObject is the superclass • ActionEvent, MouseEvent , etc. are subclasses that we use Event listeners: objects in your program that respond to events 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Events: JButton Exercise Download BFrame, ButtonTest, ButtonPanel We will build an application User presses button Application shows number of button presses Demo Button Example Framework panel ButtonPanel button (event source) (event listener) button.addActionListener(panel) Button press events actionPerformed method implements ActionListener 2
Background image of page 2
Events: JButton Exercise Preliminaries: Complete ButtonTest as shown on next page: Main(): Create new BFrame (inherits from JFrame, to be written) Sets default close operation Sets frame visible Complete BFrame: Set title Set size Get contentPane Create ButtonPanel object (ButtonPanel written next) Add the ButtonPanel object to the contentPane Use last lecture’s notes as a guide Exercise: Button, p.1 import javax.swing.*; public class ButtonTest { public static void main(String[] args) { // Create new frame // Set default close option // Show frame (set visible) } } // main has 1 st 3 lines of SwingTest main (last lecture) import java.awt.*; import javax.swing.*; public class BFrame extends JFrame {
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

lec18 - 1.00 Lecture 18 Swing Event Model Reading for next...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online