Results 1 to 4 of 4
  1. #1
    tipz is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default [SOLVED] Using Dialogs to display text

    Hello,

    So i've created a frame as the parent class for a dialog. This dialog is non modal. What i want to do is freely display text on the dialog at any given time. Ive tried creating built in methods but im not sure how to call them.

    heres a watered down version of what im trying to do

    Java Code:
    public class progView extends FrameView {
    
        public progView(SingleFrameApplication app) {
            super(app);
    
    
            initComponents();
    
            getFrame().setDefaultCloseOperation(3);
    
            etc etc
    
            showDebug(); //intialise the dialog with text area
           [b] debugWindow.debugPanelAppendText("test");   //this line does not work - debugWindow is a local dialog variable[/b]
    
    [i] the error output: cannot find symbol. location: class javax.swing.jdialog[/i]
    
       }
    
     private void showDebug() {
            if (debugWindow == null) {
                JFrame mainFrame = ProgApp.getApplication().getMainFrame();
                debugWindow = new debugPanel(mainFrame,false);
                debugWindow.setLocationRelativeTo(mainFrame);
            }
            ProgApp.getApplication().show(debugWindow);
        }
    }
    
    public class debugPanel extends javax.swing.JDialog {
    
        /** Creates new form debugPanel */
        public debugPanel(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
            initComponents();
        }
    protected void debugPanelAppendText(String text) {
            debugPanelTextArea.append(text);
            debugPanelTextArea.append("\n");
        }
    }
    so essentially i want to know if its possible to use dialogs in this manner and if i'm approaching the problem correctly. it seems like it isnt looking at the class when im directly calling a method from it and rather its looking at the super class that it extends.

    well anyway looking forward to some input

    thanks
    Last edited by tipz; 05-10-2011 at 07:32 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You'll need a reference to the other class in order to change its behavior (here the text it displays). To do this, the one class that is changing the behavior to the second class will need an instance field to the second class (your dialog) and then call its public methods as needed. It could possibly create the instance from within it and then display it or it could get a reference to the dialog object via a constructor or method (setter method) parameter.

    So for example, the first way:

    Java Code:
    public class ProgView  {
       private DebugWindow myDebugWindow;
    
       public ProgView() {
          myDebugWindow = new DebugWindow();
          // code to display the DebugWindow
       }
    
       public void otherMethod() {
          myDebugWindow.debugPanelAppendText("fubars rule!");
       }
    }


    And then the other way:

    Java Code:
    public class ProgView  {
       private DebugWindow myDebugWindow;
    
       public ProgView(DebugWindow myDebugWindow) {
          this.myDebugWindow = myDebugWindow;
          // don't need to call methods to display the DebugWindow as
          // it likely has been called by the method calling this constructor
       }
    
       public void otherMethod() {
          myDebugWindow.debugPanelAppendText("fubars rule!");
       }
    }

    Also, please follow Java coding conventions and start class names with an upper case letter. Doing this will make your coee easier for others (like us!) to understand.

  3. #3
    tipz is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default

    omg thankyou for the quick reply.

    wow thats all i needed to solve my problem, so simple!!!! sorry im more of a c++ coder but yeah all of the classes are capitalized its just in that example i was changing a few names to make it easier to read lol big thankyou again, not very familiar with java guis.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 0
    Last Post: 12-09-2010, 05:56 PM
  2. Replies: 1
    Last Post: 12-01-2010, 06:35 PM
  3. Replies: 0
    Last Post: 09-28-2010, 09:52 AM
  4. Replies: 1
    Last Post: 05-31-2010, 08:46 AM
  5. How do I get all dialogs?
    By zenteo in forum AWT / Swing
    Replies: 6
    Last Post: 03-08-2010, 10:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •