CH12 - Chapter 12 Window Interfaces Using Swing Objects...

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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)
Image of page 2
Chapter 12 Java: an Introduction to Computer Science & Programming - Walter Savitch GUIs—Graphical User Interfaces Most modern programs use a GUI GUI (pronounced “gooey”): G raphical—not just text or characters: windows, menus, buttons, etc. U ser—person using the program I nterface—way 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
Image of page 3

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

View Full Document Right Arrow Icon
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
Image of page 4
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 agent—the 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
Image of page 5

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

View Full Document Right Arrow Icon
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 don’t…”); myWindow.getContentPanel().add(myLabel); WindowDestroyer myListener = new WindowDestroyer(); myWindow.addWindowListener(myListener); myWindow.setVisible(true); } }
Image of page 6
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; public static final int HEIGHT = 200; public static void main(String[] args) {
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern