Results 1 to 3 of 3
  1. #1
    dinu is offline Member
    Join Date
    Jan 2013
    Posts
    31
    Rep Power
    0

    Default how to get return values from a button to main program.

    hello,

    I have a main program which has a button Authenticate. On click of authenticate open a form for auth which has USERNAME FIELS AND PASSWORD.
    If entered fields are true then enable editing of jtable in main program..

    Basically something like this :
    //main program
    Authenticate.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent ae)
    {
    UpdateAuth ua=new UpdateAuth();// opens form which has username and pass for authentication
    ua.setVisible(true);

    //need code here for enabling table
    if(s=="mactus")
    {
    enable table editing
    }
    //table.repaint();
    }

    });


    // form open for auth..(class UpdateAuth )

    private String SigninMouseClicked(java.awt.event.MouseEvent evt) {
    String aname=Aname.getText();
    String apass=Apassword.getText();
    if(aname.equals("") && apass.equals(""))
    {
    JOptionPane.showMessageDialog(null,"Enter login name or password","Error",JOptionPane.ERROR_MESSAGE);
    }
    if(!(aname.equals("") && apass.equals("")))
    {
    if(aname.equals("harshil") && apass.equals("harshil123"))
    {
    String s="mactus"; /// if username and password is success enable table editing in main program
    return s;

    }
    else if (!aname.equals("mactus") && !apass.equals("mactus123"))
    {
    Aname.setText("");
    Apassword.setText("");
    }
    }
    return null;
    }

  2. #2
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    307
    Rep Power
    6

    Default Re: how to get return values from a button to main program.

    So what's the question? Also, please put the [CODE] Tags around your code as it makes it easier to read.

  3. #3
    fanjavaid is offline Member
    Join Date
    Dec 2012
    Location
    Jakarta, Indonesia
    Posts
    23
    Rep Power
    0

    Default Re: how to get return values from a button to main program.

    Is the program into one Frame?
    If YES,

    You must create a "flag" isEnable if authentication is correct.
    example :
    Java Code:
    ....
    private boolean correct;
    
    if(aname.equals("harshil") && apass.equals("harshil123")) 
    { 
          setCorrect(true); // Tell if this is correct auth..
    
          String s="mactus"; /// if username and password is success enable table editing in main program
          return s;
    }
    
    //getter and setter
    ....

    and in method for table enable, you can check :
    Java Code:
    if (isCorrect == true) {
         // do enable here...
    }

Similar Threads

  1. Return positive values only
    By DomBrown in forum New To Java
    Replies: 14
    Last Post: 03-31-2011, 08:48 PM
  2. Return values and Recursion
    By blug in forum New To Java
    Replies: 4
    Last Post: 11-14-2010, 01:55 PM
  3. Using functions that return values?
    By Megapixelz in forum New To Java
    Replies: 1
    Last Post: 04-30-2008, 05:07 AM
  4. how to return values from hashmap
    By oregon in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 05:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •