title: How to pass a string value from a java class to another
body: <p>i want to pass a string value from the Login.java to homeframe.java when i press the login button. I don t understand what should i write and in which part. I tried to create a method -with a return- and call it in the 2nd class, but it didn't work.</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.awt.font.TextAttribute;
  import java.util.Map;
  
  public class Login extends JFrame {
  
  public static void main(String[] args) {
  Login frameTabel = new Login();
  }
  
  JButton blogin = new JButton("Login");
  JLabel bregister= new JLabel ("Register");
  JLabel luser=new JLabel("username: ");
  JLabel lpass=new JLabel("password: ");
  JPanel panel = new JPanel();
  JTextField txuser = new JTextField(15);
  JPasswordField pass = new JPasswordField(15);
  
  Login(){
  super("Login Authentication");
  setSize(260,400);
  setLocation(500,280);
  panel.setLayout (null); 
  
  luser.setBounds(10,40,80,20);
  txuser.setBounds(80,40,80,20);
  lpass.setBounds(10,70,80,20);
  pass.setBounds(80,70,80,20);
  blogin.setBounds(80,120,80,20);
  bregister.setBounds(190,5,80,20);
  bregister.setForeground(Color.blue);
  Font font = bregister.getFont();
  Map attributes = font.getAttributes();
  attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
  bregister.setFont(font.deriveFont(attributes));
  
  panel.add(blogin);
  panel.add(txuser);
  panel.add(pass);
  panel.add(bregister);
  panel.add(luser);
  panel.add(lpass);
  
  getContentPane().add(panel);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setVisible(true);
  actionlogin();
  mouseactionlabel();
  
  }
  
  void mouseactionlabel(){
  bregister.addMouseListener(new MouseListener() {
  public void mouseClicked(MouseEvent arg0) {
  registerFrame regFac =new registerFrame();
  regFac.setVisible(true);
  dispose();
  }
  public void mouseEntered(MouseEvent arg0) {
  }
  public void mouseExited(MouseEvent arg0) {
  }
  public void mousePressed(MouseEvent arg0) {
  }
  public void mouseReleased(MouseEvent arg0) {
  }
  });
  }
  
  public void actionlogin(){
  blogin.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent ae) {
  String puname = txuser.getText();
  String ppaswd = pass.getText();
  if(puname.equals("test") &amp;&amp; ppaswd.equals("12345")) {
  homeframe regFace =new homeframe();
  regFace.setVisible(true);
  dispose();
  } else {
  
  JOptionPane.showMessageDialog(null,"Wrong Password or Username");
  txuser.setText("");
  pass.setText("");
  txuser.requestFocus();
  }
  
  }
  });
  }
  }
  </code></pre>
  
  <p>second class</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.awt.font.TextAttribute;
  import java.util.Map;
  
  public class homeframe extends JFrame {
  
  public static void main(String[] args) {
  homeframe frameTabel = new homeframe();
  }
  
  JLabel lsearch=new JLabel ("Search by name");
  JLabel lupload=new JLabel ("Upload a file");
  JPanel panel = new JPanel();
  
  homeframe(){
  super("Home");
  setSize(260,400);
  setLocation(500,280);
  panel.setLayout (null); 
  
  lsearch.setBounds(10,30,100,20);
  lupload.setBounds(10,60,80,20);
  
  lsearch.setForeground(Color.blue);
  Font font1 = lsearch.getFont();
  Map attributes = font1.getAttributes();
  attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
  lsearch.setFont(font1.deriveFont(attributes));
  lupload.setForeground(Color.blue);
  Font font2 = lupload.getFont();
  Map attributes2 = font2.getAttributes();
  attributes2.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
  lupload.setFont(font2.deriveFont(attributes2));
  
  panel.add(lsearch);
  panel.add(lupload);
  
  getContentPane().add(panel);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setVisible(true);
  mouseactionlabel();
  }
  
  void mouseactionlabel(){
  lsearch.addMouseListener(new MouseListener() {
  public void mouseClicked(MouseEvent arg0) {
  searchFrame regFac =new searchFrame();
  regFac.setVisible(true);
  dispose();
  }
  public void mouseEntered(MouseEvent arg0) {
  }
  public void mouseExited(MouseEvent arg0) {
  }
  public void mousePressed(MouseEvent arg0) {
  }
  public void mouseReleased(MouseEvent arg0) {
  }
  });
  
  lupload.addMouseListener(new MouseListener() {
  public void mouseClicked(MouseEvent arg0) {
  uploadFrame regFac =new uploadFrame();
  regFac.setVisible(true);
  dispose();
  }
  public void mouseEntered(MouseEvent arg0) {
  }
  public void mouseExited(MouseEvent arg0) {
  }
  public void mousePressed(MouseEvent arg0) {
  }
  public void mouseReleased(MouseEvent arg0) {
  }
  });
  }
  
  }
  </code></pre>