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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java JFrame Problem

  • 06-04-2009 3:17pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 3,945 ✭✭✭Anima


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


  • Moderators, Science, Health & Environment Moderators Posts: 10,088 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