Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: communication between two JInternalFrames

  1. #1
    javaSweden is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default communication between two JInternalFrames

    I could not figure out how to send information from one JinternalFrame to another (when using different classes). I attach a simple example to illustrate my problem:

    I have one main class (MyInternalFrame13Aug) and two other classes that extends JInternalFrame class - InternalFrameA and InternalFrameB.

    I simply want to send a textstring generated from a JTextField in class InternalFrameA to the JTextField in class InternalFrameB. But the textstring from InternalFrameA does not show up in the other class - despite there is a relation between InternalFrameA and InternalFrameB.



    Would be very glad if someone could solve this problem.

    Cincerely

    Björn

    --------------------------------------------------------------------------------------------------------------------

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MyInternalFrame13Aug extends JFrame {

    private JDesktopPane desktop;
    private InternalFrameA IFrameA;
    private InternalFrameB IFrameB;
    private JPanel panel;

    public static void main (String[] args) {

    MyInternalFrame13Aug frame = new MyInternalFrame13Aug();
    frame.setVisible(true);
    }

    public MyInternalFrame13Aug() {

    setLocation(100, 100);
    setSize(800, 700);
    setTitle("FRAME HOLDING TWO INTERNAL FRAMES");

    panel = new JPanel();

    Container contentPane = getContentPane();

    desktop = new JDesktopPane();
    desktop.setBackground(new Color(227, 204, 226));
    desktop.add(panel);
    contentPane.add(desktop);

    IFrameA = new InternalFrameA();
    IFrameB = new InternalFrameB();

    desktop.add(IFrameA);
    desktop.add(IFrameB);

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    }

    }

    class InternalFrameA extends JInternalFrame implements ActionListener {

    private JTextField textField;
    private JButton okButton;

    public InternalFrameA() {

    setLocation(100, 100);
    setSize(300, 300);
    setTitle("FRAME A");

    textField = new JTextField();
    textField.setColumns(20);

    okButton = new JButton("OK");

    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(textField);
    contentPane.add(okButton);

    okButton.addActionListener(this);

    setVisible(true);

    }

    public void actionPerformed(ActionEvent e) {

    if ( e.getSource() == okButton) {
    System.out.println(textField.getText());
    }
    }

    public String getTextFrameA() {

    return textField.getText();

    }

    }

    class InternalFrameB extends JInternalFrame implements ActionListener {

    private InternalFrameA IFrameA = new InternalFrameA();;
    private JTextField textField;;
    private JButton okButton;

    public InternalFrameB() {

    setLocation(450, 100);
    setSize(300, 300);
    setTitle("FRAME B");

    textField = new JTextField();
    textField.setColumns(20);

    okButton = new JButton("OK");

    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(textField);
    contentPane.add(okButton);

    okButton.addActionListener(this);

    setVisible(true);

    }

    public void actionPerformed(ActionEvent e) {

    JButton clickedButton = (JButton) e.getSource();

    if (clickedButton == okButton) {

    System.out.println("The textstring generated from InternalFrameA is: " + IFrameA.getTextFrameA());
    textField.setText(IFrameA.getTextFrameA());
    }
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,928
    Rep Power
    16

    Default Re: communication between two JInternalFrames

    Moved from Advanced Java.

    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum

    You didn't bother to reply to 3 responses on your earlier thread. Why should we expect any better behavior this time round?

    db
    Fubarable likes this.
    Why do they call it rush hour when nothing moves? - Robin Williams

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,252
    Blog Entries
    1
    Rep Power
    24

    Default Re: communication between two JInternalFrames

    Quote Originally Posted by DarrylBurke View Post
    You didn't bother to reply to 3 responses on your earlier thread. Why should we expect any better behavior this time round?
    Thanks Darryl for the warning.

Similar Threads

  1. Communication Lag :(
    By MuslimCoder in forum Networking
    Replies: 6
    Last Post: 03-11-2010, 07:30 PM
  2. UDP Communication
    By ls_venkat in forum Networking
    Replies: 0
    Last Post: 10-15-2009, 05:47 AM
  3. Communication to PC
    By Dan_68c in forum Sun Java Wireless Toolkit
    Replies: 0
    Last Post: 09-30-2009, 04:01 PM
  4. Jar and War communication in an Ear
    By madanmohanp in forum Advanced Java
    Replies: 1
    Last Post: 08-02-2008, 01:39 PM
  5. loading JInternalFrames
    By vishakha in forum AWT / Swing
    Replies: 5
    Last Post: 07-23-2008, 03:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •