> How do i get the JTextField of Main class value to second class
> i want to display value in JTextField in secondclass
your attempt at doing it, tries to get the value of second() to Main(),
so I've changed the code to do that (modify if you want it the other way around)
(code tags pointless)
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
class Main
{
JFrame jf;
JTextField jt;
void form()
{
jf=new JFrame("
test");
Container cp=jf.getContentPane();
cp.setLayout(null);
jt=new JTextField();
cp.add(jt);
jt.setBounds(50,50,100,30);
jf.setSize(400,200);
jf.setVisible(true);
jf.setResizable(false);
}
}
class second implements ActionListener
{
JFrame jf;
JTextField jt;
JButton jb;
Main m;
public static void main(String args[])
{
second s=new second();
s.form();
}
void form()
{
jf=new JFrame("test");
Container cp=jf.getContentPane();
cp.setLayout(null);
jt=new JTextField();
jb=new JButton();
jb.addActionListener(this);
cp.add(jt);
cp.add(jb);
jb.setBounds(180,180,50,50);
jt.setBounds(50,50,100,30);
jf.setSize(400,400);
jf.setVisible(true);
jf.setResizable(false);
}
public void actionPerformed(ActionEvent ae)
{
m=new Main();
m.form();
m.jt.setText(jt.getText());
}
}
also note you can set the textfield's documents the same, so that changes in either are reflected in the other.