MVC and Swing IAT 351 Week 7 Lecture/tutorial 22.02.2008 Lyn Bartram.

Slides:



Advertisements
Similar presentations
Working with Tables for Page Design – Lesson 41 Working with Tables for Page Design Lesson 4.
Advertisements

Copyright  Oracle Corporation, All rights reserved. 3 JavaBeans: Reusing Application Components.
Advanced Swing. Advanced Layout Managers GridBagLayout – Example: Web Browser (Grid Bag Layout)Web Browser (Grid Bag Layout) BoxLayout – Example: Web.
Access Lesson 2 Creating a Database
COSC 3461: Module 8 Model-View-Controller (MVC) Architecture.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 36 JTable and JTree.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Automating Tasks With Macros
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.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Introduction To Form Builder
Object-Oriented Analysis and Design
Laboratory Exercise # 13 – Font and Number Format Styles Office Productivity Tools 1 Laboratory Exercise # 13 Font and Number Format Styles Objectives:
Access Lesson 2 Creating a Database
Unit J: Creating a Database Microsoft Office Illustrated Fundamentals.
6 Copyright © 2004, Oracle. All rights reserved. Working with Data Blocks and Frames.
Building a UI with Zen Pat McGibbon –Sales Engineer.
1 Lesson 22 Getting Started with Access Essentials Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
Lesson No:9 MS-Word Tools, Mail Merge and working with Tables CHBT-01 Basic Micro process & Computer Operation.
Chapter 8: Writing Graphical User Interfaces
IE 423 – Design of Decision Support Systems Data modeling and database development.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 38 Advanced Java Database.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Key Applications Module Lesson 21 — Access Essentials
Tables CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Java Swing. Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT. In addition to the familiar.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 24 Advanced Swing.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Pertemuan ke 4 JTable.  Swing uses the model-view-controller architecture (MVC) as the fundamental design behind each of its components  Model The model.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 33 Advanced Java.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 15 Advanced Tables.
3461 Model-View Controller Advanced GUI concepts.
Microsoft Access 2013 ®® Tutorial 10 Automating Tasks with Macros.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
XP Chapter 2 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Building The Database Chapter 2 “It is only the farmer.
1/62 Introduction to and Using MS Access Database Management and Analysis Yunho Song.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 35 MVC and Swing MVC.
CHAPTER:08 JAVA IDE PROGRAMMING-III Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 31 JTable and JTree.
Swinging in Your Java Playground. Background Swing is a part of the Java Foundation Classes (JFC). The JFC is made up of features intended to give a programmer.
Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.
Key Applications Module Lesson 14 — Working with Tables Computer Literacy BASICS.
1 Chapter 24 Advanced Swing Components. 2 Objectives · To understand the Swing model-view-controller architecture (§24.2). · To use JSpinner to scroll.
Creating User Interfaces Chapter 13 CSCI CSCI 1302 – Creating User Interfaces2 Outline Introduction Common Features of Swing GUI Components Buttons.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Copyright © Curt Hill More Widgets In Abstract Window Toolbox.
CPSC 203 Introduction to Computers T97 By Jie (Jeff) Gao.
WaveMaker Visual AJAX Studio 4.0 Training Java Script Events.
MSOffice Access Microsoft® Office 2010: Illustrated Introductory 1 Part 1 ® Database & Table.
Positioning Objects with CSS and Tables
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 6 1 Microsoft Office Access 2003 Tutorial 6 – Creating Custom Forms.
1 Organizing Information in Tables A table is information arranged in horizontal rows and vertical columns When you first insert a table into a document,
Notes for Assignment #2 Assn2: GUI Database Interface Corresponds with Chapters 28, 29, 31.
CompSci 230 S Software Construction
CompSci 280 S Introduction to Software Development
Working with Data Blocks and Frames
The practice of JTable in swing
Lecture 27 Creating Custom GUIs
CompSci 280 S Introduction to Software Development
Advanced Swing Tables.
DB Implementation: MS Access Forms
DB Implementation: MS Access Forms
Lesson 23 Getting Started with Access Essentials
Unit J: Creating a Database
Key Applications Module Lesson 14 — Working with Tables
Assignment resource Working with Excel Tables, PivotTables, and Pivot Charts Fairhurst pp The commands on these slides work with the Week 2 Excel.
Tutorial Introduction to help.ebsco.com.
Presentation transcript:

MVC and Swing IAT 351 Week 7 Lecture/tutorial Lyn Bartram

MVC and Swing | IAT351 | Assignment 3 Goal: implement different interaction techniques for the same interactive tasks in 2 different contexts  Regular desktop  Small mobile device Use model-view-controller architecture Have some FUN designing the interactions Due next week

MVC and Swing | IAT351 | The Model-View-Controller Architecture Model Controller View The view determines which events are passed to the controller The controller updates the model based on the events received The model passes its data to the view for rendering Model Controller View ComponentUI-Delegate With Swing, the view and the controller are combined into a UI-Delegate object

MVC and Swing | IAT351 | Tables Tables are used to display data in a spreadsheet fashion The JTable is oriented toward displaying database records in which each row displays a row in the database, and each column displays a different record’s values for the same field So key concepts in the model of a table:  Cell  Row, column  Value(s) in each

MVC and Swing | IAT351 | Class JTable JTable component presents data in a 2D table format The JTable has many features that make it possible to customize its rendering and editing but provides defaults for these features. A JTable consists of:  Rows of data  Columns of data  Column headers  An editor, if you want cells to be editable

MVC and Swing | IAT351 | Class JTable A JTable consists of:  A TableModel, usually a subclass of AbstractTableModel, which stores the table’s data  A TableColumnModel, usually DefaultTableColumnModel, which controls the behavior of the table’s columns and gives access to the TableColumn s  A ListSelectionModel, usually DefaultListSelectionModel, which keeps track of the JTable ’s currently selected row(s)  A TableCellRenderer, usually an instance of DefaultCellRenderer  Multiple TableColumn s, which store graphical information about each column  A JTableHeader which displays column headers

MVC and Swing | IAT351 | Class JTable Steps in creating and using JTable 1. Create a JTable (there are 7 different constructors) 2. Create a JScrollPane that can be used to scroll around the JTable via createScrollPaneForTable() 3. Place the JTable within a container 4. Control whether grid lines should be drawn via setShowGrid() 5. Specify a default value for a cell via setValueAt() 6. Get the value for a cell via getValueAt() 7. Make individual cells selectable via setCellSelectionEnabled() 8. Find out which cells are selected via the JTable ’s ListSelectionModel and the TableColumnModel ’s ListSelectionModel 9. Add new rows and columns via the JTable ’s TableModel

MVC and Swing | IAT351 | Class AbstractTableModel AbstractTableModel is an abstract class that implements most of the TableModel interface The TableModel methods that are not implemented are getRowCount(), getColumnCount(), and getValueAt() Steps in creating and using AbstractTableModel  Create an AbstractTableModel subclass  Implement the getRowCount(), getColumnCount(), and getValueAt() methods  Instantiate an instance of the subclass  Create a JTable using the subclass via new JTable( model )

MVC and Swing | IAT351 | Class AbstractTableModel To set up a table with 10 rows and 10 columns of numbers: TableModel dataModel = new AbstractTableModel() { public int getColumnCount() { return 10; } public int getRowCount() { return 10;} public Object getValueAt(int row, int col) { return new Integer(row*col); } }; JTable table = new JTable(dataModel); JScrollPane scrollpane = new JScrollPane(table);

MVC and Swing | IAT351 | Class DefaultTableModel DefaultTableModel is the JFC’s default subclass of the abstract AbstractTableModel class If a JTable is created and no TableModel is specified, the JTable creates an instance of DefaultJTableModel and uses it to hold the table’s data If you have complex data, you may prefer to extend the AbstractTableModel yourself Steps in creating and using DefaultTableModel  Create a DefaultTableModel (there are 6 different constructors) DefaultTableModel( Vector data, Vector columnIDs)  Create a JTable using the DefaultTableModel via new JTable(model)

MVC and Swing | IAT351 | Class DefaultTableModel Steps in creating and using DefaultTableModel  Define a TableModelListener to receive TableModelEvent s when the model changes, or when one or more cell’s contents change  Add a row to the DefaultTableModel via addRow()  Add a column to the DefaultTableModel via addColumn()  Get the current value of a cell in a DefaultTableModel via getValueAt()  Move one or more rows via moveRow()  Load a new set of data into a DefaultTableModel via setDataVector()  Get the number of rows or columns in a DefaultTableModel via getRowCount() and getColumnCount()

MVC and Swing | IAT351 | Class TableColumn A TableColumn contains the graphical attributes for a single column of data in a JTable ’s model It stores information about the column header, the column height and width, and how cells in the column should be drawn and edited Steps in creating and using TableColumn  TableColumn s are created automatically when columns are added to the table model. They are accessed via the table column model via getColumn()  Specify the TableCellEditor to use when editing the TableColumn ’s cells JCheckBox cbox = new JCheckBox() DefaultCellEditor editor = new DefaultCellEditor(cbox) tableColumn.setCellEditor(editor)  Change the column header via setHeaderValue()

MVC and Swing | IAT351 | Class DefaultTableColumnModel DefaultTableColumnModel is the JFC’s default implementation of the TableColumnModel interface This class is used to keep track of information about table columns. It gives access to TableColumn s and keeps track of general characteristics of columns, like column margins and widths. It also contains a ListSelectionModel that it uses to keep track of which columns are currently selected Steps in creating and using DefaultTableColumnModel  You will usually let the JTable create it  Specify the selection mode for the DefaultTableColumnModel via setSelectionMode()

MVC and Swing | IAT351 | Class DefaultTableColumnModel Steps in creating and using DefaultTableColumnModel  Define a ColumnModelListener to receive TableColumnModelEvent s when a column is added, removed, moved, margins are changed, or the column selection state changes  Get the currently selected columns via getSelectedColumns()

MVC and Swing | IAT351 | Class JTableHeader A JTableHeader is a companion to JTable and contains the graphical representation of the table’s column headers A JTableHeader does not display by default but will display if you place a JTable into a JScrollPane created using the createScrollPaneForTable() method A JTableHeader draws itself using information from the TableColumnModel associated with the JTable Steps in creating and using JTableHeader  You will usually let the JTable create it  Change the TableCellRenderer used to draw a column’s header via setHeaderRenderer()  Enable/Disable column reordering via setReorderingAllowed()

MVC and Swing | IAT351 | Class DefaultCellEditor DefaultCellEditor is an editor that can be used with a JTable or a JTree to edit table cells and tree nodes It can edit in one of three ways: as a text field, as a check box, or as a combo box Steps in creating and using a DefaultCellEditor  Create a component to be used by the DefaultCellEditor and set its properties  Create a DefaultCellEditor using the component you just created  Specify how many mouse clicks it takes to start the editor via setClickCountToStart() (default is 2)  Define a CellEditorListener to receive ChangeEvent s when a cell editing session ends

MVC and Swing | IAT351 | JTable TableModel interface methods and descriptions.

MVC and Swing | IAT351 | JTable TableModel interface methods and descriptions.

MVC and Swing | IAT351 | ? Java Documentation Look at Jtable How to use tables in Swing