wrapping a jframe - java

is there a way to open a program, that usually opens a new jframe, into an existing jframe?
here is the explanation, I have downloaded a java game one of those reflexes ones and it opens in a jframe with a bunch of sub panels inside of the frame, what i want to do is wrap the existing jframe in another frame or canvas or something so i can build internal scripts for it as apposed to building external scripts that require screenshots and getting pixel data. by internal scripts i mean scripts that run inside the new jframe

The usual way to achieve custom functionality would be to extend the class and override methods to add new/altered components and & new/altered methods.
OTOH I doubt that someone who refers to Java code as 'internal scripts' has the experience needed for this task. It would be better to start with simpler goals.

Related

What's the right way to go from one form to another?

I am doing a school java project using the NetBeans IDE. It includes some basic database manipulations. We were taught at school to use the following for linking one form to another:
new <form_name>().setVisible(true)
But this seem to slow down the whole application and there is a small lag for going from one form to another. I heard that using JDialog boxes is a solution to this problem.
So what's the right way to do it?
Better to not swap in and out of different JFrames. How many professional applications such as word processors do you use that do this that throw different windows at the user? Better to use one main JFrame and swap views (usually JPanels) in it via a CardLayout and occasionally show a dependent Window as a dialog when needed, especially when you need to get information in a modal way.
some basic database manipulations. .. But this seem to slow down the whole application
Don't block the EDT (Event Dispatch Thread) - the GUI will 'freeze' when that happens. Instead of calling Thread.sleep(n) implement a Swing Timer for repeating tasks or a SwingWorker for long running tasks. See Concurrency in Swing for more details.
(But also see #Hovercraft's advice re. CardLayout..)

JNLP - application-desc vs applet-desc - is one better than the other when not running in browser?

I have an applet which I no longer want to run in the browser - but in stead want to run as a downloadable, auto-updating, oflineable Java application via JNLP.
I do not want to maintain the ability to run it as an applet.
I have no problem with either wrapping the existing applet in a JFrame and a main-menthod, or simply rewriting it and replacing the init() and others all together.
But my question is:
Are there any advantages or disadvantages to to using application-desc vs applet-desc?
The first advantage of converting to JFrame based, is that you have immediate control of the top level container for things like:
menus
look & feel
default close operation
location
size by pack() (hooRAY!)
..
Go with applicaton-desc for a free floating deployment. But don't put the applet in a frame, instead put the applet content into a panel, and put the panel into the frame (or applet, or window, or..).

How should I efficiently update a Swing GUI?

I created a program with a Swing GUI in NetBeans a while back using the Graphical Editor. I now needed a web version but since I use eclipse now I copied + pasted the code into a new Web Applet project. I found some problems I didn't spot before and updated the code in the web applet.
I want to add some buttons to the GUI, but one problem is its an annoyance to find the part of the code where NetBeans put all the variable declarations, then find another part of the code where all the fields are initialised, then find the other part of the code where the layout needs to be defined, then find the other part of the code where all the action listeners are added, etc... Another problem is that the Swing layouts are complex and also an annoyance to hard code... it is difficult to judge what the exact outcome will look like when you have to edit GroupLayouts with other swing components already layed out in them.
Also, I can't edit this in NetBeans because the Generator is very fussy and if I copy+paste code in there it wont read it as a Java Form nor generate an XML file which I think it uses to manage your layout.
Are there any free GUI designers out there that take a bunch of java swing code and allow you to graphically edit it? How do professionals manage their graphical layouts?
So I should have implemented the Model-View approach from the start.
Here is a nice tutorial on the subject:
http://people.csail.mit.edu/phw/OnToJava/ONTOJAVA755.HTML

Embedding a JFrame in an Applet

I have found an open source application that creates a JFrame to display some content. I would like to "embed" this JFrame into an applet, so everything that is displayed in the Jframe will be displayed in the applet - is this possible?
Thanks for your help!
Create an instance of the frame.
Get the content pane of the frame.
Add the content pane to the applet.
..open source application that creates a JFrame..
Since the source is available, take whatever they do in the frame, and do that instead in an applet (with some slight variants & gotchas).
Some typical problems with using the frame content in an applet are that:
The programmers might have set the GUI visible in the constructor, meaning you cannot get access to the content pane without showing a free floating GUI element on-screen.
Custom painting direct to the frame (eeek). There's no getting that stuff. But then, any programmer that incompetent should not be 'open'ing their source in the first place.
A frame programmer would typically use EXIT_ON_CLOSE as an exit behavior for the frame. It is not permitted (or necessary) for a sand-boxed applet to end the VM. Even a trusted applet would (and should) normally be prevented from calling System.exit(int).
Frame based code often does things that either require trust in an applet, or alternate strategies to achieve the same goal.
Points 3 & 4 are less applicable/relevant if the frame was designed to be launched using web start. And since I mention webstart..
Note that it is generally easier to 'convert' a frame to be launched using Java Web Start than it is either to create and deploy an applet, or to convert a frame to an applet. Unless there is some functionality of an applet that is vital & not available to an application (which is unlikely, given you started with the application), I would recommend launching the app. via JWS, rather than doing a conversion.

Seek a Java advanced tree component (include Windowless Richedit Control function)

I love BooguNote very much (it's a Sharp tool for collecting and organizing information scraps) But what a pity it just run under windows currently.
I tried to build a Java version for BooguNote so I can run it under linux (first step: I want to just make a simple BooguViewer ) since I'm not very familiar with so huge Java libraries, so I ask for help who know the suitable Java tree component in this case.
My requirement is this:
it's not an usual tree component, as you can check from the BooguNote's screenshot as below:
http://boogu.me/en.jpg
Usual tree is used as an outline, but in BooguNote, tree node was used as a content container at the same time - you can even save a huge text in it! (I heard the author said in the forum before he used "Windowless Richedit Control" technology).
Any advices are welcome, Thanks in advance.
This Oracle tutorial tells you how to create graphical user interfaces (GUIs) for applications and applets, using the Java Swing components.
Start with the Using Swing Components tutorial. Go through the following top-level lessons:
Using Top-Level Containers
The JComponent Class
Using Text Components
Go through the following component lessons:
How to Make Frames (Main Windows)
How to Use Panels
How to Use Trees
The Swing components that you want to use to make a viewer are JFrame, JPanel, and JTree.

Categories