Java by Example

advertisement
Java by Example
Introducing IDE, Eliza, UI, IO and
other creatures
234321 Java by
Example
Created by Ron Begleiter
1
Developer Needs
Why not use
command-line and
notepad?
234321 Java by
Example
2
integrated development
environment
integrated development environment (IDE)
is an application or set of tools that allows
a programmer to write, compile, edit, and
in some cases test and debug within an
integrated, interactive environment.
234321 Java by
Example
3
Borland’s JBuilder
• Availability: Free (Foundation version)
• Functionality: integrated editor,
debugger, compiler, visual designers,
wizards, refactorings, code formatting, and
much more.
• Supported OS: Windows, Linux, Unix and
Mac
• Other Java IDEs: Eclipse, IntelliJ
234321 Java by
Example
4
JBuilder’s Hands-on
234321 Java by
Example
5
Java toy example - Eliza
Who is Eliza?
Eliza was “born” in the early 1960s in MIT’s
labs. It is viewed as the first intelligent
machine. Its creator is Prof. Joseph
Weizenbaum.
‫המשורר דויד אבידן נסע בשנות השבעים למעבדות‬
‫ שיחות אלו‬.‫ בארה"ב לשוחח עם אליזה‬IBM
:‫פורסמו בספרו בשם ''הפסיכיאטר האלקטרוני שלי‬
.'' ‫שמונה שיחות אותנטיות עם מחשב‬
234321 Java by
Example
6
What’s next?
• We will browse through a few of Java’s
basic capabilities and demonstrate how
we used them in the toy example;
• We will focus on the collection framework,
In\Out processing and User Interfacing
(UI).
• Finally, we will raise a few questions.
234321 Java by
Example
7
Java Collection Framework
Interfaces:
234321 Java by
Example
8
Java Collection Framework
Implementations:
234321 Java by
Example
9
Collections in Eliza
234321 Java by
Example
10
Java IO
Character Streams - Reader
234321 Java by
Example
11
Java IO
Character Streams - Writer
PrintWriter
234321 Java by
Example
12
Java IO
Byte Streams - Input
234321 Java by
Example
13
Java IO
Byte Streams - Output
234321 Java by
Example
14
Java IO in Eliza
234321 Java by
Example
15
Java UI - swings
234321 Java by
Example
16
Swing (continued)
234321 Java by
Example
17
Swing (continued)
234321 Java by
Example
18
Swing (continued)
234321 Java by
Example
19
Swing (continued)
234321 Java by
Example
20
Swing (continued)
234321 Java by
Example
21
Event Listener
Some Events and Their Associated Event Listeners
Act that Results in the Event
Listener Type
User clicks a button, presses Enter while typing
ActionListener
in a text field, or chooses a menu item
User closes a frame (main window)
WindowListener
User presses a mouse button while the cursor is
MouseListener
over a component
234321 Java by
Example
User moves the mouse over a component
MouseMotionListener
Component becomes visible
ComponentListener
Component gets the keyboard focus
FocusListener
Table or list selection changes
ListSelectionListener
Any property in a component changes such as
the text on a label
PropertyChangeListener
22
The MVC pattern
Meet Little
SmallTalk
in OOP
Swing architecture is rooted in the model-viewcontroller design that dates back to SmallTalk.
MVC architecture calls for a visual application to
be broken up into three separate parts:
– A Model that represents the data
for the application.
– The view that is a visualization of
that data
– The controller that manipulates the view and
updates the model
234321 Java by
Example
23
UI in Eliza
JPanel
JTextArea
JScrollPane
JLabel
JTextField
234321 Java by
Example
24
UI in Eliza (code 1/3)
234321 Java by
Example
25
UI in Eliza (code 2/3)
234321 Java by
Example
26
UI in Eliza (code 3/3)
234321 Java by
Example
27
MVC in Eliza
<<ElizaModelInterface>>
ElizaUI
implements
ElizaModel
234321 Java by
Example
Where is the controller?
Why use an interface?
28
Questions
234321 Java by
Example
29
Questions (continued)
234321 Java by
Example
30
Links
• Java tutorial –
http://java.sun.com/docs/books/tutorial/
• Swing Trail http://java.sun.com/docs/books/tutorial/uiswing/index.html
• Collections Trail http://java.sun.com/docs/books/tutorial/collections/index.html
• Java 1.5 ‘Tiger’ http://java.sun.com/developer/technicalArticles/Interviews/hamilton_qa.html
234321 Java by
Example
31
Eliza – sample conversation
Hi there
Greetings from inside the box.
what shall we talk about
Does that question interest you?
yes
Are you sure?
yes I am
Do you enjoy being ?
again yes
You seem quite positive.
yes
Please elaborate
I want to know what you would like to hear
So what's stop you?
you
We were discussing you -- not me.
damn right
Say, do you have any psychological problems?
yes
You seem quite positive.
yes
Why do you think so?
because i find myself talking with computers
Doesn't any other reasons come to mind?
nope
Can you elaborate on that?
I am spending my days in the Technion in the computers lab
Do you enjoy being spending my days in the technion in the computers lab ?
no!
Say again.
no
Are you sure?
yes
Are you sure?
yes
Please elaborate
234321 Java by
Example
32
Download