CH12 - Chapter 12 Java: an Introduction to Computer Science...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Chapter 12 Java: an Introduction to Computer Science & Programming - Walter Savitch Chapter 12 Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs Inner Classes Window Interfaces Using Swing Objects Chapter 12 Java: an Introduction to Computer Science & Programming - Walter Savitch Swing Special library of classes that allows Java programs to have a windowing interface Part of larger collection called Java Foundation Classes or JFC An improved version of older library called Abstract Window Toolkit ( AWT ) Standard part of all versions of Java 2 (JDK 1.2) Chapter 12 Java: an Introduction to Computer Science & Programming - Walter Savitch GUIsGraphical User Interfaces Most modern programs use a GUI GUI (pronounced gooey): G raphicalnot just text or characters: windows, menus, buttons, etc. U serperson using the program I nterfaceway to interact with the program Typical graphical elements: Window portion of screen that serves as a smaller screen within the screen Menu list of alternatives offered to user Button looks like a button that can be pressed Chapter 12 Java: an Introduction to Computer Science & Programming - Walter Savitch Event-Driven Programming Programs with GUIs often use Event-Driven Programming Program waits for events to occur and then responds Examples of events: Clicking a mouse button Dragging the mouse Pressing a key on the keyboard Firing an event when an object generates an event Listener object that waits for events to occur Event handler method that responds to an event Chapter 12 Java: an Introduction to Computer Science & Programming - Walter Savitch A New Approach to Programming Previous Style of Programming: List of instructions performed in order Next thing to happen is next thing in list Program performed by one agentthe computer Event-Driven Style of Programming: Objects that can fire events and objects that react to events Next thing to happen depends on next event Program is interaction between user and computer Chapter 12 Java: an Introduction to Computer Science & Programming - Walter Savitch Very Simple Swing Demonstration import javax.swing.*; public class FirstSwingDemo { public static final int WIDTH = 300; public static final int HEIGHT = 200; public static void main(String args) { JFrame myWindow = new JFrame(); myWindow.setSize(WIDTH, HEIGHT); JLabel myLabel = new JLabel(Please dont); myWindow.getContentPanel().add(myLabel); WindowDestroyer myListener = new WindowDestroyer(); myWindow.addWindowListener(myListener); myWindow.setVisible(true); } } Chapter 12 Java: an Introduction to Computer Science & Programming - Walter Savitch Notes on the Simple Demo Program import javax.swing.*; public class FirstSwingDemo { public static final int WIDTH = 300;...
View Full Document

Page1 / 39

CH12 - Chapter 12 Java: an Introduction to Computer Science...

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

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