CSSE221: Software Dev. Honors Day 8 Announcements Announcements HW3 due now, solutions will be posted. HW3 due now, solutions will be posted. Questions.

Slides:



Advertisements
Similar presentations
Graphical User Interfaces
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Gui Interfaces a la Swing Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington.
CSSE221: Software Dev. Honors Day 10 Announcements Announcements Fifteen due Monday 11:59 pm. Monday will be a workday. Fifteen due Monday 11:59 pm. Monday.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
Chapter Day 10. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 10 Questions from last Class?? Problem set 2 posted  10 programs from.
Chapter 121 Window Interfaces Using Swing Chapter 12.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
CSSE221: Software Dev. Honors Day 9 Announcements Announcements HW3 passed back, follow link from HW3 to its solution. HW3 passed back, follow link from.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
Java Programming Chapter 10 Graphical User Interfaces.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
CS Lecture 01 Frames and Components and events Lynda Thomas
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
GUI Programming using NetBeans. RHS – SOC 2 GUI construction We have previously talked about elements in a (simple) GUI –Frames, Panes and Dialogs –Text.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
Graphics in Java Dr. Andrew Wallace PhD BEng(hons) EurIng
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Basics of GUI Programming Chapter 11 and Chapter 22.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Graphical User Interface (GUI)
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
GUIs & Event-Driven Programming Chapter 11 Review.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
A Quick Java Swing Tutorial
CompSci 230 S Programming Techniques
Graphical User Interface (pronounced "gooey")
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Timer class and inner classes
Containers and Components
Graphical User Interface
Presentation transcript:

CSSE221: Software Dev. Honors Day 8 Announcements Announcements HW3 due now, solutions will be posted. HW3 due now, solutions will be posted. Questions on Arrays? Questions on Arrays? Max # of elements in an array: Max # of elements in an array: Integer.MAX_INT, but your machine probably doesn’t have enough space to hold this much data! And the JVM will certainly not claim all your memory even if you did. Integer.MAX_INT, but your machine probably doesn’t have enough space to hold this much data! And the JVM will certainly not claim all your memory even if you did. Newer machines (with 64-bit addressing) will have more… but I don’t know how Java is responding (perhaps Java 7 will have long int array indices) Newer machines (with 64-bit addressing) will have more… but I don’t know how Java is responding (perhaps Java 7 will have long int array indices) Today is Constitution Day. Today is Constitution Day. Speaker in Kahn Room in Union, 10 th hour. Speaker in Kahn Room in Union, 10 th hour. No baby yet… No baby yet…

Capsule Deliverables: sec 1 Please the quiz, key, and summary to me by 7:30 am on the day you are presenting. Please the quiz, key, and summary to me by 7:30 am on the day you are presenting. Send.doc files Send.doc files (If you get them to me by 3pm on a weekday before you present, I’ll still print them) (If you get them to me by 3pm on a weekday before you present, I’ll still print them) Lessons from week 1: Lessons from week 1: Nice research and summarization! Nice research and summarization! Proofread your stuff. Everyone else will see it. Proofread your stuff. Everyone else will see it. 1-page quizzes are good (or staple) 1-page quizzes are good (or staple) Summaries don’t have to be verbose, just dense with info. Summaries don’t have to be verbose, just dense with info.

This week: Fifteen assignment Monday: Monday: Fifteen specification Fifteen specification GUIs using Java’s Swing library GUIs using Java’s Swing library Intro to UML as a design tool Intro to UML as a design tool Start Fifteen Start Fifteen Tuesday: Tuesday: EventListeners: responding to user input EventListeners: responding to user input Time to work on project Time to work on project Thursday: Thursday: Anonymous classes (capsule) Anonymous classes (capsule) Function objects and comparators (capsule) Function objects and comparators (capsule)

“Fifteen” Arrays (especially 2D) Creating GUIs using Swing Responding to mouse clicks

Fifteem Teams beltonj1-fishmad bennetrn-leveyjr bennindp-speyerea crockeea-morrisps devorejd-priestjs lundgrpb-skilessa johnsoad-smithny sullivja-wentztj mcginnda behlinmc-bennetdj clutecc-dovalojd gatesds heinma1-hulettbh johnsoac-rubinza kruthar-richarme millerbe-eckertwm mosttw-reillytm nibertjw-stokesej Repos is csse If solo, use your personal repos. Discuss how to pair-program

Fundamentals of Software Development 1 6 The Java Swing Library JFrames, JTextBoxes, JButtons, JScrollPanes… what’s available? JFrames, JTextBoxes, JButtons, JScrollPanes… what’s available? What components will I need… What components will I need… …now, for Fifteen? …now, for Fifteen? …later, for a term project? …later, for a term project? Browse the Visual Index to the Swing Components in Sun’s Java Tutorial. Browse the Visual Index to the Swing Components in Sun’s Java Tutorial.Visual Index to the Swing Components Java TutorialVisual Index to the Swing Components Java Tutorial

JFrame A simple window that contains the other GUI components A simple window that contains the other GUI components Background Color Background Color getContentPane().setBackground(Color); getContentPane().setBackground(Color); Make sure to set visible Make sure to set visible setVisible(true); setVisible(true); Setting the size Setting the size setSize(width, height); setSize(width, height);

Benefits of Extending JFrame or JComponents like JPanel When extending the JFrame class we can still instantiate it as JFrame. When extending the JFrame class we can still instantiate it as JFrame. “Controlling” the JFrame is easier to comprehend when we do not need the calling object stated every time. “Controlling” the JFrame is easier to comprehend when we do not need the calling object stated every time. i.e. setSize(w,h); instead of jFrameObject.setSize(w,h);

JLabel Displays text to user Displays text to user User cannot edit text User cannot edit text Construction: JLabel message = new JLabel(String text); Construction: JLabel message = new JLabel(String text);Methods: String text = message.getText(); String text = message.getText(); message.setText(String text); message.setText(String text);

JTextField Lets user enter or modify a single line of text Lets user enter or modify a single line of text Construction: Construction: JTextField text = new JTextField(int WidthInCharacters); JTextField text = new JTextField(int WidthInCharacters); Getting the Text: Getting the Text: String input = text.getText(); String input = text.getText(); Setting text in a Text Field: Setting text in a Text Field: text.setText(String output); text.setText(String output);

JTextArea Lets user enter or modify multiple lines of text. Lets user enter or modify multiple lines of text. Declaration: private JTextArea text; Declaration: private JTextArea text; Constructors: Constructors: text = new JTextArea(int rows, int columns); text = new JTextArea(int rows, int columns); text = new JTextArea(String output); text = new JTextArea(String output); text = new JTextArea(String output, int rows, int columns); text = new JTextArea(String output, int rows, int columns); Useful methods: Useful methods: String input = text.getText(); String input = text.getText(); text.setText(String output); text.setText(String output); setEditable(Boolean editable); setEditable(Boolean editable); boolean editable = text.isEditable(); boolean editable = text.isEditable();

JButton Used to let user execute action Used to let user execute action Construction: JButton button = new JButton(String text); Construction: JButton button = new JButton(String text); button.setBackground(Color color); button.setBackground(Color color);

JPanel Simple container that groups objects Simple container that groups objects Meant to subdivide Meant to subdivide Creation Syntax: Creation Syntax: JPanel panelName = new JPanel(); JPanel panelName = new JPanel(); Useful attributes and methods Useful attributes and methods.setLayout(new Layout());.setLayout(new Layout());.add(component);.add(component);.setBackground(Color color);.setBackground(Color color);

Layout Managers Frames are organized by layout managers. Frames are organized by layout managers. Organizes the locations of the components within the frame Organizes the locations of the components within the frame Not only frames use layout managers, but Panels are also organized by layout managers. Not only frames use layout managers, but Panels are also organized by layout managers. Allows for panels within panels. Allows for panels within panels.

Layout: Flow Layout Places the components from the left side to the right side. Places the components from the left side to the right side. Wraps around the right side. Wraps around the right side..setLayout(new FlowLayout());.setLayout(new FlowLayout()); No special add syntax. No special add syntax.

Layout: Border Layout North, South, East, West, Center North, South, East, West, Center setLayout(new BorderLayout()); setLayout(new BorderLayout());.add(component, BorderLayout.NORTH);.add(component, BorderLayout.NORTH);

Layout: Grid Layout Similar to flow in the left to right manner, but the grid that you define limits the size of any one component Similar to flow in the left to right manner, but the grid that you define limits the size of any one component You can leave out a definite definition of how many rows or columns are in the grid. You can leave out a definite definition of how many rows or columns are in the grid. setLayout(new GridLayout(r,c)); setLayout(new GridLayout(r,c)); Adds in components from left to right, top to bottom. Cannot specify which block. Adds in components from left to right, top to bottom. Cannot specify which block.

PaintComponent Used with JPanels, and all JComponents, to paint the components on the screen. Used with JPanels, and all JComponents, to paint the components on the screen. Called automatically, no need to invoke it. Called automatically, no need to invoke it. Use repaint(); to force the paintComponent() method to execute. Use repaint(); to force the paintComponent() method to execute. Start with super.paintComponent(g); where g is your Graphics object Start with super.paintComponent(g); where g is your Graphics object public void paintComponent(Graphics g) { super.paintComponent(g); setBackgroundColor(Color.red);g.drawOval(10,40,20,20);}

Alternative designs I want a component to appear. Question: I want a component to appear. Question: Should I paint it? Add a new component? Should I paint it? Add a new component? Answer: It depends… Answer: It depends… On how much control you want over its appearance On how much control you want over its appearance On how you want it to respond to events On how you want it to respond to events It’s usually a tradeoff. It’s usually a tradeoff. Press me!

Listeners If you want to respond to events, you need to implement a Listener interface. If you want to respond to events, you need to implement a Listener interface. We’ll look at these in detail tomorrow We’ll look at these in detail tomorrow

Demo together