-3

I have looked everywhere for help and nothing is hitting the nail on the head of what I am trying to do.

I have a grade averaging program that I want to add a gui to with netbeans and I am not sure how to put the two together. I can somewhat make a gui with the help of netbeans but I am totally lost in how to bring them together.

Any help or advise would be appreciated as I am still learning.

Thank you.

0

1 Answer 1

2

Your grade averaging program needs to be split into methods that can be called from GUI. You add listeners to events in the GUI builder, events tell your program when the user did something such as click a button. You get data from some of your some of the graphics controls needed as inputs by your averaging program, call the method from your averaging program and use the results to set values of other graphical controls so the user can see the results.

For example to handle a button click, select the button, right click and choose Events -> Action -> actionPerformed from the popup menu and it will create a function that will be called when someone clicks the button and open the editor with the cursor inside that function.

So you get something like this.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)    {                                         
    // TODO add your handling code here:
}                                        

and edit it to do something like this:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // Get the inputs the user entered
    int input1 = Integer.valueOf(jTextField1.getText());
    int input2 = Integer.valueOf(jTextField2.getText());

    // use your other class to do something
    int result = new MyAverager().average(input1,input2);

    // Display the result for a user.
    jTextField3.setText(Integer.toString(result));
} 
1
  • Thank you for answering and contributing to Stack Overflow, however please take a second look at the question, for it seems to be off-topic according to the help center. Answering off-topic question make it look like it's okay to ask such questions - it's not. Off-topic questions might get closed and then deleted, which would nullify your contribution!
    – Kyll
    Oct 5, 2015 at 12:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.