Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Problem with classloader

Thread view: 
jerry - 26 Oct 2007 04:51 GMT
[code]
Class[] argTypes = { String[].class };
java.lang.reflect.Method method =
ClassLoader.getSystemClassLoader().loadClass(className).getDeclaredMethod("main",
argTypes);
Object[] args = { new String[0] };
method.invoke(null, args);
[/code]

what is wrong with this code? i have a java application (JPanel) and
it work as a main window and then, im trying to launch a java
application (JFrame) but when i close the JFrame window, the main
window also terminated.

is somebody know this?

thanks.
Andrew Thompson - 26 Oct 2007 07:49 GMT
...
>..i have a java application (JPanel) and
>it work as a main window and then, im trying to launch a java
>application (JFrame) but when i close the JFrame window, the main
>window also terminated.
>
>is somebody know this?

Look at the method
javax.swing.JFrame.setDefaultCloseOperation(int).
The default is JFrame.DO_NOTHING_ON_CLOSE, but I
suspect your IDE has other 'ideas'.

By the way.  Sentences in English should start with a single
Upper Case letter to help the reader tell where they start and
end.  Also, the word I or the abbreviation I'm, should also start
with upper case. 'I' is always upper case.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

jerry - 30 Oct 2007 10:23 GMT
> ..
>
[quoted text clipped - 19 lines]
>
> Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1

Thank you for correction, I really appreciate it.

I tried the code above and it seems work to me. But my problem is,
I've created a program that will launch
application from jar file, so means I don't have access on it. This
jar file is a collection
of window application.

If the application(JFrame/Other Object) has this code:
(probably a child window)
    addWindowListener(new java.awt.event.WindowAdapter() {
           public void windowClosing(java.awt.event.WindowEvent evt)
{
               System.exit(0);
           }
       });
the main window (Launcher) exit too.
Andrew Thompson - 30 Oct 2007 10:41 GMT
...
>I tried the code above and it seems work to me. But my problem is,
>I've created a program that will launch
>application from jar file, so means I don't have access on it. This
>jar file is a collection
>of window application.
...
>                System.exit(0);
...
>the main window (Launcher) exit too.

Unless you implement an 'ExitManager'* to prevent
the other applications from doing that.

*
<http://groups.google.com/group/comp.lang.java.programmer/msg/f29ab45389d9f5f2

Whether the other apps. handle that gracefully is
another matter.  You may need to explicitly
setVisble(false) and take other measures.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Andrew Thompson - 30 Oct 2007 10:54 GMT
>...
>>I tried the code above and it seems work to me. But my problem is,
[quoted text clipped - 8 lines]
>
>Unless you implement an 'ExitManager'* ...

Or, I realise now as I reread Arne's reply, start the other
apps. in entirely new Process(es).

OTOH - I think the current approach using the code you
have + an ExitManager,  has more control over the resulting
application.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

jerry - 30 Oct 2007 14:56 GMT
> Look at the method
> javax.swing.JFrame.setDefaultCloseOperation(int).
[quoted text clipped - 8 lines]
> --
> Andrew Thompsonhttp://www.athompson.info/andrew/

Thank you for correction, I really appreciate it.

I tried the code above and it seems work to me. But my problem is,
I've created a program that will launch
application from jar file, so means I don't have access on it. This
jar file is a collection
of window application.

If the application(JFrame) has this code:
(probably an application that will launch from main window)
    addWindowListener(new java.awt.event.WindowAdapter() {
           public void windowClosing(java.awt.event.WindowEvent evt)
{
               System.exit(0);
           }
       });
the main window (Launcher) exit too.
Arne Vajhøj - 27 Oct 2007 18:00 GMT
> [code]
> Class[] argTypes = { String[].class };
[quoted text clipped - 9 lines]
> application (JFrame) but when i close the JFrame window, the main
> window also terminated.

The two "things" are running in the same process. If closing the
JFrane result in a a call to System.exit, then the entire process
is exited.

But you can control that - see Andrews posts for some Swing hints.

Arne
Roedy Green - 27 Oct 2007 21:44 GMT
>ClassLoader.getSystemClassLoader().loadClass(className)

would you not normally code that as
Class.forName( className )
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Daniel Pitts - 28 Oct 2007 00:38 GMT
>> ClassLoader.getSystemClassLoader().loadClass(className)
>
> would you not normally code that as
> Class.forName( className )
Not if you wanted it to be loaded by a specific ClassLoader

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.