Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 14 : Swing II King Fahd University of Petroleum & Minerals College of Computer Science.

Slides:



Advertisements
Similar presentations
Java Software Development Paradigm Lecture # 12. Basics of GUI.
Advertisements

Corresponds with Chapter 12
CS221 © 2007 Ray S. Babcock Layout, Components, & Data Entry Appendix C.3-C.5.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 20, 2005.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
LAB SESSION 10 *LAYOUT MANAGER *LISTENERS. Laying the components manually by using a null layout is tedious. Each container object has a layout manager.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
Chapter 121 Window Interfaces Using Swing Chapter 12.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 16 : Swing VI Graphics King Fahd University of Petroleum & Minerals College of Computer.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
CS102--Object Oriented Programming Lecture 18: – The Swing Package Copyright © 2008 Xiaoyan Li.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Layout Mangers CSC 171 FALL 2001 LECTURE 14. History: The Transistor William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance.
CPSC150 JavaLynn Lambert CPSC150 Week 12 InheritanceInterfaces.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
Java Swing. Introduction to Swing A GUI (graphical user interface) is a windowing system that interacts with the user The Java AWT (Abstract Window Toolkit)
Advanced Java and Android Programming Day 1: Introduction to GUI Programming Intro to GUI Programming1.
Java Programming Chapter 10 Graphical User Interfaces.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Programming With Java ICS201 University Of Ha’il1 Chapter 17 Graphical User Interfaces Swing I.
CSE 219 Computer Science III Graphical User Interface.
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 13 : Swing I King Fahd University of Petroleum & Minerals College of Computer Science.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
Comp 249 Programming Methodology Chapter 17 Swing I Prof. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal,
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
University of Limerick1 Software Architecture Java Layout Managers.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
Csc Basic Graphical User Interface (GUI) Components.
Computer Science 209 GUIs Model/View/Controller Layouts.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Lab 4: GUIs, Panels, Mouse and Key Listeners ICOM4015: FALL 2014 A N I NTRODUCTION TO P ANELS AND L AYOUTS CREATED BY KATYA I. BORGOS REVISED BY AMIR H.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Project Proposals: Due Today!Project Proposals: Due Today! –Identify.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
CSI 3125, Preliminaries, page 1 Layout Managers. CSI 3125, Preliminaries, page 2 Layout Managers The LayoutManagers are used to arrange components in.
Java Layouts CSIS 3701: Advanced Object Oriented Programming.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 7 : Interfaces King Fahd University of Petroleum & Minerals College of Computer.
Dept. of CSIE, National University of Tainan 10/21/2012 Arranging Components on a User Interface.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 17 : Applets King Fahd University of Petroleum & Minerals College of Computer Science.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
Chapter 7 A First Look at GUI Applications Layout Managers.
Chapter 17 Swing I Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Layout Managers Layout Manager—an object that decides how components will be arranged in a container Some types of layout managers: BorderLayout FlowLayout.
Swing JComponents.
Modern Programming Language Java
Graphical User Interface (GUI) Programming III
Chapter 17 Swing I Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage Copyright © 2016 Pearson Inc. All.
Tim McKenna Layout Mangers in Java Tim McKenna
Creating Graphical User Interfaces
GUI building with the AWT
Comp 249 Programming Methodology
Zhen Jiang West Chester University
GUI building with the AWT
Graphical User Interface
Presentation transcript:

Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 14 : Swing II King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department

Swing I: (2/4) Reading: Pages 934 – 952 Outline A Better Version of Our First Swing GUI Labels Colors Layout Managers: Border, Flow & Grid

The Normal Way to Define a JFrame

A Better Version of Our First Swing GUI A better version of FirstWindow makes it a derived class of the class JFrame This is the normal way to define a windowing interface The constructor in the new FirstWindow class starts by calling the constructor for the parent class using super(); This ensures that any initialization that is normally done for all objects of type JFrame will be done Almost all initialization for the window FirstWindow is placed in the constructor for the class Note that this time, an anonymous object is used as the action listener for the endButton

Old and New Versions Old New The normal way to define a JFrame

Labels A label is an object of the class JLabel Text can be added to a JFrame using a label The text for the label is given as an argument when the JLabel is created The label can then be added to a JFrame JLabel greeting = new JLabel("Hello"); add(greeting);

Color In Java, a color is an object of the class Color The class Color is found in the java.awt package There are constants in the Color class that represent a number of basic colors A JFrame can not be colored directly Instead, a program must color something called the content pane of the JFrame Since the content pane is the "inside" of a JFrame, coloring the content pane has the effect of coloring the inside of the JFrame Therefore, the background color of a JFrame can be set using the following code: getContentPane().setBackground(Color);

The Color Constants

DemoColoredWindow.java ColoredWindow.java A JFrame with Color

Containers and Layout Managers Multiple components can be added to the content pane of a JFrame using the add method However, the add method does not specify how these components are to be arranged To describe how multiple components are to be arranged, a layout manager is used There are a number of layout manager classes such as BorderLayout, FlowLayout, and GridLayout If a layout manager is not specified, a default layout manager is used

Border Layout Managers A BorderLayout manager places the components that are added to a JFrame object into five regions These regions are: BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST, BorderLayout.WEST, and BorderLayout.Center A BorderLayout manager is added to a JFrame using the setLayout method For example: setLayout(new BorderLayout());

Border Layout Manager (Example)

Border Layout Managers The previous diagram shows the arrangement of the five border layout regions Note: None of the lines in the diagram are normally visible When using a BorderLayout manager, the location of the component being added is given as a second argument to the add method add(label1, BorderLayout.NORTH); Components can be added in any order since their location is specified

Flow Layout Managers The FlowLayout manager is the simplest layout manager setLayout(new FlowLayout()); It arranges components one after the other, going from left to right Components are arranged in the order in which they are added Since a location is not specified, the add method has only one argument when using the FlowLayoutManager add.(label1);

A GridLayout manager arranges components in a two-dimensional grid with some number of rows and columns setLayout(new GridLayout(rows, columns)); Each entry is the same size The two numbers given as arguments specify the number of rows and columns Each component is stretched so that it completely fills its grid position Note: None of the lines in the diagram are normally visible Grid Layout Managers

When using the GridLayout class, the method add has only one argument add(label1); Items are placed in the grid from left to right The top row is filled first, then the second, and so forth Grid positions may not be skipped Note the use of a main method in the GUI class itself in the following example This is often a convenient way of demonstrating a class

Grid Layout Managers

Some Layout Managers

The end