Subclass the WebUtil Object
Hi. I'm attempting to Subclass the WebUtil Object. I've attached the library to my application and I've opened the WebUtil Object Library. But how do I do this 'subclassing' to my form?
At this point I'm assuming I need an entry under the Object Group node of my form. How do I do this?
Thanks in advance.
After you've opened the object library in forms builder, double-click on it and then drag and drop the 2 webutil objects into your form. The object group goes into your object groups node, and the parameter goes into into the parameters node.
Then you need to reorder canvases and blocks so that the webutil components do not appear first when you run the form
Similar Messages
-
Attaching the WebUtil object group to a form
Hi. I'm hoping for some help on how to attach the WebUtil object group to a form. I go to the Object Groups node in the object navigator and click the '+' button, but I'm not prompted to attach .olb files. How do I do this? Without it attached I'm receiving the message "The WebUtil object group is not available in this form. WebUtil cannot work." when I run my application. Thanks in advance.
Okay I opened the .obl and it appears under the Object Libraries Node. Then I double-click on the Object Groups node in my form and it simply creates a new object named OBJECT_GROUP100. I can't seem to drag and drop from the Libraries Node to the Object Groups node in my form. It just shows a circle with a line through it indicating that I can't drag it. Any suggestions? (Sorry, I've not done this before).
-
Subclass the webutil.olb object library
Hello,
please can anybody show me how to subclass an objectgroup in the designer 9i.
I want to add the webutil.olb in somme module, but it doesn't work, and it attached only the original qmsolb65.olb. The STOLB is set to qmsolb65.olb and I add webutil.olb, but it doesn't work.
Thank youA suggestion: try to specify the object library in the Generate Form dialog directly. Also set the object group of WebUtil with pref OLBLST.
regards,
Harm -
The WEBUTIL object group is not available in this Form WebUtil cannot work
I Attacth Lib Webutil
create buttom on click
CLIENT_HOST('cmd /c DEL c:\test.mmx');
while run form then click buttom
alert error
formsweb.cfg
[webutil]
#WEBUTIL_CONFIG=C:\DevSuiteHome_1\forms\webutil.cfg
#WebUtilArchive=frmwebutil.jar,jacob.jar
WebUtilArchive=/forms/java/frmwebutil.jar,/forms/java/jacob.jar
WebUtilLogging=off
WebUtilLoggingDetail=normal
WebUtilErrorMode=Alert
WebUtilDispatchMonitorInterval=5
WebUtilTrustInternal=true
WebUtilMaxTransferSize=16384
archive_jini=frmall_jinit.jar
archive=frmall.jar
lookAndFeel=oracle
how to solve a problem Thank youLooking at both of your posts on this topic, this one and Found Error FRM-13008 Cannot find JaveBean with name oracle.forms.webutil.o I really believe that your WebUtil configuration is not complete. I ran into this same issue when I was configuring WebUtil for the first time. I attempted to take a few short-cuts because I didn't think they mattered or I thought they were already complete. After spending about 2 hours and still not getting anywhere I decided to start over and intentionally complete each step of in the Configuration section of the manual - even if I had already completed the task. Fifteen minutes later, I had WebUtil configured and working. I kicked myself for not doing that the first time! :8} You might want to consider doing the same.
Hope this helps,
Craig B-)
If someone's response is helpful or correct, please mark it accordingly. -
Added webutil object group with JDAPI - adjust the webutil block sequence ?
Hi all,
I'm using the JDAPI to subclass in the webutil object group into Forms in an application. Annoyingly, the webutil block becomes the first block on the Form - which means on some Forms it displays on startup. Is there anyway (programmatically using JDAPI) that I can move the block the end of the block list after I've subclassed in the object group ?
TIA
SteveHello,
move
void move(JdapiObject nextObject)
Reorders an object with respect to its siblings in the collection it belongs to. This is similar to using drag and drop in Form Builder to move a block in a list. This method represents a way to do the same thing programmatically. For example, if you want a block appear immediately before Block5 in a list, you pass the object representing Block5 as the nextObject argument.
Pass null to this method to move the object to the end of the list. If the specified object and the next_object do not share the same owner, or do not have the same type, the method throws an exception.
You cannot use this method to move objects between parents. For example, it cannot be used to move an Item from one Block to another. If you want to move an object from one parent to another you will have to do something like:
// to move 'itmA' to be positioned before 'itmB' in block
// 'blkB' (when 'itmA' is in another block)
// copy itmA into a new parent (blkB) using same name
Item newItmA = itmA.clone(blkB, itmA.getName());
newItmA.move(itmB); // move new item relative to itmB
itmA.destroy(); // delete original object
itmA = newItmA;
Parameters:
nextObject - the object next to which the specified object is to be moved.
Throws:
JdapiException - if you attempt to move an object next to an object that does not share the same owner or is not of the same type.
Francois -
FRM-92101 in wu_test (the webutil demo form)
Error:
FRM-92101 in wu_test (the webutil demo form)
Problem:
I am attempting to run the wu_test form, downloaded with demos for webutil 1.02.
Running wu_test or another form containing webutil functions results in
FRM-92101 in the form's window and the following error in the OC4J console.
"Forms session <1> aborted: unable to communicate with runtime process."
Environment:
Java Client: Tried with both Sun Java Plug-In 1.4.2.04/5 and Jinitiator 1.3.1.17
Application Server: Oracle 9.0.4 iDS (Orion Development OC4J)
Database: Enterprise Edition 10.1.0.2.0
Forms Listener Servlet
Attempted Solutions:
I have scoured OTN & MetaLink & tried everything I could find with no luck. I
apologize for the length of this post, but I want to provide as much information
as possible re: what I've tried and my environment.
For instance, the remedy in Note 252600.1, which can cause these symptoms, did
not help.
This note states:
In webutil.cfg modify
install.syslib.location to an absolute URL, replacing the line:
install.syslib.location=/webutil
To an absolute URL like:
install.syslib.location=http://[host]:[port]/forms90/webutil
(replacing [host] and [port] with your own values) or
install.syslib.location=//../webutil
Other Information:
Other forms (ones that don't contain webutil functions/beans) run fine with the same
env and config used for webutil.
The wu_test form is already set up so first navigation item is not on the
webutil canvas, but on the "demo" canvas.
OC4J Console:
C:\Program Files\Common Files\System\MAPI\1033\nt>C:\Ora10giDS\jdk\bin\java -Xbo
otclasspath/p:C:\Ora10giDS\vbroker4\lib\vbjboot.jar -Doracle.security.jazn.confi
g=C:\Ora10giDS\j2ee\DevSuite\config\jazn.xml -Doracle.home=C:\Ora10giDS -DORACLE
_HOME=C:\Ora10giDS -jar C:\Ora10giDS\j2ee\home\oc4j.jar -userThreads -config C:\
Ora10giDS\j2ee\DevSuite\config\server.xml
04/07/29 15:46:09 Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)
initialized
04/07/29 15:46:19 FormsServlet init():
configFileName: C:\Ora10giDS/forms90/server/formsweb.cfg
testMode: false
04/07/29 15:46:35 ListenerServlet init()
04/07/29 15:46:51 Forms session <1> aborted: unable to communicate with runtime
process.
Orion webserver application.log:
04/07/29 15:46:07 Started
04/07/29 15:46:19 forms90web: jsp: init
04/07/29 15:46:19 forms90web: f90servlet: init
04/07/29 15:46:19 forms90web: FormsServlet init():
configFileName: C:\Ora10giDS/forms90/server/formsweb.cfg
testMode: false
04/07/29 15:46:19 forms90web: 9.0.4.0.0 Started
04/07/29 15:46:35 forms90web: l90servlet: init
04/07/29 15:46:35 forms90web: ListenerServlet init()
04/07/29 15:46:51 forms90web: Forms session <1> aborted: unable to communicate with runtime process.
04/07/29 15:46:51 forms90web: Forms session <1> exception stack trace:
java.io.IOException: FRM-93000: Unexpected internal error.
Details : No HTTP headers received from runform
at oracle.forms.servlet.ListenerServlet.forwardResponseFromRunform(Unknown Source)
at oracle.forms.servlet.ListenerServlet.doPost(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:765)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
at java.lang.Thread.run(Thread.java:534)
Java Console:
Java(TM) Plug-in: Version 1.4.2_05
Using JRE version 1.4.2_05 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\isellers
Proxy Configuration: No proxy
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
p: reload proxy configuration
q: hide console
r: reload policy configuration
s: dump system properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
RegisterWebUtil - Loading Webutil Version 1.0.2 Beta
proxyHost=null
proxyPort=0
connectMode=HTTP, native.
Forms Applet version is : 9.0.4.0
oracle.forms.net.ConnectionException: Forms session <1> aborted: unable to communicate with runtime process.
at oracle.forms.net.ConnectionException.createConnectionException(Unknown Source)
at oracle.forms.net.HTTPNStream.getResponse(Unknown Source)
at oracle.forms.net.HTTPNStream.doFlush(Unknown Source)
at oracle.forms.net.HTTPNStream.flush(Unknown Source)
at java.io.DataOutputStream.flush(Unknown Source)
at oracle.forms.net.StreamMessageWriter.run(Unknown Source)
Or JInitiator Console:
Oracle JInitiator: Version 1.3.1.17
Using JRE version 1.3.1.17-internal Java HotSpot(TM) Client VM
User home directory = N:
Proxy Configuration: no proxy
JAR cache enabled
Location: N:\Oracle Jar Cache
Maximum size: 50 MB
Compression level: 0
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
q: hide console
s: dump system properties
t: dump thread list
x: clear classloader cache
0-5: set trace level to <n>
Loading http://localhost:8890/forms90/webutil/webutil.jar from JAR cache
Loading http://localhost:8890/forms90/java/f90all_jinit.jar from JAR cache
Loading http://localhost:8890/forms90/webutil/jacob.jar from JAR cache
RegisterWebUtil - Loading Webutil Version 1.0.2 Beta
proxyHost=null
proxyPort=0
connectMode=HTTP, native.
Forms Applet version is : 9.0.4.0
oracle.forms.net.ConnectionException: Forms session <2> aborted: unable to communicate with runtime process.
at oracle.forms.net.ConnectionException.createConnectionException(Unknown Source)
at oracle.forms.net.HTTPNStream.getResponse(Unknown Source)
at oracle.forms.net.HTTPNStream.doFlush(Unknown Source)
at oracle.forms.net.HTTPNStream.flush(Unknown Source)
at java.io.DataOutputStream.flush(Unknown Source)
at oracle.forms.net.StreamMessageWriter.run(Unknown Source)
Named Config sections from formsweb.cfg
#A named (sample) named configuration section for use with WebUtil & Sun JPI
[webutil]
pageTitle=Oracle Forms Services - WebUtil
webUtilArchive=/forms90/webutil/webutil.jar,/forms90/webutil/jacob.jar
WebUtilLogging=off
WebUtilLoggingDetail=normal
WebUtilErrorMode=Alert
baseHTMLjinitiator=html/bocowebutiljpi.htm
baseHTMLjpi=html/bocowebutiljpi.htm
userid=<replacedforsecurity>/<replacedforsecurity>@<replacedforsecurity>
legacy_lifecycle=false
heartBeat=5
envFile=env/webutil.env
#A named (sample) named configuration section for use with WebUtil & JInitiator
[webutiljinit]
pageTitle=Oracle Forms Services - WebUtil JInit
webUtilArchive=/forms90/webutil/webutil.jar,/forms90/webutil/jacob.jar
WebUtilLogging=off
WebUtilLoggingDetail=normal
WebUtilErrorMode=Alert
baseHTMLjinitiator=html/bocowebutiljini.htm
baseHTMLjpi=html/bocowebutiljini.htm
userid=<replacedforsecurity>/<replacedforsecurity>@<replacedforsecurity>
envFile=env/webutil.env
Webutil.env (with comments removed)
ORACLE_HOME=C:\Ora10giDS
FORMS90_PATH=C:\Ora10giDS\forms90\webutil\forms;C:\Ora10giDS\forms90\webutil\demo;C:\Ora10giDS\apps;
WEBUTIL_CONFIG=C:\Ora10giDS\forms90\webutil\webutil.cfg
CLASSPATH=C:\Ora10giDS\j2ee\OC4J_BI_Forms\applications\forms90app\forms90web\WEB-INF\lib\f90srv.jar;C:\Ora10giDS\jlib\repository.jar;C:\Ora10giDS\jlib\ldapjclnt9.jar;C:\Ora10giDS\jlib\debugger.jar;C:\Ora10giDS\jlib\ewt3.jar;C:\Ora10giDS\jlib\share.jar;C:\Ora10giDS\jlib\utj90.jar;C:\Ora10giDS\jlib\zrclient.jar;C:\Ora10giDS\reports\jlib\rwrun.jar;C:\Ora10giDS\jdk\jre\lib\rt.jar;C:\Ora10giDS\forms90\webutil\lib\webutil.jar;C:\Ora10giDS\forms90\webutil\lib\jacob.jar;
PATH=C:\Ora10giDS\bin;C:\Ora10giDS\jdk\jre\bin\client
FORMS90=C:\Ora10giDS\forms90
Section from Webutil.cfg
#install.syslib.location=/webutil
# Try absolute URL per note 252600.1 - no help
#install.syslib.location=http://it110981.boco.co.boulder.co.us:8890/forms90/webutil
# Or try relative URL like this per note 252600.1 - also no help
install.syslib.location=//../webutil
Line from orion-web.xml
<virtual-directory virtual-path="/webutil" real-path="C:\Ora10giDS/forms90/webutil/lib" />
Any suggestions on how I can get this to work will be appreciated. Thanks. -Ianmost of the time this means that your webutil.pll isn't good attached but it is very dependant on the versions you working on.
Post your versions of forms ias and webutil.
In older version it is sometimes necessary to first subclass the webutil group and then attach the webutil.pll. Other way around didn't work (was in beta version 1.02 I believe) -
Subclass webutil object group problem
Hi,
I am using 10g form.
I download the webutil demo and got a form called WU_TEST_106 in which there is
a object group called WEBUTIL.
Then I create a new form and drag the object group WEBUTIL of the form
WU_TEST_106 to the object group of the new form and choose 'subclass'.
When I check the content of the WEBUTIL data block in the new form, there
is no items there.
There should be some bean area such as WEBUTIL_FILE_FUNCTIONS and
WEBUTIL_HOST_FUNCTIONS etc.
Anyone can help ?
IvanDo not subclass WEBUTIL from another form. In folder <DevSuiteHome>\forms there should exist file webutil.olb. Open this file directly in Form Builder using
File | Open
and subclass the objects contained within.
Eric Adamson
Lansing, Michigan -
Associating native calls with the calling object
I have a problem where calls into a native library need to retain data for subsequent method calls. Imagine the following two native methods (just imagine that the signature is write for JNI methods):
void initialise(int value)
// Stores the value somehow
void dosomething()
// Does something with the previously stored value
}If I was to store the value in a global variable, then it would be shared across all instance of the java class wouldnt it? So if object 1 called initialise, then object 2 called initialise, whichever of the objects then called dosomething, it would be based on the latest call to initialise.
How do I get around this sort of thing?
I currently work in C, though I would be quite happy to switch to C++ if necessary.
MossopI haven't used JNI_OnUnload, but may see why it isn't called. The doc says it runs in the finalizer for the classloader that loaded the library. Assuming this is the system (not custom) classloader, then its finalizer will never run because it gets gc'd only at shutdown, and finalizers don't run at shutdown by default. You could try calling Runtime.runFinalizersOnExit, but it's deprecated and sounds unsafe.
So my next idea would be to add a shutdown hook (Runtime.addShutdownHook) the first time one of your objects is constructed. The hook would call a native method to do the cleanup. Or since a shutdown hook is a Thread subclass, just make your overridden run() be the native cleanup function.
Of course this now requires keeping a native-side data structure to track the native objects, though I'd still vote for storing each native peer's pointer in a Java long field for fast dereference, and make this native data structure be a simple array or list (not map) for usage only by the cleanup logic.
Another idea is to clean up in a function called by the OS or C++ runtime when your library is unloaded, independent of Java. This could be DllMain (for Windows) or a C++ global object destructor.
-slj- -
Vector clone references the same objects??
Hi all
I'm developing a simple chess program.
Obviously, each move the user tries must be checked against the following sets of chess rules:
1.) Whether it is that colour player's turn to move
2.) Whether this move is valid for this specific piece (eg. 3 forward for a King --> invalid of course)
3.) Whether this move will jeopardize the player's king (put it in check)
If from any of the above the move is found to be invalid, the move is not executed.
My program structure is briefly this:
A. abstract super class 'ChessPiece' - subclassed by the various specific Chess Piece classes.
Each of the specific ChessPiece subclasses must implement an abstract method to check if a
proposed move is valid, and also a method to actually do the move...
B. 'PieceManager' class - has a Vector of ChessPieces:
This class checks whether the given move is valid:
For the piece: by calling the checking method (see A above)
For the general game: by making sure the given move doesn't put the player's king in check.
NOTE: In chess (for those who don't know), it is illegal to move any piece if, at the end of
the move, your king will be in check [possible to be captured by any enemy piece]
This last check I want to do in the following way:
1) copy/clone the entire PieceManager object
2) in this copied object, actually do the move
3) still in the copied/cloned object, see if the moving player's king is now in check
4) based on this evaluation, execute the move in the original PieceManger object or don't...
The Problem:
When I clone this PieceManager object, its 'pieces' Vector is obviously also cloned.
BUT it seems that the cloned 'pieces' Vector references the same ChessPiece objects
as those referenced by the original 'pieces' Vector; ie the 2 Vectors are sharing the same Objects.
Thus, when I actually execute the move in the test/cloned PieceManager object,
the original PieceManager's corresponding piece is moved too (well, it seems it is the same piece...).
I am pretty stuck with this.
I've tried the Vector clone method; it doesn't seem to copy the objects, but create another reference
to the same objects, as I've said.
I've tried cloning the entire object ; also not helping......
I'd love any comments, helpful pointers, suggestions.
Also any comments on my program structure... is a Vector the best tool for this job?
Thanks very much -
luthaHi all, OP here.
Ok thanks guys for all your posts...
two points:
1) I have tried the "copy constructor", and it seems to be doing the same thing. (ie 'shallow clone')
What's really frustrating me is that nothing I do seems to actually physically copy the Vector's objects
to new, separate copies of those objects...
I had my PieceManager class implement Cloneable (just in case - not too sure on that one; in fact I
commented that out later), and I overrode the clone method like this:
public Object clone ()
PieceManager pm = new PieceManager ();
Vector pcs = new Vector ();
// Enumeration e = pieces.elements ();
//while (e.hasMoreElements ())
// ChessPiece p = (ChessPiece) e.nextElement ();
//pcs.add ();
//} // still references the same objects!!
pieces.trimToSize ();
int size = pieces.size ();
Object[] arr = new Object [size];
Object[] initial = pieces.toArray ();
System.arraycopy (initial, 0, arr, 0, size);
for (int i = 0 ; i < size ; i++)
ChessPiece p = (ChessPiece) arr ;
pcs.add (p);
pm.pieces = pcs;
return pm;
This all still does the same 'shallow cloning'...
2) m.winter, my ChessPiece objects are not immutable - they have a co-ordinate field that
changes as they are moved. This is for getting as called by another object, and for checking in
the ChessPiece's own internal method for checking whether the passed-in square co-ordinate
is a valid destination.
Anyway, I don't think that's the main issue here. How can I properly clone/copy a Vector, resulting
in :
a) the original Vector
b) a new, totally unrelated Vector.
Thanks again all for your input.
regards,
lutha -
Including webutil objects with api
Is possible including webutil objects (objects from object library and webutil.pll ) with forms API. Exists examples for this?
The answer is yes - it's pretty simple to carry out the tasks you need to do. Attaching the PLL and the Object Group are simple (see the JDAPI samples in the forms Demos for this) and for the conversion of the Code calls - e.g. OLE2 to CLIENT_OLE2 you can actually use the migration assistant to make the string changes in the PL/SQL code for you. It has a code replacfement feature configured through it's properties file which you can add to to do this.
-
Failed to load the following objects....
I sublassed some objects from an object library. They worked well for while. However, after I installed some other oracle software, I opened the form again I got error message:
FRM-18108: Failed to load the following objects.
Even I edited the subclass information property to re-enter the information again, I still got the message.
Any way to correct this.
Thanks.Thanks.
Now, the message is gone.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Suresh Rangaswamy ([email protected]):
your registry got screwed-up. Check the forms path in the registry (forms60_path)<HR></BLOCKQUOTE>
null -
Where is the origin of the ServerletConfig object?
Look at the following code snippet, which is a typical init() method from a HttpServlet subclass:
====================================================
public class myServlet
extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
====================================================
This implementation stores the ServletConfig object it receives from the servlet container for later use.
My question is where the particulars of the ServletConfig object come from? Any .xml file or .properties file? My working environment is Tomcat 4.1.partially from the application's web.xml, that is the only information useful to a java web developer anyway (next to the META-INF/context.xml used in tomcat 5 and up).
-
The method clone() from the type Object is not visible
Hi,
This is my 1st post here for a few years, i have just returned to java.
I am working through a java gaming book, and the "The method clone() from the type Object is not visible" appears, preventing the program from running. I understand "clone" as making a new copy of an object, allowing multiple different copies to be made.
The error occurs here
public Object clone() {
// use reflection to create the correct subclass
Constructor constructor = getClass().getConstructors()[0];
try {
return constructor.newInstance(new Object[] {
(Animation)left.clone(),
(Animation)right.clone(),
(Animation)deadLeft.clone(),
(Animation)deadRight.clone()
catch (Exception ex) {
// should never happen
ex.printStackTrace();
return null;
}The whole code for this class is here
package tilegame.sprites;
import java.lang.reflect.Constructor;
import graphics.*;
A Creature is a Sprite that is affected by gravity and can
die. It has four Animations: moving left, moving right,
dying on the left, and dying on the right.
public abstract class Creature extends Sprite {
Amount of time to go from STATE_DYING to STATE_DEAD.
private static final int DIE_TIME = 1000;
public static final int STATE_NORMAL = 0;
public static final int STATE_DYING = 1;
public static final int STATE_DEAD = 2;
private Animation left;
private Animation right;
private Animation deadLeft;
private Animation deadRight;
private int state;
private long stateTime;
Creates a new Creature with the specified Animations.
public Creature(Animation left, Animation right,
Animation deadLeft, Animation deadRight)
super(right);
this.left = left;
this.right = right;
this.deadLeft = deadLeft;
this.deadRight = deadRight;
state = STATE_NORMAL;
public Object clone() {
// use reflection to create the correct subclass
Constructor constructor = getClass().getConstructors()[0];
try {
return constructor.newInstance(new Object[] {
(Animation)left.clone(),
(Animation)right.clone(),
(Animation)deadLeft.clone(),
(Animation)deadRight.clone()
catch (Exception ex) {
// should never happen
ex.printStackTrace();
return null;
Gets the maximum speed of this Creature.
public float getMaxSpeed() {
return 0;
Wakes up the creature when the Creature first appears
on screen. Normally, the creature starts moving left.
public void wakeUp() {
if (getState() == STATE_NORMAL && getVelocityX() == 0) {
setVelocityX(-getMaxSpeed());
Gets the state of this Creature. The state is either
STATE_NORMAL, STATE_DYING, or STATE_DEAD.
public int getState() {
return state;
Sets the state of this Creature to STATE_NORMAL,
STATE_DYING, or STATE_DEAD.
public void setState(int state) {
if (this.state != state) {
this.state = state;
stateTime = 0;
if (state == STATE_DYING) {
setVelocityX(0);
setVelocityY(0);
Checks if this creature is alive.
public boolean isAlive() {
return (state == STATE_NORMAL);
Checks if this creature is flying.
public boolean isFlying() {
return false;
Called before update() if the creature collided with a
tile horizontally.
public void collideHorizontal() {
setVelocityX(-getVelocityX());
Called before update() if the creature collided with a
tile vertically.
public void collideVertical() {
setVelocityY(0);
Updates the animaton for this creature.
public void update(long elapsedTime) {
// select the correct Animation
Animation newAnim = anim;
if (getVelocityX() < 0) {
newAnim = left;
else if (getVelocityX() > 0) {
newAnim = right;
if (state == STATE_DYING && newAnim == left) {
newAnim = deadLeft;
else if (state == STATE_DYING && newAnim == right) {
newAnim = deadRight;
// update the Animation
if (anim != newAnim) {
anim = newAnim;
anim.start();
else {
anim.update(elapsedTime);
// update to "dead" state
stateTime += elapsedTime;
if (state == STATE_DYING && stateTime >= DIE_TIME) {
setState(STATE_DEAD);
}Any advice? Is it "protected"? Is the code out-of-date?
thankyou,
Lance 28Lance28 wrote:
Any advice? Is it "protected"? Is the code out-of-date?Welcome to the wonderful world of Cloneable. In answer to your first question: Object's clone() method is protected.
A quote from Josh Bloch's "Effective Java" (Item 10):
"A class that implements Cloneable is expected to provide a properly functioning public clone() method. It is not, in general, possible to do so unless +all+ of the class's superclasses provide a well-behaved clone implementation, whether public or protected."
One way to check that would be to see if super.clone() works. Their method uses reflection to try and construct a valid Creature, but it relies on Animation's clone() method, which itself may be faulty. Bloch suggests the following pattern:public Object clone() throws CloneNotSupportedException {
ThisClass copy = (ThisClass) super.clone();
// do any additional initialization required...
return copy
if that doesn't work, you +may+ be out of luck.
Another thing to note is that Object's clone() method returns a +shallow+ copy of the original object. If it contains any data structures (eg, Collections or arrays) that point to other objects, you may find that your cloned object is now sharing those with the original.
Good luck. -
Garbage-collecting the cloned objects
public class Clone implements Cloneable {
public static void main(String[] arg) {
Clone i0, i1;
i0 = new Clone();
System.out.println("Created: " + i0);
try{
i1 = (Clone)i0.clone();
System.out.println("Cloned: " + i1);
} catch(CloneNotSupportedException e){
e.printStackTrace();
i0 = null;
i1 = null;
System.gc();
public Object clone() throws CloneNotSupportedException {
return super.clone();
public void finalize() {
System.out.println("Finalizing " + this);
With the example above you can notify that with Hotspot VM of JDK1.3 the
finalize() method will not be called for the cloned object; though,
running the sample with the classic VM, the finalize() will be
called for both objects.
Bypassing the finalize() can be made intended, in order to avoid
multiple "release" or "close" calls on the same object, eg. if the
finalize() has to close a file or a JDBC-connnection. But then why
is it called in the classic VM? Is it sure that the cloned object
too will be garbage-collected?Here's the proper way to write a clone() method:
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}There's no reason for a clone() method to declare that it throws CloneNotSupportedException. Doing so just makes code that uses the clone() method more complicated unnecessarily.
Here's the proper way to write a finalizer:
protected void finalize() {
try {
// perform subclass cleanup
} finally {
super.finalize();
You should always make finalize() protected to help ensure that only the garbage collector calls it, and it should always call super.finalize() to ensure that the superclass finalization can happen.
Now, to your question. There's no way to guarantee that an object will be garbage collected or finalized. In fact, finalizers are so notoriously hard to write correctly that Java 2 added PhantomReferences to allow a simpler way to clean up objects.
If you want an object to release resources, such as closing a file or releasing a database connection, provide a close() or dispose() or release() method in the class and close the resources there. Even if you could guarantee that your finalizer is called or if you used PhantomReference queues to perform cleanup, this cleanup would probably not happen in a timely manner. Finalizers are not C++ destructors -- if you need to release resources, add a method to do that. -
Getting the calling object reference / class?
Dear forum members,
Is it possible for A in the below example to get that B was the "caller"?
class A {
A() {
public void someMethod(String text) {
System.out.println("I was called with: " + text);
System.out.println("I was called by: " + thatMagicWayToGetCallerClassOrReference());
class B {
public static void main(String[] args) {
A a = new A();
a.someMethod("HOLA HOLA");
}Another way of getting the class of your caller is to use a SecurityManager object. getClassContext() is protected but you can get at it by subclassing SecurityManager (it works if you just instanciate the manager without installing it). This gives you a reference to the Class object itself where the stack trace returns only the class name. Bear in mind that the class in question will be several items up the array, the first entry is the SecurityManager itself, the second the called class.
However, I agree with others it doesn't sound like the best design. If you're having trouble with not being able to change the interface specifications to pass the extra information then consider using a static reference, if necessary a ThreadLocal. What happens if you want to call the offending method indirectly through some central method at some future time? You've lost the call origin data.
Why can't you simply add a parameter to the offending call?
Maybe you are looking for
-
Camera not recognized! Green image only.
Here's a mystery for ya... I've got a brand new Powerbook G4, 1.67GHz, 2GB of RAM with a 120G harddrive. A few of the applications I can hook up my DV camera to via firewire freeze up, freak out or just plain don't work. On my older Powerbook (1GHz,
-
I need help. All of my word docs from Microsoft word 2004 cannot be read in Lion. I can't believe I'll have to pay for a Word upgrade. Is it worth it? Is pages as good? Will all of my docs be recognized once I upgrade to the current word or Page
-
Hi All, I am doing WebService to File Scenario. Here I am facing problem when I am sending request . It is saying " http error.Could not post file" I have given the url as http://<server>.domain:<port>/XISOAPAdapter/MessageServlet?channel=:BS_SOA
-
i updated my iphone 4 via itunes from 5.1.1 to 6.1.2. when i finished update it, it deleted all my messages and pictures and they're very important to me. please help me to restore it. thanks
-
Buying First iPhone Tomorrow Curious if I should get 16gb or 32gb
Getting my first iPhone tomorrow and curious which would be the best choice.I've had a 30gb 5th Generation iPod for some time which is full... so should I go for the 32gb iPhone..?