Running a Java executable class from another executable class
I am programming with Java and have 2 executable classes, win.class and programManager.class. Both have main() methods and are executable. I want to execute programManager.class from win.class. Can this be done, and if so, what command would I use to do it in my win.java file? All .java and .class files are in the same directory.
|
Have a look here:
Classloader You'll want to use ClassLoader.getSystemClassLoader(); rather than the ClassLoader example they use. Pretty interesting stuff. |
You can also simply call the other class main method from the first one.
Code:
public class win |
answer
hello LUB997 ...
i just wanted to ask if u know what is Object-Oriented Programming ?? i don't realy know what your program supposed to do , but u could change your design and insted of using the static main method , u just could create object of that specific class and send it messeges so that it will respond the way u like ... .. .((( modularity is important thing for programmer ))) modularity is : ---->> A quality of a system where it consists of various parts which separate cleanly and fit together well. High modularity costs some design time but pays back well through clarity, elegance, maintainability and -->> FLEXIBILITY <<-- . good luck , :-) |
another small thing ... .. .
Quote:
it should be like this ... .. . Code:
public class win good luck , :-) |
Hi mohama,
I tried your example, but it compiles neither, here's what I got: Code:
win.java:3: illegal start of type |
I got it to work a different way. I finally figured out how to apply the example in my Java book to my own program and ended up using a package. I just put "package win.manager" at the top of my source file for programManager.java and then on win.java did "import win.manager" and then to call my programManager method from my programManager.class stored in win.manager I just did "programManager();" in my win.java source file. Worked beautifully, but it took me a while to figure out since I don't know a whole lot about Java or object oriented programming yet. I've taken a year of C# in school, but we still haven't really gotten into the object oriented aspects of it yet. For those wondering what kind of program I am making, I am making a Windows for Workgroups 3.11 clone in Java. Not for any particular purpose, but mainly just for the sake of doing something complicated to advance my programming skills, but not so complicated that I can't do it. It of course will not be able to run Windows 3.1 programs, but will just be the Windows 3.1 GUI. win.java is my main screen (the background), and programManager.java is just that; the program manager. As anybody who remembers the DOS days recalls, you used to type "win" from the command prompt to start Windows 3.1. With mine you type "java win" from the bash prompt. If anybody's interested in it, I'll gladly share the sourcecode on it when it's finished, but not until then because the idea here is for me to learn something after all, and not just have others do it for me. Once I succeed at creating it in Java I will then try something more complicated and Linux oriented such as C and maybe GTK or QT for the graphics. My real goal is to create Linux programs, and thus I am really more interested in C than Java, but in this case I chose Java because you can do a lot with it fairly easily, and this is my first run with a program that has a detailed GUI, so I didn't want to use a language that would complicate things too much for me. Thanks for all the responses!
|
hi jlliagre .. .
Quote:
an other thing , there is nothing for this to do with object oriented programming , Quote:
good luck .... LUB997 bye, |
Mohama, please think twice before posting, read again this thread and see that you started with this inappropriate comment:
Quote:
I used an ellipsis (three dots) in my sample code to represent parts unrelated with the demonstration, "programManager.main(args);" can be used from anywhere inside the win class. The sample code you posted is not adding anything, but on the opposite seems to limit the main call from the local main, which is wrong. I was hoping you take my previous posting with humour, but am disappointed and sorry you missed it ... |
hellooooo
Quote:
Quote:
bye ;~)) |
Quote:
|
ahaaa
and how is that ???
inner class ??? if yes then this thread become with no mean , the perpuse of this forum is to help others and not ... .. . so ... bye , |
Hi,
Can you state the purpose of the program and what it will be doing. In Software Engineering/and Hardware Engineering, we are taught that design is the most important step to coding/or simulations. A universal truth. Please let me know and you *may* rework the design if needed. If you are invoking main within a main, it may be time to look at design, as that is not a very common case (never seen a need for that one in all my years programming, but there *could* be, I guess. This all depends on the design). |
And,.... Yes.. I would use an object oriented approach as suggested. Java lends itself to this nicely. But, all depends on design requirements.
|
Quote:
Quote:
Quote:
Quote:
|
All times are GMT -5. The time now is 12:56 PM. |