Results 1 to 3 of 3
- 08-16-2012, 02:47 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
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());
}
}
}
- 08-16-2012, 03:56 PM #2
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?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
-
Re: communication between two JInternalFrames
Similar Threads
-
Communication Lag :(
By MuslimCoder in forum NetworkingReplies: 6Last Post: 03-11-2010, 07:30 PM -
UDP Communication
By ls_venkat in forum NetworkingReplies: 0Last Post: 10-15-2009, 05:47 AM -
Communication to PC
By Dan_68c in forum Sun Java Wireless ToolkitReplies: 0Last Post: 09-30-2009, 04:01 PM -
Jar and War communication in an Ear
By madanmohanp in forum Advanced JavaReplies: 1Last Post: 08-02-2008, 01:39 PM -
loading JInternalFrames
By vishakha in forum AWT / SwingReplies: 5Last Post: 07-23-2008, 03:58 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks