NExuS Gaming
NExuS Gaming

Reputation: 13

JFrame not appearing after initialization in NetBeans

I have been working at this for about an hour now attempting to get it working but to no avail.

I am rather new to Java and this is my first time using JFrames but for some reason, when I attempt to initialise this JFrame from another JFrame it refuses to work.

Step by step:

  • User inputs a set of integers and clicks calculate
  • A try-catch catches any NumberFormatExceptions
  • Try-catch then prints error to console and sets the JFrame dialogueBox to visible
  • JFrame does not appear

    It is worth noting that the dialogueBox

    JFrame is being called from another JFrame called StudentDetails.

    Code for mouse clicked event listener:

        private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        int score1 = 0;
        int score2 = 0;
        int score3 = 0;
        int score4 = 0;
        int score5 = 0;
        int score6 = 0;
        dialogueBox db = new dialogueBox();
        try {
            score1 = Integer.parseInt(this.testScore1Input.getText());
            score2 = Integer.parseInt(this.TestScore2Input.getText());
            score3 = Integer.parseInt(this.testScore3Input.getText());
            score4 = Integer.parseInt(this.testScore4Input.getText());
            score5 = Integer.parseInt(this.testScore5Input.getText());
            score6 = Integer.parseInt(this.testScore6Input.getText());
        } catch (NumberFormatException numberFormatException) {
            System.out.println(numberFormatException.toString());
            db.setVisible(true);
        }
        int total = (score1 + score2 + score3 + score4 + score5 + score6);
        float average = total / 6;
        averageScoreOutput.setText(Float.toString(average));
    
    } 
    

    I was just looking for some insight into why this would not be working and also if anyone has any tips for best practices when using JFrames.

    Upvotes: 1

    Views: 64

  • Answers (1)

    camickr
    camickr

    Reputation: 324108

    if anyone has any tips for best practices when using JFrames.

    An application should only have a single JFrame. For child/popup windows you should use a JDialog.

    In your case you should be using a JOptionPane which is a customized JDialog.

    Read the section from the Swing tutorial on How to Make Dialogs for examples of using a JOptionPane.

    Upvotes: 2

    Related Questions