Java – How to get string value from one Frame to another

javajframestringswing

I made little application and I need help for one I think easy thing but am stack atm with it.
There are 2 Classes with JFrames . One is login and other I GUI and program that does something.Login is connected with Database and all how can I take value from textField where is username and when it passes verification to show up in other GUI class like USER : (name which u first wrote in login frame).

I tried with set get method to and add value to that string for example

String s = textField.getText().toString();

But when I call get method in GUI nothin happens.

Best Solution

try this one to pass data:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class PassData extends JFrame
{
    JTextField text;
    PassData(){
        JLabel l=new JLabel("Name: ");
        text=new JTextField(20);
        JButton b=new JButton("Send");
        setLayout(null);
        l.setBounds(10,10,100,20);
        text.setBounds(120,10,150,20);
        b.setBounds(120,40,80,20);
        add(l);
        add(text);
        add(b);
        setVisible(true);
        setSize(300,100);
          b.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            String value=text.getText();
            NextPage page=new NextPage(value);
            page.setVisible(true);
            }
        });
    }
        public static void main(String[] args) 
    {
        new PassData();
    }
}

try this code for next page:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class NextPage extends JFrame
{
  NextPage(String st)
   {
     setLayout(null);
     setDefaultCloseOperation(javax.swing. WindowConstants.DISPOSE_ON_CLOSE);
     setTitle("Welcome");
     JLabel lab=new JLabel("Welcome  "+st);
     lab.setBounds(10,10,500,20);
     add(lab);
     setSize(300, 100);
      }
 }