Welcome to TRiBot Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0
SlayeRRR

JFrame Pass Values to Method [HELP]

2 posts in this topic

Hello,

 

I am creating a programme for a friend that takes a Username and Workstation ID input and then submits them to a database.

 

I have my JFrame layout styled to how I want it

 

acb81a327505651cb2cc208016b87fb6.png

 

 

Here is my current code that asks for 3 arguments

public void setData(int id, String username, String date){               try {                        st.executeUpdate("insert into tester " + "values  ('"+id+"','"+username+"', '"+date+"')");             System.out.println("Inserted Into The Database");                                            }catch(Exception ex){            System.out.println("Error :"+ex);        }    }

How would I take the text entered in the JFrame to be passed to the correct place and then executed once I press submit?

 

I've watched a few tutorials and learnt you need to add code to the ActionListener part but I can't think what I would be adding.

 

 

Thank you! :)

Edited by SlayeRRR

Share this post


Link to post
Share on other sites

//intializing the jframe components

submitButton.setText("Submit");

submitButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

submitButtonActionPerformed(e);

}

});

//this method is called when you click the button because of the action event listener

private void submitButtonActionPerformed(ActionEvent e) {

String username = userTextField.getText();

String[] usernames = DataBase.getUsernames();

for (int u = 0; u < usernames.length; u++) {

if (username.equals(u) {

//do stuff

break;

} else {

if (u.length == usernames.length -1) {

//send "invalid username" message

}

}

}

}

Edited by Flamo353

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.