CS 424524: Introduction to Java Programming - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

CS 424524: Introduction to Java Programming

Description:

Elicit requirements from Human Relations Department. Want to send invitations to picnic ... Need to plan games. Want to give 'Years of Service' awards. Simple ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 15
Provided by: dyes
Category:

less

Transcript and Presenter's Notes

Title: CS 424524: Introduction to Java Programming


1
CS 424/524 Introduction to Java Programming
  • Lecture 24
  • Spring 2002
  • Department of Computer Science
  • University of Alabama
  • Joel Jones

2
Overview
  • Questions
  • Handout MP
  • Review GUI Development
  • Developing Swing Applications
  • Exercise for next time
  • Reading for next time

3
Review Steps in Designing a GUI Application
  • Iteratively
  • Analyze the problem
  • Design the model
  • Design the graphical layout
  • Write unit test for model
  • Write unit test for GUI
  • Write code for model
  • Write code for GUI

Pair Up Why would you choose command-line?
text-file? GUI?
4
Simple HR Database
  • Analyze the Problem
  • Elicit requirements from Human Relations
    Department
  • Want to send invitations to picnic
  • Need to know how many veggie pizzas to order
  • Need to plan games
  • Want to give Years of Service awards

5
Simple HR Database (cont.)
  • Analyze the Problem (cont.)
  • Turn into simple data items
  • first name
  • last name
  • sport
  • of years
  • Vegetarian?
  • Design the model
  • simple 2-d array of Objects

6
Simple HR Database (cont.)
  • Design the GUI

7
Simple HR Database (cont.)
  • Write unit test for model
  • Our model (2-d array of Objects) has no behavior
  • Therefore, no unit test or code to implement
  • Write unit test for GUI
  • Ignore for expediency
  • Write code for GUI
  • Use JTable
  • But how does JTable work?

8
Using JTable
  • See code printout (SimpleTableLayout)
  • Simplest JTable constructor uses
  • 2-d array of objects as model
  • String array of column names
  • This constructor is easy to use, but
  • Everything is editable
  • All data types treated the same
  • Stupid Inappropriate model

9
Using JTable (cont.)
  • The appearance of columns can be controlled
  • TableColumn column getColumnModel().getColumn(i)
  • column.setPreferredWidth(100)
  • setAutoResizeMode()

10
Using JTable (cont.)
  • Model for JTable must subclass AbstractTableModel
    abstract class
  • But this isnt hard, the default one is code like
    that found in handout

11
Using JTable (cont.)
  • Lets change behavior
  • Dont let user edit first or last names
  • Use check boxes for Vegetarian? column
  • See TableDemo code in handout
  • What if model can change not through the view
    (JTable)?
  • firefoo methods of AbstractTableModel

12
Using JTable (cont.)
  • What is going on with the checkbox?
  • Default Cell Editor and Renderer
  • The defaults are
  • Boolean check box
  • Number right-aligned box
  • ImageIcon centered label
  • Object label that displays objects string
    value
  • How do use my own Cell Editor?
  • table.setDefaultEditor(Class, DefaultCellEditor)

13
MP2 Demo
14
Further Reading
  • Java Tutorial on JTable
  • http//java.sun.com/docs/books/tutorial/uiswing/co
    mponents/table.html
Write a Comment
User Comments (0)
About PowerShow.com