![]()
Lecture Topic:
![]()
// Generic AppletFrame
import java.awt.*;
import java.applet.Applet;
// Applet to Application Frame window
public class AppletFrame extends Frame {
public static void startApplet(String className, String title, String args[]) {
Applet a;
Dimension appletSize;
try {
// create an instance of your applet class
a = (Applet) Class.forName(className).newInstance();
} catch (ClassNotFoundException e) {
System.out.println("ClassNotFoundException in AppletFrame");
return;
} catch (InstantiationException e) {
System.out.println("InstantiationException in AppletFrame");
return;
} catch (IllegalAccessException e) {
System.out.println("IllegalAccessException in AppletFrame");
return;
}
// initialize the applet
a.init();
a.start();
// create new application frame window
AppletFrame f = new AppletFrame(title);
// add applet to frame window
f.add("Center", a);
// resize frame window to fit applet
// assumes that the applet sets its own size
// otherwise, you should set a specific size here.
appletSize = a.size();
f.pack();
f.resize(appletSize);
f.resize(200,200);
// show the window
f.show();
} // end startApplet()
// constructor needed to pass window title to class Frame
public AppletFrame(String name) {
// call java.awt.Frame(String) constructor
super(name);
}
// needed to allow window close
public boolean handleEvent(Event e) {
// Window Destroy event
if (e.id == Event.WINDOW_DESTROY) {
dispose();
return true;
}
// it's good form to let the super class look at any unhandled events
return super.handleEvent(e);
} // end handleEvent()
} // end class AppletFrame
rewriting code is not good idea, so AppletFrame now extends closable frame
// Applet to Application Frame window
public class ClosableFrame extends Frame {
// constructor needed to pass window title to class Frame public ClosableFrame(String name) { // call java.awt.Frame(String) constructor super(name); }// needed to allow window close public boolean handleEvent(Event e) { // Window Destroy event if (e.id == Event.WINDOW_DESTROY) { dispose(); return true; } // it's good form to let the super class look at any unhandled events return super.handleEvent(e); } // end handleEvent()
This way, the Applet Frame need not concentrate on closing event as the parent frame
Closable Frame handles the Window destroy event. This is infact a neet idea.
Save as
FileDialog fd = new FileDialog(this ,"save as...", fileDialog.SAVE);
fd.show( );
String fn = fd.getFile( );
if( fn != null ){
if( fn.endswith(" *.* ")){
fn = fn.substring( 0, fn.length( ) - 4 );
String fqn = fd.getDirectory( ) + fn;
......
The above bug mentioned, is when a file is saved , it automatically
brings up *.* extension, with the file thereby resulting in a undefined
behaviour. This bug , we suppose is corrected in JDK 1.1
Parsing BTree



Finite state machine diagram is a directed graph ( diagraph )

An example class state can be defined as follows
class state{
boolean flag = false;
state left_child;
state right_child;
add_child_L(state S){
left_child = S;
}
add_child_R(state S){
right_child = S;
}
Array of states Ps[i]
state stateArray[ ] = new state[10];
.......
An alternative definition of state class
class state{
int LNext_state;
int RNext_state;
int x = getint( );
int S = 0;
S = stateArray[S].getNextsState(x);
getNextState(int x){
if( x == 0 )
return LNext_state;
else
return RNext_state;
}
.....
Delete min - Return an element of lowest priority
Make null
Highest Priority gets lowest priority
Priority 40, 20, 26, 10, 45, 33, 14, 2

Left most leaf at Bottom level and move to Root
Delete O(log n)
Insert O(log n)
Left child at A[2i]
Right child at A[2i+1]
JGL - Java Generic Library
Last Update:
04/09/97
Copyright © 1997- Douglas Lyon
Lyon@cse.bridgeport.edu