Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Password
    primarykey
    data
    text
    <p>I have a program in Java that has two classes, the Main class and the <code>appGUI</code> class.</p> <p>This is the Main class:</p> <pre><code>import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /** * @param args */ public static void main(String[] args) throws Exception { appGUI gui = new appGUI(); gui.setVisible(true); String password = ""; //The password entered... try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(password.getBytes()); System.out.println(new BigInteger(1, md.digest()).toString(16)); } catch(NoSuchAlgorithmException e) { e.printStackTrace(); } } } </code></pre> <p>And this is the appGUI class:</p> <pre><code> import java.awt.*; import java.awt.event.*; import javax.swing.*; /* * Created by JFormDesigner on Wed Apr 03 19:24:35 BST 2013 */ /** * @author Hrach Ghapantsyan */ public class appGUI extends JFrame { public appGUI() { initComponents(); } private void loginButtonActionPerformed(ActionEvent e) { // TODO add your code here } private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner Evaluation license - Hrach Ghapantsyan loginPasswordField = new JPasswordField(); loginUsernameField = new JTextField(); usernameLabel = new JLabel(); passwordLabel = new JLabel(); loginButton = new JButton(); titleLabel = new JLabel(); //======== this ======== setTitle("Experimental X | Administrator Login"); Container contentPane = getContentPane(); contentPane.setLayout(null); contentPane.add(loginPasswordField); loginPasswordField.setBounds(80, 65, 100, loginPasswordField.getPreferredSize().height); contentPane.add(loginUsernameField); loginUsernameField.setBounds(80, 35, 100, loginUsernameField.getPreferredSize().height); //---- usernameLabel ---- usernameLabel.setText("Username:"); contentPane.add(usernameLabel); usernameLabel.setBounds(20, 40, 55, usernameLabel.getPreferredSize().height); //---- passwordLabel ---- passwordLabel.setText("Password:"); contentPane.add(passwordLabel); passwordLabel.setBounds(20, 70, 55, passwordLabel.getPreferredSize().height); //---- loginButton ---- loginButton.setText("Login"); loginButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { loginButtonActionPerformed(e); } }); contentPane.add(loginButton); loginButton.setBounds(80, 95, 100, loginButton.getPreferredSize().height); //---- titleLabel ---- titleLabel.setText("Experimental X | Administrator Login"); contentPane.add(titleLabel); titleLabel.setBounds(45, 10, 190, titleLabel.getPreferredSize().height); { // compute preferred size Dimension preferredSize = new Dimension(); for(int i = 0; i &lt; contentPane.getComponentCount(); i++) { Rectangle bounds = contentPane.getComponent(i).getBounds(); preferredSize.width = Math.max(bounds.x + bounds.width, ``preferredSize.width); preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); } Insets insets = contentPane.getInsets(); preferredSize.width += insets.right; preferredSize.height += insets.bottom; contentPane.setMinimumSize(preferredSize); contentPane.setPreferredSize(preferredSize); } setSize(270, 170); setLocationRelativeTo(getOwner()); // JFormDesigner - End of component initialization //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables // Generated using JFormDesigner Evaluation license - Hrach Ghapantsyan private JPasswordField loginPasswordField; private JTextField loginUsernameField; private JLabel usernameLabel; private JLabel passwordLabel; private JButton loginButton; private JLabel titleLabel; // JFormDesigner - End of variables declaration //GEN-END:variables } </code></pre> <p>When I run the Java code, the appGUI class is activated which causes a pop-up. A login box pops-up. When the login box pops up, A user is required to enter his or her username and password.</p> <p>What I wanted to happen is when the user clicks on login, it submits the password to the Main class and does something like this:</p> <pre><code> String password = "the password that the user just inputed"; </code></pre> <p>In the:</p> <pre><code> public static void main(String[] args) throws Exception {} </code></pre> <p>Is there any way to do this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload