FrameEditorDemo - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

FrameEditorDemo

Description:

Java, Javac can find classes and directories stored in ZIP and JAR archives. ... Goal: Ability to open and close directories, and to view files and their properties. ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 29
Provided by: Techs
Category:

less

Transcript and Presenter's Notes

Title: FrameEditorDemo


1
Lecture 4
  • FrameEditorDemo
  • Packages
  • System Object
  • Runtime Object
  • File Systems

2

User
(JVM)
runs
Files
FrameEditorTester
creates
reads/writes
FrameEditor
GameFrame
creates
creates
quitButton
interacts with
User
3
Flow of ActionEvents
FrameEditorTester
?
FrameEditor
GameFrame
?
4
Effect of wrapper addActionListener methods
FrameEditorTester
initial calls to addActionListener()
FrameEditor
GameFrame
relayed calls to addActionListener()
5
Packages
  • Hierarchy of classes, independent of
    inheritance.
  • Packages group classes related by function.
  • A package is a namespace
  • protected/package access specifiers

6
Creating Packages
  • First line of each file is
    package packagename
  • To access a class import packagename.classna
    me
  • To access all classes from a package import
    packagename.
  • Each package has its own directory, named
    packagename.

7
Using Packages
  • By default, files are in the unnamed package.
    This is only ok for very small projects.
  • Can have hierarchies of packages. Ex
    com.company.region.package. This corresponds to
    the directory CLASSPATH/com/company/region/packag
    e. There are a few naming conventions.
  • Separate import statements for each package,
    even subpackages.

8
Example Package Layout
9
File Layout
ActionFrame.java
(unnamed)
frameeditor
FrameEditor.java
app
pres
trans
EditorFrame EditorPanel EditorMenuBar IconSelector
HelpFrame EditorToolbar
FileSaver EditUndoer
TargetHandler EditorPanelHandler EditorMenuHandler
10
Package code
frameeditor.FrameEditor
package frameeditor import ActionFrame import
frameeditor.pres. import frameeditor.app. impo
rt frameeditor.trans.
frameeditor.pres.EditorFrame
package frameeditor.pres import
ActionFrame import frameeditor.FrameEditor
frameeditor.trans.EditorMenuHandler
package frameeditor.trans import
ActionFrame import frameeditor.FrameEditor impor
t frameeditor.app. import frameeditor.pres.Edito
rMenuBar
11
Package Details
  • Matters where you compile from. Java and Javac
    look in 2 places for packages CLASSPATH, and
    the current directory.
  • Java, Javac can find classes and directories
    stored in ZIP and JAR archives.
  • May have to disambiguate names, e.g.
    javax.swing.Timer, java.util.Timer and
    com.thomasphayes.silly.Timer

12
File Systems
  • A standardized, high-level mechanism to allow a
    user or users to access organized data on a
    medium or media.
  • Usually a rooted tree at heart (Unix), sometimes
    a rooted forest (Win), may be a directed graph
    (both fake this).
  • Files, directories, paths.
  • Permissions, owners, locks.

13
Paths
  • Steps from one node to another.
  • May be absolute (starts at root), canonical
    (absolute, plus no redundancies or shortcuts), or
    relative (starts somewhere else).
  • . current, .. parent, / or \
    file-separator, or path-separator.
  • Root / in Unix. L\ in Win

14
Warning File systems
  • Notably, the pathnames for Win and Unix are
    different.
  • Windows C\home\hayest\fname
  • Unix /home/hayest/fname
  • File location conventions also differ.
  • JRE seems to support Unix symlinks but not
    Windows Shortcuts.

15
Solutions
  • java.io.File.separator
    Do not hard-code pathnames.
  • Environment variables. HOME, PATH, CLASSPATH,
    FRAMEEDITORSAVEPATH, etc. Your installer
    can easily set up more.
  • Make user locate files (JFileChooser)

16
Example Fixing filenames
  • images/starters/icon1.gif or
    images\\starters\\icon1.gif should be replaced
    by images file.separator starters
    file.separator icon1.gif
  • Avoid symbolic links and absolute paths.
  • e.g. images needs to be replaced by ..
    file.sep .. file.sep images file.sep
    starters in a number of the demos.

17
Environment variables
  • Can get a few of these with System.getProperties(
    )
  • Can get all from shell, but code will be highly
    system dependent. Runtime rt
    Runtime.getRuntime() Process proc
    rt.exec(set) //code to grab output from
    process
  • Demo code

18
RunTime and System
  • System provides a system-independent way of
    accessing system resources, but is very limited.
  • Runtime lets you execute OS commands, and fiddle
    with the Java Interpreter and Java Virtual
    Machine. You should minimize and encapsulate
    this code to retain some portability.

19
The Runtime Object
20
System calls
  • Get the Runtime instance (there can be only
    one). Runtime rt
    Runtime.getRuntime()
  • Call an exec method. This returns a Process
    object and may throw an IOException.
  • Monitor the returned Process.

21
Runtime Example
  • Runtime.getRuntime() gets the Runtime object.
  • exec() creates a Process object.
  • Wrap the InputStream produced by the Process
    object, then use read() methods to read the
    input.
  • waitFor(), destroy() methods available.

22
Shells
  • A tool for low-level OS control.
  • High-level conveniences, such as variables, job
    control, automatic completion, scripting.
  • Downside steep learning curve, ugly.
  • Perfect candidate for a GUI!

23
Shell --gt WinDohs 101
  • Goal Ability to open and close directories, and
    to view files and their properties.
  • Shell normally lets you into only one directory
    at a time this doesnt make sense for our GUI.
    Each window can display the contents of a
    directory.
  • When to refresh?

24
Oh no!
  • We must be experts at using the File, System,
    and Runtime objects.
  • We must be experts on the shell.
  • We must be experts on the OS.
  • We must be experts on GUIs.
  • We must be crazy!

25
Dont Panic!
  • Basically, our job is translation.
  • The shell will do all the really hard work.
  • Plenty of help out there for the asking.
  • We have already learned most of what we need.

26

User
(JVM)
runs
WinDohs
creates
creates
Runtime
DirectoryFrame
invokes
creates
creates
data
Process
interacts with
User
27
create desktop bring up FolderSelector
click on directory name check permissions open
and refresh a new window if ok
FolderSelector
Cancel
click on refresh button or refresh timer
event. check permissions exec(ls) display
output if ok
QuitDialog
Quit
Done
28
Summary
  • Work on FrameEditor!
  • Study the Demos
  • Course Project Specs TBA this week
Write a Comment
User Comments (0)
About PowerShow.com