Results 1 to 2 of 2
  1. #1
    santhosh_el is offline Member
    Join Date
    Feb 2009
    Posts
    50
    Rep Power
    0

    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

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java 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.

Similar Threads

  1. i want to display decimal values in frame window
    By santhosh_el in forum AWT / Swing
    Replies: 4
    Last Post: 03-16-2009, 10:07 AM
  2. GUI new frame
    By billbo123 in forum New To Java
    Replies: 15
    Last Post: 03-02-2009, 05:24 AM
  3. frame
    By arunkumarinfo in forum NetBeans
    Replies: 0
    Last Post: 02-07-2009, 11:26 AM
  4. Read/Write of components of frame window
    By Harish kumara M in forum AWT / Swing
    Replies: 0
    Last Post: 09-17-2008, 09:14 AM
  5. Frame to other Frame
    By Aswq in forum New To Java
    Replies: 2
    Last Post: 07-19-2008, 05:27 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
  •