J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are.

Slides:



Advertisements
Similar presentations
G5BUID - Java Swing Laying out components Manage realized components Determine size and position Each container has a layout manager (usually)
Advertisements

Introduction to Swing Components Chapter 14. Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java program.
Unit 121 A layout manager is an object that determines the manner in which components are arranged in a container. Each layout manager implements one of.
Graphical User Interfaces
TCU CoSc Programming with Java Visual Design (Chapter 5)
Graphic User Interfaces Layout Managers Event Handling.
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.
Corresponds with Chapter 12
LayoutManager, J 1 Layout Manager. LayoutManager, J 2 Layout Manager To each UI container there is a layout manager (an object). When you add a component.
GUI programming AWT(Abstract Windows Toolkit)-GUI components library when Java was introduced AWT was replaced by Swing components import javax.swing.*;
Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other.
Inheritance Review CSC 171 FALL 2004 LECTURE 19. READING Read Horstmann, Chapter 11 Look at Chapter 12 – Will not be on MT or Final – One lab Begin Reading.
LAB SESSION 10 *LAYOUT MANAGER *LISTENERS. Laying the components manually by using a null layout is tedious. Each container object has a layout manager.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
Jan Containers Yangjun Chen Dept. Business Computing University of Winnipeg.
GUI Layout Managers Arkadiusz Edward Komenda. Outline Components and Containers Layout Managers Flow Layout Grid Layout Border Layout Nested Containers.
GUI and event-driven programming An introduction.
CS3 - AWT/Swing1 The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness –The Abstract.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Layout Management Containers can arrange their components. Our container is a JPanel, and it can set the way it’s components will be laid out : mypanel.setLayout.
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.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.
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.
Chapter 8: Getting Started with Graphics Programming Graphics Class Hierarchy Graphics Class Hierarchy Frames Frames The relationship between frame and.
1 Why layout managers Can we perform layout without them? –Yes. A container’s layout property can be set to null. Absolute positioning: specify size and.
Field Trip #19 Animations with Java By Keith Lynn.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Laying Out Components Interior Design for GUIs. Nov 042 What is Widget Layout? Positioning widgets in their container (typically a JPanel or a JFrame’s.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Layout Managers Arranges and lays out the GUI components on a container.
Layout Manager Summary
© Marty Hall, Larry Brown, Web core programming 1 Layout Managers Arranging Elements in Windows.
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 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.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
Object-Oriented Software Engineering
3461 Laying Out Components Interior Design for GUIs.
GUI Basics. Agenda What GUI How to make in java Creating frames Frequently used GUI components Layout Managers.
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.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
CSI 3125, Preliminaries, page 1 Layout Managers. CSI 3125, Preliminaries, page 2 Layout Managers The LayoutManagers are used to arrange components in.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
Java Swing - Lecture 3 Layout Management
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Event Handler Methods Text field Object Responder JAVA AWT Environment: Messages are sent between JAVA Objects Screen Event Notification Press Button.
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Dept. of CSIE, National University of Tainan 10/21/2012 Arranging Components on a User Interface.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Unit 131 GUI Layout Managers Learning Outcomes oList and distinguish between the four most common, standard layout managers in Java. oUse these and other.
Chapter 7 A First Look at GUI Applications Layout Managers.
Graphical User Interfaces
Graphical User Interfaces -- GUIs
Swing JComponents.
Modern Programming Language Java
Chapter 13: Advanced GUIs and Graphics
Containers and Components
Tim McKenna Layout Mangers in Java Tim McKenna
Creating Graphical User Interfaces
Panels & Layout Managers
LayoutManagers The LayoutManagers are used to arrange components in a particular manner. LayoutManager is an interface that is implemented by all the classes.
Layout Organization and Management
Graphical User Interface
Presentation transcript:

J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are interested in. It now looks and behaves like we want. This subclass has all the properties of its superclass along with the extra’s we’ve added. We can now re-use this component! can create multiple instances of it can subclass it

J McQuillanSE204:2004/2005: Lecture 3Slide 2 import java.awt.*; import javax.swing.*; class DaysPanel extends JPanel{ JComboBox days; JLabel l; DaysPanel(){ setPreferredSize(new Dimension(300, 200)); setBackground(Color.white); l = new JLabel("Choose a day"); days = new JComboBox(); days.addItem(“Monday"); days.addItem(“Tuesday"); add(l); add(days); }

J McQuillanSE204:2004/2005: Lecture 3Slide 3 We can now place this in a frame, in an applet, or any other higher-level container!

J McQuillanSE204:2004/2005: Lecture 3Slide 4 Other Component Methods setVisible(boolean b) can be called on any component it makes the component visible or invisible setEnable(boolean b) can be used to disable a component, it cannot receive user input most components when disabled change their appearance

J McQuillanSE204:2004/2005: Lecture 3Slide 5 Laying out components Can place components in containers by use of absolute position and size co- ordinates use of layout managers The arrangement of several components in a container is called a layout.

J McQuillanSE204:2004/2005: Lecture 3Slide 6 Laying out components There are a number of predefined layout classes FlowLayout BorderLayout GridLayout GridBagLayout CardLayout These all implement the LayoutManager interface

J McQuillanSE204:2004/2005: Lecture 3Slide 7 Using Layouts Set the layout of the container by invoking the setLayout() method. This method accepts as a parameter an instance of a class that implements the layout manager interface.

J McQuillanSE204:2004/2005: Lecture 3Slide 8 Border Layout This allows you to place components in five different regions in the container - North, South, East, West and Center. You specify the position of each component when adding it to the container.

J McQuillanSE204:2004/2005: Lecture 3Slide 9 Border Layout Constructors BorderLayout() -- creates a new border layout BorderLayout(int hGap, int vGap) -- creates a new border layout with the specified horizontal and vertical gaps

J McQuillanSE204:2004/2005: Lecture 3Slide 10 import java.awt.*; import javax.swing.*; Public class borderPanel extends JPanel{ JButton[] b; borderPanel(){ setPreferredSize(new Dimension(300, 200)); setBackground(Color.white); setLayout(new BorderLayout()); b = new JButton[5]; for(int i=1; i<=b.length; i++) b[i-1] = new JButton("Button "+i); add("North", b[0]); add("East", b[1]); add("South", b[2]); add("West", b[3]); add("Center", b[4]);} }

J McQuillanSE204:2004/2005: Lecture 3Slide 11 public class borderFrame extends JFrame { private borderPanel p1; borderFrame(){ super("Border Frame"); p1 = new borderPanel(); getContentPane().add(p1); pack(); setVisible(true); } public static void main(String args[]){ new borderFrame(); }

J McQuillanSE204:2004/2005: Lecture 3Slide 12 Flow Layout This allows any number of components in a container. It arranges the components from left to right in a row. When that row is full, it will begin a new row.

J McQuillanSE204:2004/2005: Lecture 3Slide 13 Flow Layout Constructors FlowLayout() -- creates a new flow layout with centered alignment. FlowLayout(int alignment) -- creates a new flow layout with the specified alignment. FlowLayout(int alignment, int hGap, int vGap) --creates a new flow layout with the specified alignment and horizontal and vertival gaps.

J McQuillanSE204:2004/2005: Lecture 3Slide 14 import java.awt.*; import javax.swing.*; class flowPanel extends JPanel{ JButton[] b; int n; flowPanel(int n){ this.n = n; setPreferredSize(new Dimension(300, 200)); setBackground(Color.white); setLayout(new FlowLayout()); b = new JButton[n]; for(int i=1; i<=b.length; i++){ b[i-1] = new JButton("Button "+i); add(b[i-1]); }

J McQuillanSE204:2004/2005: Lecture 3Slide 15 public class flowFrame extends JFrame { private flowPanel p1; flowFrame(){ super("Flow Frame"); p1 = new flowPanel(5); getContentPane().add(p1); pack(); setVisible(true); } public static void main(String args[]){ new flowFrame(); }

J McQuillanSE204:2004/2005: Lecture 3Slide 16 Grid Layout This allows you to lay out components in a grid of rows and columns.

J McQuillanSE204:2004/2005: Lecture 3Slide 17 Grid Layout Constructors GridLayout(int rows, int cols) -- creates a new grid layout with the specified number of rows and columns GridLayout(int rows, int cols, int hGap, int vGap) -- creates a new grid layout with the specified number of rows and columns and specified horizontal and vertical gaps

J McQuillanSE204:2004/2005: Lecture 3Slide 18 import java.awt.*; import javax.swing.*; class gridPanel extends JPanel{ JButton[] b; int n; gridPanel(int n){ this.n = n; setPreferredSize(new Dimension(300, 200)); setBackground(Color.white); setLayout(new GridLayout(3,2)); b = new JButton[n]; for(int i=1; i<=b.length; i++){ b[i-1] = new JButton("Button "+i); add(b[i-1]); }

J McQuillanSE204:2004/2005: Lecture 3Slide 19 public class gridFrame extends JFrame { private gridPanel p1; gridFrame(){ super("Grid Frame"); p1 = new gridPanel(5); getContentPane().add(p1); pack(); setVisible(true); } public static void main(String args[]){ new gridFrame(); }

J McQuillanSE204:2004/2005: Lecture 3Slide 20 Other Layouts There are other layouts available These include CardLayout, BoxLayout