title: Get String of a main function from another class
body: <p>I have this main function (Class: <code>DialogBoxForIt.java</code>):</p>
  
  <pre><code>public void main(final SimpleCallback&lt;HashMap&lt;SPARAM, Object&gt;&gt; sr) {
      if(mainwindow == null){
          JFrame jf = new JFrame();
          jf.setTitle(_T.PasswordEncrypt_title.val());
          jf.setResizable(false);
          jf.setIconImages(ResourceCenter.icons);
          jf.getContentPane().setLayout(new BoxLayout(jf.getContentPane(), BoxLayout.Y_AXIS)); 
          jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          thiswindow = jf;
      }
      else{
          JDialog jd = new JDialog(mainwindow);
          jd.setModal(true);
          jd.setTitle(_T.PasswordEncrypt_title.val());
          jd.setResizable(false);
          jd.setIconImages(ResourceCenter.icons);
          jd.getContentPane().setLayout(new BoxLayout(jd.getContentPane(), BoxLayout.Y_AXIS)); 
          jd.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          thiswindow = jd;
      }
  
      JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
      JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
      JPanel lineok = new JPanel(new GridBagLayout());
      JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
      final JPanel lineopt = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  
      final JPasswordField tf = new JPasswordField();
      tf.setPreferredSize(new Dimension(200, 25));
  
      final JPasswordField tf2 = new JPasswordField();
      tf2.setPreferredSize(new Dimension(200, 25));
  
      final JTextField jtf = new JTextField(""+CryptoCodes.STANDARD_PBKDF2_ITERATIONS); 
  
      JButton b = new JButton("OK");
  
      ActionListener act = new ActionListener(){
          @Override
          public void actionPerformed(ActionEvent e) {
              char[] s1 = tf.getPassword();
              char[] s2 = tf2.getPassword();
  
              if(s1 == null || s2 == null || s1.length == 0 || s2.length == 0)
                  return;
  
              int minlen = CryptoCodes.STANDARD_PBKDF2_PWLEN;
  
              tf.setText(DUMMYTEXT);
              tf2.setText(DUMMYTEXT);
  
              tf.setText("");
              tf2.setText("");
  
              if(Arrays.equals(s1, s2) &amp;&amp; s1.length &gt;= minlen){
                  thiswindow.dispose();
                  CryptoUtils.kill(s2);
  
                  char[] passw = PasswordGenerator.GenerateRandomString(18,25,3,1,1,1).toCharArray();
                  String passwds = String.valueOf(passw);
                  try {
                      passwds = new String(passw);
                  } catch (IOException e1) {
                      // TODO Auto-generated catch block
                      e1.printStackTrace();
                  }
  
  
  
                  myParams.put(SPARAM.password, passwds.toCharArray());
  
                  System.out.println("let test -- "+String.valueOf((char[])myParams.get(SPARAM.password))) ;
  
  
                  if(lineopt.isVisible()){
                      String tmp = jtf.getText();
                      if(FilterNumbers.validate(tmp)) myParams.put(SPARAM.itcount, tmp);
                  }
                  sr.callbackValue(this, myParams);
              }
              else{
                  CryptoUtils.kill(s1);
                  CryptoUtils.kill(s2);
                  tf.requestFocus();
  
                  if(s1.length &lt; minlen)
                      JOptionPane.showMessageDialog(thiswindow, _T.PasswordEncrypt_len.msg(minlen));
                  else
                      JOptionPane.showMessageDialog(thiswindow, _T.PasswordEncrypt_nomatch);
              }
          }
      };
  
      b.addActionListener(act);
      tf.addActionListener(act);
      tf2.addActionListener(act);
      jtf.addActionListener(act);
  
      JLabel jl = new JLabel(_T.PasswordEncrypt_label + ": ");
      line1.add(jl);
      line1.add(tf);
      thiswindow.add(line1);
  
      jl = new JLabel(_T.PasswordEncrypt_retype + ": ");
      line2.add(jl);
      line2.add(tf2);
      thiswindow.add(line2);
  
      b.setPreferredSize(new Dimension(200, 35));
      GridBagConstraints gbc = new GridBagConstraints();
      gbc.insets = new Insets(5, 5, 5, 5);
      gbc.fill = GridBagConstraints.BOTH;
      gbc.weightx = gbc.weighty = 1.0;
      lineok.add(b, gbc);
      thiswindow.add(lineok);
  
      javax.swing.ToolTipManager.sharedInstance().setDismissDelay(7000);
  
      ((PlainDocument) jtf.getDocument()).setDocumentFilter(new FilterNumbers());
      jtf.setPreferredSize(new Dimension(200, 25));
      jtf.setToolTipText(_T.PasswordEncrypt_itcountdescr.val());
      jl = new JLabel(_T.PasswordEncrypt_itcount + ": ");
      jl.setToolTipText(_T.PasswordEncrypt_itcountdescr.val());
      lineopt.add(jl);
      lineopt.add(jtf);
  
      final JButton jb = new JButton(new ImageIcon(ResourceCenter.optsup));
      line3.add(jb);
      thiswindow.add(line3);
  
      thiswindow.add(lineopt);
      lineopt.setVisible(false);
  
      jb.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
              if(lineopt.isVisible()){
                  lineopt.setVisible(false);
                  jb.setIcon(new ImageIcon(ResourceCenter.optsup));
              }
              else{
                  lineopt.setVisible(true);
                  jb.setIcon(new ImageIcon(ResourceCenter.optsdown));
              }
  
              thiswindow.pack();
          }
      });
  
      thiswindow.pack();
  
      thiswindow.setLocationRelativeTo(mainwindow);
      thiswindow.setVisible(true);
  
      thiswindow.addWindowListener(new WindowAdapter() {
          @Override
          public void windowClosed(WindowEvent e) {
              try {
                  tf.setText(DUMMYTEXT);
                  tf2.setText(DUMMYTEXT);
  
                  tf.setText("");
                  tf2.setText("");
              } catch (Exception ex) {}
          }
      });
  
      if(Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK)){
          JOptionPane.showMessageDialog(thiswindow, _T.Password_caps);
      }
  }
  </code></pre>
  
  <p>I call this main function from another class like this (The other class name: <code>AppTest.java</code>):</p>
  
  <pre><code>new DialogBoxForIt(currentSource).main(this);
  </code></pre>
  
  <p>I want get the passwds String of main function from this class.</p>
  
  <p>How to do that please ?</p>
  
  <p>What changes i must apport in order to get it there ?</p>
  
  <p>You must know that passwds String contain a random generated password, and must be transfered to the other class for another use.</p>
  
  <p>I tried to add public string (<code>public String passwpub = ""</code>) and then inside the function (<code>passwpub = passwds;</code>), but can't get it from the other class.</p>
  
  <p>If you have any idea will be highly appreciated.</p>
  
  <p>Thank you !</p>