I would like to make a program where I can add something like "plug-ins". Lets say I have Project1
where I have JFrame
and Project2
where I have JPanel
.
The point is, that user can develop his own programs (plug-ins) and than add it to the main program ( Project1
).
So... I export frame as runnable JAR file and export panel as runnable JAR file (or only as JAR file?).
What I want to do is to show panel in frame.
Simply I want to do something like this or this but only in Java and with panel, I don't need to run any .exe programs. (It's going to run on Linux not Windows).
My professional picture that should describe what I want to do :) image
Is there some way to do this?
For the plugin part, you can look at this project that I created, the loadPlugin method loads plugins from jar files.
And for the JPanel part, you just have to let to plugins a way (an API surely) that lets them change the displayed panel of the JFrame (with JFrame::setContentPane ). I hope that'll help you, ask me for more precision if you need.
Edit:
As an example you can get the JPanel from the .jar and instantiate it like this :
URLClassLoader classLoader = new URLClassLoader(new URL[]{file.toURI().toURL()}, Thread.currentThread().getContextClassLoader());
String packageName = "package.where.is.the.jpanel.to.load";
JPanel jpanel = (JPanel) Class.forName(packageName, true, classLoader).getConstructor().newInstance();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.