Returning Non Serializable Objects
Is it possible in anyway to return non serializable objects from the remote method of an EJB, for instance return a result set. Everytime i try, i get a CORBA marshalling exception, i tried to put the resultset in a serilized object such as an enumeration or vector but got the same error when retreiving it from the enumeration or vector. Help is needed and appreciated. Thanx.
Is it possible in anyway to return non serializable objects from the remote method of an EJB, for instance return a result set. Everytime i try, i get a CORBA marshalling exception, i tried to put the resultset in a serilized object such as an enumeration or vector but got the same error when retreiving it from the enumeration or vector. Help is needed and appreciated. Thanx.
Similar Messages
-
I am working on a java project and I have to serialize a class (created by me) which has many references to other classes that should be serialized too.
I add the marker "implements serializable" to all the necessary classes, but when I run I get a non serializable exception.
Maybe one ore more objects are non serializable, but how do I identify them?
I've read that If I have to serialize non serializable objects, I need to write my own writeObject(ObjectOutputStream out)throws IOException and readObject(ObjectInputStream in) , but I don't know how to implement and us them.
note : I can't use transient beacuse I need everything to be serialized!
Thanks a lot. Bye!Now I'll post my code, If anyone knows how to serialize (and then deseserialize) the class "AgentMessage" , and its subclasses "StaticPart" and "DynElement" from the main class , I'll be grateful.. It's about 2 days I'm working on it and I continue getting "nonserialializable exception" ...
thank you guys
package agentsLibrary;
//some imports
public class AgentMessage implements Serializable{
private static final long serialVersionUID = 1L;
private StaticPart sp;
private DynElement de;
public AgentMessage(String agent,byte[] code,String mainclass,Certificate signerId,PrivateKey priv,String configuration,Serializable dclear,byte[] dsecret,PathEl[] dpath,byte[] c){ //costruttore
sp=new StaticPart(agent,code,mainclass,signerId,priv,configuration);
de=new DynElement(dclear,dsecret,c,dpath);
public StaticPart getSp(){
return sp;
public DynElement getDe(){
return de;
private void writeObject(java.io.ObjectOutputStream out) throws IOException{
System.out.println("class implements writeObject( )");
//depends on the method to store out all the important state
//out.defaultWriteObject();//perform the default serialization(va sempre fatto il default)
out.writeObject(sp);
out.writeObject(de);
private void readObject(java.io.ObjectInputStream in)throws ClassNotFoundException, IOException {
System.out.println("class implements readObject( )");
//in.defaultReadObject();
sp=(StaticPart)in.readObject();
de=(DynElement)in.readObject();
package agentsLibrary;
public class StaticPart implements Serializable{
private static final long serialVersionUID = 1L;
private String agent="";
private byte[] code=null;
private String mainclass="";
private Certificate signerid=null;
private PrivateKey priv=null;
private Calendar timestamp=null;
private Signature sig=null;
private byte[] buffertotale=null;
private byte[] firma=null;
private String configuration="";
public StaticPart(String agent, byte[] code, String mainclass, Certificate signerid, PrivateKey priv,String configuration){
this.configuration=configuration;
this.code=code;
this.mainclass=mainclass;
this.agent=agent;
this.priv=priv;
this.signerid=signerid;
timestamp=Calendar.getInstance();
Date time=new Date();
time=timestamp.getTime();//Gets this Calendar's current time.
try {
byte[] nomeagent=agent.getBytes("8859_1");//converto stringa
byte[] mainclas=mainclass.getBytes("8859_1");//converto stringa
byte[] signer=signerid.getEncoded();
byte[] priva=priv.getEncoded();
byte[] dat=null;
dat=time.toString().getBytes("8859_1");
buffertotale=new byte[nomeagent.length+mainclas.length+signer.length+priva.length+dat.length+code.length];
System.arraycopy(nomeagent, 0, buffertotale, 0, nomeagent.length);
System.arraycopy(code, 0, buffertotale, nomeagent.length, code.length);
System.arraycopy(mainclas, 0, buffertotale, code.length, mainclas.length);
System.arraycopy(signer, 0, buffertotale, mainclas.length, signer.length);
System.arraycopy(priva, 0, buffertotale, signer.length, priva.length);
System.arraycopy(dat, 0, buffertotale, priva.length, dat.length);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.exit(1);
} catch (CertificateEncodingException e) {
e.printStackTrace();
System.exit(1);
try {
sig = Signature.getInstance(priv.getAlgorithm());
sig.initSign(priv);
sig.update(buffertotale, 0, buffertotale.length);
firma=sig.sign();
} catch (SignatureException e) {
e.printStackTrace();
System.exit(1);
} catch (InvalidKeyException e) {
e.printStackTrace();
System.exit(1);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
System.exit(1);
public boolean verify() {
try{
PublicKey pub=signerid.getPublicKey();
Signature sig = Signature.getInstance(pub.getAlgorithm());
sig.initVerify(pub);
sig.update(buffertotale, 0, buffertotale.length);
return sig.verify(firma);
} catch (SignatureException e) {
e.printStackTrace();
System.exit(1);
} catch (InvalidKeyException e) {
e.printStackTrace();
System.exit(1);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
System.exit(1);
return false;
public String getAgentName() {
return agent;
public byte[] getCode() {
return code;
public String getClassName() {
return mainclass;
public PrivateKey getPrivate() {
return priv;
public Certificate getId() {
return signerid;
public byte[] getSignature(){
return firma;
public String getConfiguration(){
return configuration;
package agentsLibrary;
import java.io.Serializable;
public class DynElement implements java.io.Serializable{
private static final long serialVersionUID = 1L;
private Serializable dclear=null;
private byte[] dsecret=null;
private PathEl[] dpath=null;
private byte[]c=null;
public DynElement(Serializable dclear,byte[] dsecret,byte[]c,PathEl[] dpath){
this.dclear=dclear;
this.dsecret=dsecret;
this.c=c;
this.dpath=dpath;
public byte[] getC() {
return c;
public Serializable getDclear() {
return dclear;
public PathEl[] getDpath() {
return dpath;
public byte[] getDsecret() {
return dsecret;
//finally the following is the main class that should serialize
AgentMessage msg=new AgentMessage(name,code,mainclass,signerId,privata,configuration,dclear,dsecret,dpath,c);
try {
System.out.println("Sending Agent Message to Server "+ip+":"+port);
Socket s = new Socket(ip,port);
ObjectOutputStream out=new ObjectOutputStream(s.getOutputStream());
out.writeObject(msg);
out.flush();
s.close();
} catch (Exception e) {
return false;
return true;
} -
Sending Non-Serializable Objects
I'm trying to make my server program send a non-serializable object to the client program. But I'm getting a 'java.io.NotSerializableException'. Is there any way to send a non-serializable object through an ObjectOutputStream, or through some other type of stream object?
Thanks.
~jonI have some experience before, here is one solutions:Well, nice to know, but its not a solution to the problem discussed in this topic though.
>
>
using toByteArray to get a byte[] and a length of the
array
then using the following format to send through
sockets,
[bytearray.length][byte array content]
It really works in a project of a MMS system I have
worked on. -
Serialializing non serializable objects
Hi guys,
I have to serialize (and then send through socket) a class which implements java.io.Serializable. This class also has some reference with other classes, which should be serialized togheter.
But when I run the main class (which only serializes) , java.io.NotSerializableException is thrown.
How do I recognize if a class is effectively serializable?
How do I serialize too even with non-serializable objects?
(I need all these objects)
note : In the class I have only put the marker "implements java.io.Serializable",should I have to do somenthing else?
Thank You for your great help!Hi guys,
I have to serialize (and then send through socket)a
class which implements java.io.Serializable. This
class also has some reference with other classes,
which should be serialized togheter.
But when I run the main class (which onlyserializes)
, java.io.NotSerializableException is thrown.
How do I recognize if a class is effectively
serializable?
How do I serialize too even with non-serializable
objects?
(I need all these objects)
note : In the class I have only put the marker
"implements java.io.Serializable",should I have todo
somenthing else?
Thank You for your great help!I wish there was a utility that could inspect a
Class, traverse its containment tree and flag
serializability issues. This could be more powerful
if generics are used.
To solve your problem besides the marker, implement
methods writeObject and readObject and serializing
the contained object that is not serializable by
hand. For example if your class is X which contains Y
that is not serializable then you need to serialize
fields Y in X.writeObject and construct a Y object in
X.readObject:
class Y { // not serializable and you cannot modify
it
int i;
int j;
Y(int i, int j)
class X implements Serializable {
String xyz;
Y y;
private void writeObject(ObjectOutputStream out)
throws IOException{
out.writeObject(xyz);
out.writeInt(y.getI());
out.writeInt(y.getJ());
private void readObject(ObjectInputStream in)
throws IOException{
xyz = (String) in.readObject();
int i = in.readInt();
int j = in.readInt();
y = new Y(i, j);Remember to maintain the same order in readObject and
writeObject.
Hi guys,
I have to serialize (and then send through socket)a
class which implements java.io.Serializable. This
class also has some reference with other classes,
which should be serialized togheter.
But when I run the main class (which onlyserializes)
, java.io.NotSerializableException is thrown.
How do I recognize if a class is effectively
serializable?
How do I serialize too even with non-serializable
objects?
(I need all these objects)
note : In the class I have only put the marker
"implements java.io.Serializable",should I have todo
somenthing else?
Thank You for your great help!I wish there was a utility that could inspect a
Class, traverse its containment tree and flag
serializability issues. This could be more powerful
if generics are used.
To solve your problem besides the marker, implement
methods writeObject and readObject and serializing
the contained object that is not serializable by
hand. For example if your class is X which contains Y
that is not serializable then you need to serialize
fields Y in X.writeObject and construct a Y object in
X.readObject:
class Y { // not serializable and you cannot modify
it
int i;
int j;
Y(int i, int j)
class X implements Serializable {
String xyz;
Y y;
private void writeObject(ObjectOutputStream out)
throws IOException{
out.writeObject(xyz);
out.writeInt(y.getI());
out.writeInt(y.getJ());
private void readObject(ObjectInputStream in)
throws IOException{
xyz = (String) in.readObject();
int i = in.readInt();
int j = in.readInt();
y = new Y(i, j);Remember to maintain the same order in readObject and
writeObject. -
Inserting non-serializable objects
Is there any way to insert non-serializable objects into a database? (Or to convert them to bytes?)
Is there any way to insert non-serializable objectsinto a database?
A joke right?No, it's not a joke. It would be a pretty bad one if it were.
Yes, there is a way. Create a table that corresponds
to the object where each attribute in the object
corresponds to field in the object. Add a unique key
if one doesn't exist.I wish it were that simple. I don't have access to those attributes...
>
To create an object insert a row into the table. To
load the object use the unique key to query for the
row. To 'delete' the object delete the row from the
table.BTW, the object in question is the java.awt.geom.Area object (http://java.sun.com/j2se/1.3/docs/api/java/awt/geom/Area.html ).
The only way I can think of to insert an object that doesn't map to a SQL type is to convert it to bytes through serialization, and insert it as RAW data.
I've extended Area to add a name and made my class serializable. However, since Area is not serializable, the only data I can retrieve after deserializing is the name I added (from my understanding of serialization, I have to save Area's data myself, but can't since I don't have access to it, so the deserialization process calls the Area() constructor which initializes the object to empty). -
Non-Serializable objects in webservice
Hi everyone,
I'm writing a webservice that connects and performs update on a third-party
data repository (document management system) through the vendor provided
framework.
Some of the objects used in the framework are not serialized, and WebLogic
Workshop 7.0 won't compile my services because they contain non-serializable
objects. Those objects are not used as messages or method parameters, rather
are the member variables of the services.
My question is how would I go about using non-serialized objects in a
webservice class with WebLogic Workshop 7.0? I've seen some Apache AXIS
webservice examples that does the similar thing, but some of the services
works with non-serializable objects. Do I need to create an EJBcontrol that
masks non-serializable objects to be used with the webservice?
Any input is greatly appreciated. I'm still new at webservice programming.
Thank you,
MakotoHi everyone,
I'm writing a webservice that connects and performs update on a third-party
data repository (document management system) through the vendor provided
framework.
Some of the objects used in the framework are not serialized, and WebLogic
Workshop 7.0 won't compile my services because they contain non-serializable
objects. Those objects are not used as messages or method parameters, rather
are the member variables of the services.
My question is how would I go about using non-serialized objects in a
webservice class with WebLogic Workshop 7.0? I've seen some Apache AXIS
webservice examples that does the similar thing, but some of the services
works with non-serializable objects. Do I need to create an EJBcontrol that
masks non-serializable objects to be used with the webservice?
Any input is greatly appreciated. I'm still new at webservice programming.
Thank you,
Makoto -
Failed to replicate non-serializable object Weblogic 10 3 Cluster environ
Hi,
We have problem in cluster environment, its showing all the objects in Session needs to be serialized, is there any tool to find what objects in session needs to be serialized or any way to find. There was no issue in WLS 8 when the application again setup in WLS 10, we are facing the session replication problem.
The setup is there are two managed server instance in cluster, they are set to mulicast(and also tried with unicast).
stacktrace:
####<Jun 30, 2010 7:11:16 PM EDT> <Error> <Cluster> <userbser01> <rs002> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1277939476284> <BEA-000126> <All session objects should be serializable to replicate. Check the objects in your session. Failed to replicate non-serializable object.>
####<Jun 30, 2010 7:11:19 PM EDT> <Error> <Cluster> <userbser01> <rs002> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1277939479750> <BEA-000126> <All session objects should be serializable to replicate. Check the objects in your session. Failed to replicate non-serializable object.>
Thanks,Hi
Irrespective of WLS 8.x or WLS 9.x, 10.x, in general any objects that needs to be synced/replicated across the servers in cluster should be Serializable (or implement serializable). The object should be able to marshall and unmarshall. Simple reason why it did not showed in WLS 8.x is may be in that version they could not show these details like Error. May be they showed as Info or Warn or Just Ignored it. Weblogic Server became more and more stable and more efficient down the lines like from its oldest version 4.x, 5.x, 6.x, 7.x to latest 10.x. So my guess is they added more logic and more functionality to capture all possible errors and scenarios. I did worked on WLS 8.1 SP4 to SP6 long time back. Could not remember if I saw or did not see these errors for cluster domain with non-serializabe objects. I vaguley remember seeing it for Portal Domains but not sure. I do not have 8.x installed, otherwise I would have given a quick shot and confirm it.
So even though it did not showed up in WLS 8.x, still underneath rule is any object that needs to be replicated that is getting replicated in cluster needs to implement Serializable interface.
Thanks
Ravi Jegga -
URGENT : Pass non-serializable objects over sockets
I am working with a non-serializable class.I can't change it to serializable(since it's an API class).I can't create a subclass either as I need to pass the same exact Object .I have tried wrapping it in a serializable class (as transient )but then the particular object that I need is not serialized.Is there a way to pass non-serializable objects over sockets?.Some other way of doing this?. Should i use RMI or Externalize?. Any help would be appreciated.
{snip}
Like this:
public class SerializableLibraryClass extends
LibraryClass implements Serializable {
}Then you've got a class that is exactly the same as
LibraryClass, but is now serializable.Not quite. The base class still isn't Serializable. Take, for example, the following code:
public class A
public int a1;
public class B extends A implements Serializable
public int b1;
B beforeSend = new B();
beforeSend.a1 = 1;
beforeSend.b1 = 2;
objectOutputStream.writeObject(b);
B afterSend = (B)(objectInputStream.readObject());Both beforeSend and afterSend have fields a1 and b1. For beforeSend, a1 = 1 and b1 = 2. For afterSend, b1 = 2 but a1 = 0. The superclass wasn't Serializable; therefore, its members weren't Serialized and, when the object was created on the other side of the stream, a1 was left at its initial value.
In short, you can't just Serialize the subclass. That Serialization won't apply to its superclasses. -
Pass non-serializable objects over sockets
I am working with a non-serializable class.I can't change it to serializable(since it's an API class).I can't create a subclass either as I need to pass the same exact Object .I have tried wrapping it in a serializable class (as transient )but then the particular object that I need is not serialized.Is there a way to pass non-serializable objects over sockets?.Some other way of doing this?.
Have you considered leaving it in situ and using RMI to manipulate it remotely ?
To be a little pedantic, if you need the "same exact object" then there's no technique that will work for you, since you can only copy an object between JVMs, not move it.
D. -
Returning a serializable object from a java stored procedure
[Server : Oracle 8.1.6 on WinNT4 server. Client : java 1.2.2 on WinNT4 workstation.]
I am attempting to use a java stored procedure to build a complex serializable java object on the database (to minimise number of requests/queries on the network) and then return this object in response to the original query.
I have it writing a BLOB by means of
OutputStream os = retval.getBinaryOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(v);
return retval;
where retval is a blob selected from a dummy table (created for this purpose) and v is a vector containing only serializable objects.
However, on the client side when I attempt to recover the object by
OracleResultSet rs = (OracleResultSet)stmt.executeQuery("SELECT javatest FROM DUAL");
oracle.sql.BLOB blob=rs.getBLOB(1);
InputStream inp = blob.getBinaryStream();
ObjectInputStream oinp = new ObjectInputStream(inp);
Vector retval = (Vector)oinp.readObject();
I get an exception telling me that the input stream does not contain an object at the line containing new ObjectInputStream(inp);
The full exception is :
java.io.StreamCorruptedException: InputStream does not contain a serialized object
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:731)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:165)
at eRespond.DBLayer.JavaStoredProcedures.testdbobj.test2(testdbobj.java:143)
at eRespond.DBLayer.JavaStoredProcedures.testdbobj.main(testdbobj.java, Compiled Code)
I've checked that the returned blob is non-null, and that oracle.sql.BLOB is used throughout.
Any thoughts?
Thanks,
mark.Firstly I guess to be able to new B() as a Thread, B
should extends Thread.
Secondly the constructor should not have any return
type:
public B(String cmd)
instead of
public void B(String cmd)
Lastly there is no need to override the start() method
if all it does is to call the superclass. The subclass
automatically inherits the method.
Hope this helps.thanks for replying so soon...
yes, you are right, it should extends Thread and it is, i forgot to out in this example... my mistake!
i'll try the construnctor thing to see if it works. bare in mind that i working with java stored procedures, it should work even so, right?
thanks -
Store non-serializable object in session
Dears,
I am storing an object in the session but after some requests the object gets null. A friend told me that happens because that object is not serializable.
Is that true? and how to fix this?
Thanks in advance
BISObiso wrote:
I am storing an object in the session but after some requests the object gets null. A friend told me that happens because that object is not serializable.
Is that true? Only if the application server is configured to persist the sessions on shutdown and it is been restarted while you was using/testing the webapp. But you should have seen a NotSerializableException in the application server logs, which is fairly self-explaining.
and how to fix this?Implement [java.io.Serializable|http://java.sun.com/javase/6/docs/api/java/io/Serializable.html].
Or just don't restart the appserver while you're testing on the same session. -
How to store a Non Serializable Java Object ?
Hi..
I have a non serializable java object which I want to store in the Oracle database and retrieve it. Can anyone help me with how to go about doing this ?
many thanks in advance
RagavanIf you share the same JVM then its possible, but I doubt that is the case. If you don't share the JVM then its
impossible to share an object between two apps.
But if all your attempting to do is duplicate the object in the other app then I spose it is possible, as long as
you can reconstruct the object from information that you can interegate from the object.
For example, if you have App A, and App B. WIthin App A is a Double d object. Then you could get the
value of the Double by doing:
d.doubleValue()
write the double to a file/socket/stream, read the file/socket/stream at the other end, create a new Double
via Double d = new Double(parsedValue);
Now the two Apps will have a Double d object that represent the same value via a a.equals(b) == true, but
they will not refer to the same object within memory/jvm.
James. -
Object (which has non-serializable attr.) serialization
i could not solve object serialization problem in anyway. how can this be performed without "java.io.NotSerializableException"?
import java.awt.Image;
import java.awt.Toolkit;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Object2ByteArray {
public static void main(String[] args) {
Object2ByteArray obj2ba = new Object2ByteArray();
AnObject anObj = obj2ba.new AnObject();
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//FileOutputStream fos = new FileOutputStream("C:\\obj.file");
ObjectOutputStream oos = new ObjectOutputStream(baos); //or (fos)
baos.writeTo(oos);
oos.writeObject(anObj);
oos.flush();
byte[] objInBytes = baos.toByteArray();
System.out.println("An object (which has a non-serializable element[Image]) is written to ObjectOutputStream.");
} catch (IOException e) {
e.printStackTrace();
public class AnObject implements Serializable {
Image img = Toolkit.getDefaultToolkit().getImage("C:\\anil.jpg");
int c = 10;
String desc = null;
}Hi,
No, transient means that the attribute won't be sent over the stream. You usually declare fields that you don't want to send, or can't send as transient.
/Kaj -
Hi,
I am attempting to create a cache on the web server to store
frequently accessed reference data. I do so by running a series of
queries in a startup class. The data retrieved from the result set of
each query is stored in a custom class and bound to the server context.
My understanding is that when serializable objects are bound, they are
written to disk (so as not.to waste valuable Heap space I assume). As a
test I made the startup query return a large amount of data and I
expected to see the amount of free disk space decrease as the objects
were bound however I did not see this occurring. I examined the memory
usage of the java process with the NT task manager, and the memory usage
was increasing pretty dramatically as the query results were performed
and new objects created to store this data.
Based on these observations I assume that the objects I created and
bound are stored in the Java Heap and not written to disk. Would
Weblogic at some point write these to disk if memory became tight or is
my understanding that binding an object serializes it incorrect?
If it turns out that what I am attempting here consumes a lot of heap
space, I assume that server performance will suffer which is
unacceptable. Would using read-only entity beans be a better solution?
The container could manage this memory more effectively but it would
seem to add a lot of overhead for a simple read only data cache.
Thanks,
Steve SnodgrassWe never write jndi data to the disk. So if you add more objects your are
going to take up more heap space. You should be looking at other
alternatives to implement this.
-- Prasad
Steve Snodgrass wrote:
Hi,
I am attempting to create a cache on the web server to store
frequently accessed reference data. I do so by running a series of
queries in a startup class. The data retrieved from the result set of
each query is stored in a custom class and bound to the server context.
My understanding is that when serializable objects are bound, they are
written to disk (so as not.to waste valuable Heap space I assume). As a
test I made the startup query return a large amount of data and I
expected to see the amount of free disk space decrease as the objects
were bound however I did not see this occurring. I examined the memory
usage of the java process with the NT task manager, and the memory usage
was increasing pretty dramatically as the query results were performed
and new objects created to store this data.
Based on these observations I assume that the objects I created and
bound are stored in the Java Heap and not written to disk. Would
Weblogic at some point write these to disk if memory became tight or is
my understanding that binding an object serializes it incorrect?
If it turns out that what I am attempting here consumes a lot of heap
space, I assume that server performance will suffer which is
unacceptable. Would using read-only entity beans be a better solution?
The container could manage this memory more effectively but it would
seem to add a lot of overhead for a simple read only data cache.
Thanks,
Steve Snodgrass -
I'm using OC4J 9.0.2.1 and JDeveloper 9.0.2 with Oracle db. I have a set of queues created in the database.
Before I try to send my request, I create an instance of the serializable object I want to send. I do all of my queue connection setup, then I call:
queueSession.createObjectMessage(request);
Where "queueSession" is a QueueSession obtained from "queueConnection.createQueueSession()".
When I step over this function call, I get the following:
oracle.jms.AQjmsException: JMS-109: Class not found: com.attws.it.bsa.felix.mci.common.ServiceInfoRequest
(The indicated class name is the type of the "request" object.)
What could I be doing wrong?The code below creates the following classes when I compile it (using jsk1.3):
DistanceBarApplication2.class
DistanceBarApplication2$1
DistanceBarApplication2$2
DistanceBarApplication2$3
DistanceBarApplication2$DistanceBar2
The error I receive is: load: class DistanceBarApplication2 not found
Here is my HTML code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<applet code="DistanceBarApplication2.class" width=300 height=50>
</applet>
</BODY>
</HTML>
Here is the Java code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DistanceBarApplication2 extends JApplet {
private final DistanceBar2 bar = new DistanceBar2();
public void init() {
bar.setMaximum(100);
bar.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
bar.stop();
JOptionPane.showMessageDialog(bar, bar.getValue() + " yards");
bar.start();
this.getContentPane().add(bar);
bar.start();
static class DistanceBar2 extends JProgressBar {
private Thread mThread;
private boolean mRunning= false;
private int mValue = 0;
private boolean mUp = true;
private Runnable updater = new Runnable() {
public void run() {
setValue(mValue);
public void start() {
if (mRunning) {
return;
mRunning = true;
mThread = new Thread(new Runnable() {
public void run() {
while (mRunning) {
try {
Thread.sleep(30);
} catch (InterruptedException e) { }
adjust();
mThread.setDaemon(true);
mThread.start();
public void stop() {
mRunning= false;
// Best to let a thread run itself out
// if (mThread != null)
// mThread.interrupt();
// Don't need this for this applet, but possibly later
// public Dimension getPreferredSize() {
// return new Dimension(300,70);
private void adjust() {
int delta = getMaximum() / 40;
mValue += delta * (mUp ? 1 : -1);
if (mValue >= getMaximum()) {
mValue = getMaximum();
mUp = false;
} else if (mValue <= 0) {
mValue = 0;
mUp = true;
SwingUtilities.invokeLater(updater);
Maybe you are looking for
-
Can I use SubPanels to display and run multiple executables from the same GUI?
I have two Labview executables that performs some A/D I/O, each using an independent USB-6008. I would like to run both of these executables from a single UI. Is this possible usin SubPanels? Or some other method? I found KB regarding exe's and VI
-
hi, i have tryed to install os x leopard, (its a old imac) , disk utility is greyed out , my install dvd cant find any hdd to install on , my only way to format and configure is through terminal but dont know what commands to execute... i tryed diffr
-
Org determination from Sales area
Guys, Here's the scenario..we have downloaded all Org structure from R/3. I need the sales org, sales office & group to be determined from the sales area maintained in the BP master data. Currently all BP's have only one Sales Area assigned. The stru
-
Setting multiple text dynamically on the GUI
HI, I have this function which computes the position record of 6 requests. ( ie x,y,dx,dy--these are the position records for a request) I want to display these position records in a textfield, which i have in my GUI, as soon as i press the "position
-
Hi all. I need a popup quite similar to POPUP_TO_DECIDE_LIST, but I need to be able to choose more than one item from the list. Does anyone have a suggestion which popup to use? Thanks in advance!