Java WIndows

I guess in Xojo I relied too much (always?) on windows being Implicit Instances.

So I’m playing with Java… and createing a single window app is fairly easy…

But say I have TWO (or more) Window classes

  • class window01 extends JFrame {
  • class window02 extends JFrame {

And in Main I want to START with window01, so yeah I need an INSTANCE

	 public static void main(String args [ ] ) {
         instance01 = new window01();

At what point do I create the INSTANCE of window02?
Say for example there is a button on Window01 … that should show Window02
and conversely there is a button on Window02 the should show Window01

the first time the button on Win1 is clicked there would be no Win2 instance… but after that it would be.

Should all the window instances be created up front??? This would possibly create window instances that may or may not be used in a given session?

Should the code in each button be aware of a null instance? (that means each window needs to be cognizant of certain aspects of the next window)

I have two classes. Let me say one is the Starter Class

public class Appstarter{
public static void main(String args){

And I have the Class with the Window Design, It is a Frame there I do

public class Guiclass extends JFrame{

public static void main(String args){

Guiclass frame = new Guiclass();

Inside of the GuiClass there is the init components method and so on. When calling the main method of the Guiclass I am building an instance of the Guiclass and it appears.

In Xojo an implicit Window is actually a function call, named the same name as the Window, that returns an instance of that window

   function Window2() as Window2
        static mWindow as Window2

        if mWindow is nil then
            mWindow = new Window2
        end if

        return mWindow

    end function

not sure if Java will let you do this

For perspective on this Aaron wrote this way back in 2007 when ImplicitInstance came into being

ImplicitInstance is evil.


It’s right there with global variables. :slight_smile:


That form of window Management is evil at all at least for a Java Programmer and for a C++ Programmer with QT.
Xojo isn’t strict at all and so it is possibly not that bad to do so

I advocated removing it or at least starting with that setting off
Would get rid of

Hey when I access this property on my window it shows on screen. Why ?

that is so frequently asked

Hi Dave,

Did you get an answer to your question? I am following this post closely and have been working on this exact question for a while, with no solutions yet.

Maybe someone has a simple working example of this?

The instance is not there. Normal would be: dispose on close. Therefore MVC Model of programming helps to prevent you from even thinking about. Inherit instances like in Xojo are not even needed to think about. They would even in Java be evil.

So I have a Controller Class holding my Data presented in page and filling the Data into the page which uses static variables holding my Data or non statics depends on the needs and filling the form.

Make your live less complex.