Feb 18, 2000 Intermediate Containers. Global, Local and Static zGlobal/local are terms for variables in a program written in procedural-based language.

Slides:



Advertisements
Similar presentations
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Advertisements

Lecture 20 – Swing Layout Programming Lecturer: Prof Jim Warren.
Event Handling Feb 14, Event Model Revisited zRecall that a component can fire an event. zEach type of event is defined as a distinct class. zAn.
What is Covered Everything up to and including Lecture 11 Types Recursion (including grammars) Lists and Trees GUIs Does not include Big-O notation (Lecture.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
Events ● Anything that happens in a GUI is an event. For example: – User clicks a button, presses return when typing text, or chooses a menu item ( ActionEvent.
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.
“Look and Feel” and Layouts Feb 11, Pluggable Look and Feel zYou can change the looking or “look and feel” of your Swing application easily into:
JFC and the Swing Package Feb 10, Java Foundation Class (JFC) zAWT (Abstract Window Toolkit) has been used since jdk1.0 Archaic and very poorly.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
Graphical User Interfaces
GUI and event-driven programming An introduction.
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
Chapter 8: Graphical User Interfaces Objectives - by the end of this chapter, you should be able to do the following: –write a simple graphical user interface.
Introduction to GUI Java offers a great number of pre-defined classes to support the development of graphical user interfaces –These are broken down into.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington User Interface COMP 112 #30.
Lesson 27: Introduction to the Java GUI. // helloworldbutton.java import java.awt.*; import javax.swing.*; class HelloButton{ public static void main.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
CSE 219 Computer Science III Graphical User Interface.
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Lesson 36: The calculator – Java Applets. 1. Creating Your First Applet HelloWorldApp is an example of a Java application, a standalone program. Now you.
CS377A: A Programming Approach to HCI Jan Borchers Spring Swing Refresher David Merrill 5/14/2002
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
Lab 6: Shapes & Picture Extended Ellipse & Rectangle Classes Stand-Alone GUI Applications.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Lesson 34: Layering Images with Java GUI. The FlowLayout RECAP.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
GUIs for Video Games. The Plan ● Layout suggestions ● Observer/Observable ● Steps to writing Observer/Observables ● Sample Code ● Practice.
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.
1.  At the end of this slide, student able to:  Object-Oriented Programming  Research on OOP features.  Do a code walkthrough to examine the implementation.
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.
Lesson 39: More wrapup on GUIs. 1.This presentation will focus on the decisions around software architecture and the decisions that will drive the code.
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
Creating a GUI with JFC/Swing. What are the JFC and Swing? JFC –Java Foundation Classes –a group of features to help people build graphical user interfaces.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Topic 13 List Boxes. JList Generates an ListSelectionEvent Event monitored by ListSelectionListener ListSelectionListener invokes method valueChanged.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Computer Science 209 GUIs Model/View/Controller Layouts.
Outline Creating Objects The String Class The Random and Math Classes Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
1CS480: Graphical User Interfaces. Dario Salvucci, Drexel University. Lecture 3: Layout Basics.
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)
Menus and Toolbars CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Lesson 33: Layout management and drawing – Java GUI.
Notes for Assignment #2 Assn2: GUI Database Interface Corresponds with Chapters 28, 29, 31.
제 14 장 고급 스윙 컴포넌트.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
GUI Programming in Java Hao Jiang Boston College April, 2009.
Import javax.swing.*; class Check { public static void main(String[] args) { JFrame frame = new JFrame("Check"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//DO_NOTHING_ON_CLOSE.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
GUI 1: JFC and Swing Basics OOP tirgul No
Object-Oriented Software Engineering
Graphical User Interfaces
GUIs Model/View/Controller Layouts
Java GUI.
A Quick Java Swing Tutorial
A Quick Java Swing Tutorial
Real World Scenario Sometimes it's appropriate to have exactly one instance of a class: window manager print spooler Filesystems press Ctrl-F to display.
Computer Science 209 Images and GUIs.
Presentation transcript:

Feb 18, 2000 Intermediate Containers

Global, Local and Static zGlobal/local are terms for variables in a program written in procedural-based language. (such as C) zSince we are doing OOP (everything is object), we can not distinguish global/local objects in program level. zHowever, we can say class variable( or fields) are global within an object since they are visible to all methods in the same object. (In that sense, whatever defined in a method is local) Therefore, fields are global in an object level. zStatic keyword is introduced to serve as global, however this should be carefully understood. Recall we can not say which object is global or local.

What it means by static zIn OOP world, every object should be instantiated to be used in a program. zjava.lang.Math contains a bunch of mathematics functions. Since we are only interested in particular methods (functions) in Math class, not entire copy (object) of it, it will be waste of space if multiple objects of Math type are created just to serve different objects. zDefined as static, a method can be directly called by other objects whether its enclosing object is created or not. zThe same is true for static fields. Famous examples are System.out, Math.PI, Color.yellow, etc. zStatic fields are global among the objects or the same type.

Object Handle and Pointer zThey say there’s no pointers in Java. However, object handles are essentially pointers. zRecall that objects are created in Garbage-collected Heap Area. By creating an object, we only get a handle that points to real object in the Heap. zBy passing an object handle, we simply pass the pointer. Not the object itself!!!

Object Handls class Game{... Card card = deck.draw(); player[0].getCard(card); … } class SimplePlayer extends Player { Card card[] = new Card[10]; … void getCard(Card card) { card[1] = card; } Array in CardDeck Array in SimplePlayer Card objects in heap object handle

Vector Class zMost frequently used Java Classes. zVector is a resizable array. You don’t have to worry about its capacity. It will resize itself. zHowever, Vector can not hold primitive data types. It only holds Objects. zI do not know why they call it as Vector. zGood example of generic handling and upcasting and downcasting.

Useful Intermediate Containers zPanel (JPanel) zScroll Pane (JScrollPane) zEditor Pane (JEditorPane) zSplit Pane (JSplitPane) zTool Bar (JToolBar) zTabbed Pane (JTabbedPane)

import java.awt.*; import java.awt.event.*; import javax.swing.*; class ScrollPaneDemo { ScrollPaneDemo() { JFrame frame = new JFrame("ScollPane"); frame.setSize(200,200); Container pane = frame.getContentPane(); pane.add(makeScrollPane()); frame.setVisible(true); } private Component makeScrollPane() { // Implementation comes in the next slide. } public static void main(String args[]) { new ScrollPaneDemo(); }

private Component makeScrollPane() { JPanel panel = new JPanel(); ImageIcon image = new ImageIcon("cab.gif"); panel.add(new JLabel(image)); JScrollPane scroll_pane = new JScrollPane(panel); return scroll_pane; }

class ToolBarDemo extends JFrame { ToolBarDemo() {... JToolBar toolBar = new JToolBar(); addButtons(toolBar);... Container pane = getContentPane(); pane.setLayout(new BorderLayout()); pane.add(toolBar, BorderLayout.NORTH); pane.add(scrollPane, BorderLayout.CENTER); } protected void addButtons(JToolBar toolBar) { // See the next slide!!! } public static void main(String args[]) { new ToolBarDemo(); }

protected void addButtons(JToolBar toolBar) { JButton button = null; //first button button = new JButton(new ImageIcon("images/left.gif"));... toolBar.add(button); //second button button = new JButton(new ImageIcon("images/middle.gif"));... toolBar.add(button); //third button button = new JButton(new ImageIcon("images/right.gif"));... toolBar.add(button); }