Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-01-2009, 08:19 AM
Member
 
Join Date: Feb 2009
Posts: 51
Rep Power: 0
santhosh_el is on a distinguished road
Default Regarding issue in frame window
dear sir,

i am developing a frame window in that i have textfield and button ,suppose i am developing another window,when i press the button in first frame window the entered data in textfield should be displayed in another window textfield.it is possible.i need a code.

thanks
santhosh babu
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 06-01-2009, 09:10 AM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class WindowTalk {
    JDialog dialog;
    JTextField dialogField = new JTextField(12);

    private JPanel getContent() {
        final JTextField textField = new JTextField(12);
        JButton button = new JButton("send data");
        ActionListener al = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String text = textField.getText();
                dialogField.setText(text);
                if(dialog.isVisible()) {
                    dialog.toFront();
                } else {
                    dialog.setVisible(true);
                }
            }
        };
        textField.addActionListener(al); // Enter key
        button.addActionListener(al);
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(wrap(textField), "First");
        panel.add(wrap(button), "Last");
        return panel;
    }

    private JPanel wrap(JComponent c) {
        JPanel panel = new JPanel();
        panel.add(c);
        return panel;
    }

    private void showDialog(Frame f) {
        dialog = new JDialog(f, "Dialog", false);
        dialog.add(wrap(dialogField), "First");
        dialog.setSize(200,100);
        dialog.setLocation(390,100);
        dialog.setVisible(true);
    }

    private JTextField getTextField(Container parent) {
        Component[] c = parent.getComponents();
        for(int i = 0; i < c.length; i++) {
            //System.out.println(c[i].getClass().getSimpleName());
            if((Container)c[i] instanceof JTextField) {
                return (JTextField)c[i];
            }
            if(((Container)c[i]).getComponentCount() > 0) {
                return getTextField((Container)c[i]);
            }
        }
        return null;
    }

    public static void main(String[] args) {
        WindowTalk test = new WindowTalk();
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(test.getContent());
        f.setSize(240,150);
        f.setLocation(100,100);
        test.showDialog(f);
        f.setVisible(true);
        test.getTextField(f).requestFocusInWindow();
    }
}
For more information see Trail: Creating a GUI with JFC/Swing.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
i want to display decimal values in frame window santhosh_el AWT / Swing 4 03-16-2009 10:07 AM
GUI new frame billbo123 New To Java 15 03-02-2009 05:24 AM
frame arunkumarinfo NetBeans 0 02-07-2009 11:26 AM
Read/Write of components of frame window Harish kumara M AWT / Swing 0 09-17-2008 09:14 AM
Frame to other Frame Aswq New To Java 2 07-19-2008 05:27 PM


All times are GMT +2. The time now is 09:36 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org