Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java JFrame Problem

Options
  • 06-04-2009 4:17pm
    #1
    Registered Users Posts: 115 ✭✭


    Basically, this is my problem. I have two files: NoteFrame.java and Chords.java.

    I'm attempting to make an instance of the NoteFrame dialog appear when I click on a button in the Chords.java class.

    I have the following code in the event handler code for the button "tunerBtn" in the Chords.java class:

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

    NoteFrame newNoteFrame = new NoteFrame();
    newNoteFrame.setVisible(true);
    newNoteFrame.pack();

    }


    This works, as in when I click the button, the NoteFrame dialog appears. However, the NoteFrame dialog is not set up as it is when I run the dialog directly from the NoteFrame class itself.

    Inside the 'main' function in the NoteFrame class I have included a function called 'run' which sets up all the JLabels, Text colours etc.. for the dialog. This doesnt seem to be called when the NoteFrame dialog is created by the button click in the Chords class..

    Is there any way to gain access to 'main' or 'run' through the Chords class in order to ensure the dialog is set up correctly..??

    Any help is appreciated,

    Thanks


Comments

  • Registered Users Posts: 3,945 ✭✭✭Anima


    Post up the full code, can't really tell what you're saying.


  • Moderators, Science, Health & Environment Moderators Posts: 10,079 Mod ✭✭✭✭marco_polo


    As Anima says without code it is hard to see exactly what you are trying to do.

    Hazarding a guess, what you probably want to do is define a default constructor for your dialog box(don't forget to call the constructor of the base class of NoteFrame, I presume it is a JDialog or JFrame?) and move all your logic from the run method to the constructor. See skeleton below.
    class NoteFrame extends ? {
    
        public NoteFrame(){
            super();
            //your code here
        }
    
    ....
    
    }
    


Advertisement