Hi,

I have a frame and it contains some different JInternal frames.

I have a request that some people want some of these frames to be free floating, and not confined within a desktop.

Is there any way to do this with JInternal frames? Or is there any way to make the outer desktop not visible so the JInernal frames appear to float? If i did this latter idea i was thinking of a toggle to turn it on and off. That way they could get the desktop back when they needed to access the menu.

the final idea is i could just convert 2 of these JInternal frames to JFrame. and that brings up my question on pre processing. In c++ i can use preprocessor stuff to dictate which code runs when i compile.

i.e. depending on some variable i set, when compiling it would run one or the other line here:

class myclass extends JInternalFrame

or

class myclass extends JFrame

this would let me maintain two different types of code on run or compile that would hit without resorting to commenting in and out code in a bunch of spots.

thanks
Mike

Java does not have/needs preprocessor directives as C/C++ has

no macro, no #define

so no preprocessor that's it

clearly there is a need. i just outlined the need. i got users on mac windows and linux and what they are looking for can be different and i don't want to maintain separate code files. that was the need.

Mac users are used to free floating windows. i've talked to a number. Windows users are not. windows users are happy with a desktop containing the windows.

Mike

clearly there is a need. i just outlined the need.

Means and ends. You don't need a preprocessor, you need a technique for getting your program to exhibit the behavior you want. The preprocessor is the means you'd use in C++, that's all. In java you'd do this a bit more object-style.

If JFrame and JInternalFrame both support the methods you need, you might try making an adapter of some sort. Off the top of my head, the simpest version of what I'm thinking would be something like:

public Component makeWindow(boolean switch)
{
if (switch)
JFrame window = new JFrame();
else
JInternalFrame window = new JInternalFrame();

//build your window

return window;
}

Then cast the returned Component to JFrame or JInternalFrame on return. This isn't really an adapter, it's just a method that makes use of the fact that the two classes have the same methods that do the same things. I don't know how true this is, I haven't done any research on that part, but if it is the case, then this should work. If you think you can actually use the same code for the two classes, then this would be the first thing I'd try.


If you want to get really enterprisey, you could actually write an adapter, but that would probably be a bit of a job and I don't know if it would gain you much. Depends on the classes, I guess. If you find that the two classes have similar capabilities with different names, this starts to make sense.

Looking at that again - you're wanting to extend. Probably you'd have to write an adapter in that case.

He could just as easily extend JPanel and plug those into whatever top-level frames he wants to use for the OS.

Well, there you go making sense again. Yeah, do what he said. :)

thanks for suggestions. some ideas to think about.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.