CSSE221: Software Dev. Honors Day 8

skatechildrenSoftware and s/w Development

Nov 3, 2013 (3 years and 7 months ago)

66 views

CSSE221: Software Dev. Honors


Day 8


Announcements



HW3 due now, solutions will be posted.


Questions on Arrays?


Max # of elements in an array:


Integer.MAX_INT, but your machine probably doesn’t have enough
space to hold this much data! And the JVM will certainly not claim all
your memory even if you did.


Newer machines (with 64
-
bit addressing) will have more… but I
don’t know how Java is responding (perhaps Java 7 will have long int
array indices)


Today is Constitution Day.


Speaker in Kahn Room in Union, 10
th

hour.


No baby yet…

Capsule Deliverables: sec 1


Please email the quiz, key, and summary to me by 7:30
am on the day you are presenting.


Send .doc files


(If you get them to me by 3pm on a weekday before
you present, I’ll still print them)


Lessons from week 1:


Nice research and summarization!


Proofread your stuff. Everyone else will see it.


1
-
page quizzes are good (or staple)


Summaries don’t have to be verbose, just dense with info.



This week: Fifteen assignment


Monday:


Fifteen specification


GUIs using Java’s Swing library


Intro to UML as a
design

tool


Start Fifteen


Tuesday:


EventListeners: responding to user input


Time to work on project


Thursday:


Anonymous classes (capsule)


Function objects and comparators (capsule)

“Fifteen”

Arrays (especially 2D)

Creating GUIs using Swing

Responding to mouse clicks

Fifteem Teams


beltonj1
-
fishmad


bennetrn
-
leveyjr


bennindp
-
speyerea


crockeea
-
morrisps


devorejd
-
priestjs


lundgrpb
-
skilessa


johnsoad
-
smithny


sullivja
-
wentztj


mcginnda

behlinmc
-
bennetdj

clutecc
-
dovalojd

gatesds

heinma1
-
hulettbh

johnsoac
-
rubinza

kruthar
-
richarme

millerbe
-
eckertwm

mosttw
-
reillytm

nibertjw
-
stokesej

Repos is csse221
-
200810
-
<usr1>
-
<usr2>. If solo, use your personal repos.

Discuss how to pair
-
program

Fundamentals of Software
Development 1

6

The Java Swing Library


JFrames, JTextBoxes, JButtons, JScrollPanes…
what’s available?



What components will I need…


…now, for Fifteen?


…later, for a term project?



Browse the
Visual Index to the Swing Components
in
Sun’s
Java Tutorial
.

JFrame


A simple window that contains the other GUI
components


Background Color


getContentPane().setBackground(Color);


Make sure to set visible


setVisible(true);


Setting the size


setSize(width, height);

Benefits of Extending JFrame or
JComponents like JPanel


When extending the JFrame class we can still
instantiate it as JFrame.


“Controlling” the JFrame is easier to
comprehend when we do not need the calling
object stated every time.

i.e. setSize(w,h); instead of

jFrameObject.setSize(w,h);


JLabel


Displays text to user


User cannot edit text


Construction: JLabel message = new
JLabel(String text);

Methods:


String text = message.getText();


message.setText(String text);

JTextField


Lets user enter or modify a single line of text


Construction:


JTextField text = new JTextField(int
WidthInCharacters);


Getting the Text:


String input = text.getText();


Setting text in a Text Field:


text.setText(String output);

JTextArea


Lets user enter or modify multiple lines of text.


Declaration: private JTextArea text;


Constructors:


text = new JTextArea(int rows, int columns);


text = new JTextArea(String output);


text = new JTextArea(String output, int rows, int columns);



Useful methods:


String input = text.getText();


text.setText(String output);


setEditable(Boolean editable);


boolean editable = text.isEditable();

JButton


Used to let user execute action


Construction: JButton button = new
JButton(String text);


button.setBackground(Color color);

JPanel


Simple container that groups objects


Meant to subdivide


Creation Syntax:


JPanel panelName = new JPanel();


Useful attributes and methods


.setLayout(new Layout());


.add(component);


.setBackground(Color color);

Layout Managers


Frames are organized by layout managers.


Organizes the locations of the components
within the frame


Not only frames use layout managers, but Panels
are also organized by layout managers.


Allows for panels within panels.

Layout: Flow Layout


Places the components from the left side to the
right side.


Wraps around the right side.


.setLayout(new FlowLayout());


No special add syntax.

Layout: Border Layout


North, South, East, West, Center


setLayout(new BorderLayout());


.add(component, BorderLayout.NORTH);

Layout: Grid Layout


Similar to flow in the left to right manner, but the grid
that you define limits the size of any one component


You can leave out a definite definition of how many
rows or columns are in the grid.


setLayout(new GridLayout(r,c));


Adds in components from left to right, top to bottom.
Cannot specify which block.

PaintComponent


Used with JPanels, and all JComponents, to
paint the components on the screen.


Called automatically, no need to invoke it.


Use repaint(); to force the paintComponent()
method to execute.


Start with super.paintComponent(g); where g is
your Graphics object


public

void

paintComponent(Graphics g) {


super
.paintComponent(g);


setBackgroundColor(Color.red);


g.drawOval(10,40,20,20);

}

Alternative designs


I want a component to appear. Question:


Should I paint it?

Add a new component?





Answer: It depends…


On how much control you want over its appearance


On how you want it to respond to events



It’s usually a tradeoff.

Press me!

Listeners


If you want to respond to events, you need to implement a
Listener interface.


We’ll look at these in detail tomorrow

Demo together