The relationship between two different JFrames?

Hello, you may have heard of GIMP or something like that using different frames. Like full gui, so I was wondering how to make such frame messages when both (possibly several) frames are loaded into memory and visible.

I looked through some articles, but they were not so satisfactory, if anyone has a good example or tutorial, please share.

Alok Sharma Relations

+3
source share
3 answers

Basically, this is just a question of whether there is a link to frame A in frame B and a link to frame B in frame A:

public class FrameA extends JFrame {
    private FrameB frameB;

    public void setFrameB(FrameB frameB) {
        this.frameB = frameB;
    }

    public void foo() {
        // change things in this frame
        frameB.doSomethingBecauseFrameAHasChanged();
    }
}

public class FrameB extends JFrame {
    private FrameA frameA;

    public void setFrameA(FrameA frameA) {
        this.frameA = frameA;
    }

    public void bar() {
        // change things in this frame
        frameA.doSomethingBecauseFrameBHasChanged();
    }
}

public class Main {
    public static void main(String[] args) {
        FrameA frameA = new FrameA();
        FrameB frameB = new FrameB();
        frameA.setFrameB(frameB);
        frameB.setFrameA(frameA);
        // make both frames visible
    }
}

( ..) , , .

+6

"" "" MVC, , .

, JFrame , . , .

+1

, NetBeans (RCP Swing-bsed), . TopComponets, .

You can communicate between TopComponents and modules through an instance of Lookup.

+1
source

Source: https://habr.com/ru/post/1794914/


All Articles