java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
javax.swing.JApplet
objectdraw.Controller
public class Controller
Controller
is the class you should extend if you want to create an applet or
window that contains your own custom GUI instead of a DrawingCanvas
. It provides
some helpful ObjectDraw features such as the begin()
method, the
startController()
methods, and methods to load images and audio. Otherwise,
it leaves you free to create whatever GUI you want.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JApplet |
---|
JApplet.AccessibleJApplet |
Nested classes/interfaces inherited from class java.applet.Applet |
---|
Applet.AccessibleApplet |
Nested classes/interfaces inherited from class java.awt.Panel |
---|
Panel.AccessibleAWTPanel |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary |
---|
Fields inherited from class javax.swing.JApplet |
---|
accessibleContext, rootPane, rootPaneCheckingEnabled |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
Controller()
|
Method Summary | |
---|---|
void |
begin()
Override this method to do whatever your controller needs to do to set up its GUI. |
AudioClip |
getAudio(String path)
Load an audio file as an AudioClip . |
Image |
getImage(String path)
Load an image file as an Image . |
static String |
getVersion()
Determine which version of ObjectDraw you are using. |
void |
hideGrid()
|
boolean |
isGridVisible()
|
void |
showGrid()
|
void |
startController()
Run this Controller in a new window 400 pixels by 400 pixels. |
void |
startController(int width,
int height)
Run this Controller in a new window of the specified size. |
void |
startController(int width,
int height,
String name)
Run this Controller in a new window of the specified size. |
Methods inherited from class javax.swing.JApplet |
---|
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, remove, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update |
Methods inherited from class java.applet.Applet |
---|
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, init, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop |
Methods inherited from class java.awt.Panel |
---|
addNotify |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Controller()
Method Detail |
---|
public void begin()
public AudioClip getAudio(String path)
AudioClip
. Not all file formats are guaranteed to
work; in particular, the version of Java on your computer may not know how to play
.mp3
files, even if you have a separate mp3 player. The formats that should
almost always work are .midi
, .wav
, and .au
.
path
- Path of the file, relative to the project directory. In other words, the sound
file should be inside your project folder.
AudioClip
representing the requested file. If no such file was
found or it cannot be read, the return value will still be a valid AudioClip
object (not null), but it will not play anything.public Image getImage(String path)
Image
. The image formats that should
almost always work are .png
, .gif
, and .jpg
.
path
- Path of the file, relative to the project directory. In other words, the image
file should be inside your project folder.
Image
representing the requested file. If no such file was
found or it cannot be read, the return value will still be a valid Image
object (not null), but it will be invisible or may even cause an error when shown.public static String getVersion()
String
.public void hideGrid()
public boolean isGridVisible()
public void showGrid()
public void startController()
Controller
in a new window 400 pixels by 400 pixels. This method
allows you to create and run a controller from a main()
method, so that
you program can run as an application rather than an applet. It also makes it possible
to create and run a controller interactively in BlueJ or DrJava.
public void startController(int width, int height)
Controller
in a new window of the specified size. This method
allows you to create and run a controller from a main()
method, so that
you program can run as an application rather than an applet. It also makes it possible
to create and run a controller interactively in BlueJ or DrJava.
width
- width of appletheight
- height of appletpublic void startController(int width, int height, String name)
Controller
in a new window of the specified size. This method
allows you to create and run a controller from a main()
method, so that
you program can run as an application rather than an applet. It also makes it possible
to create and run a controller interactively in BlueJ or DrJava.
width
- width of appletheight
- height of appletname
- name of window