Jump to content
Sign in to follow this  

JFrame Pass Values to Method [HELP]

Recommended Posts



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





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.addActionListener(new ActionListener() {


public void actionPerformed(ActionEvent 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


} 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  

  • Recently Browsing   0 members

    No registered users viewing this page.