Marcel Krammer
Marcel Krammer

Reputation: 1

Dynamic Java.swing Menu

I have a special problem in coding a dynamic menu in Java.

What I want: I want a menubar that looks for special files (example: addon01_men.class) and adds the content of this file to the menu as a new item.

Problem: To invoke the methode/class in the file, I've to invoke it in the main file. But the addon-class is needed in this case, because java checks the presence of the methode/class. So the program will not start, if "addon01_men.class" is missing.

My solutions didn't work (perhaps in my fault): - Reflections - Override

I don't want to use dynamic classes because it's necessary to compile when the program starts - because not all PCs that can run java, can compile java.

I'd be pleased when someone has a working idea. Thank you.

Upvotes: 0

Views: 587

Answers (1)

Pedro Nunes
Pedro Nunes

Reputation: 420

You should start simple like this example using Reflections:

http://www.mkyong.com/java/how-to-use-reflection-to-call-java-method-at-runtime/ For want you want, you need look for a directory containing the class files like addon01_men.class (think like they're plugins), load them and create instances.

Upvotes: 1

Related Questions