Results 1 to 10 of 10

Thread: Internal Frames

  1. #1
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Internal Frames

    I have two classes.
    One is a calculator (using swing) and another is a desktop-like interface, with a basic menu bar with a button that is supposed to call the calculator.
    How can I call the calculator inside of the desktop, and the desktop and the calculator cannot be moved outside the desktop? (Like a container?)

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: Internal Frames

    That sounds like a JInternalFrame. The link is to Oracle's Tutorial.

  3. #3
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Internal Frames

    Quote Originally Posted by pbrockway2 View Post
    That sounds like a JInternalFrame. The link is to Oracle's Tutorial.
    I understand JInternal frames, but how do I implement all the actions from the other class into this frame?
    Do I have to re-write the entire program underneath this internal frame?

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

    Default Re: Internal Frames

    Much depends on how you've written your other codes. If you've done well, you'll have your program logic well separated from your GUI code, and you'll have your GUI code geared towards creating JPanels, not top level windows, so that these GUI views can be placed anywhere you need them: JFrames, JApplets, JDIalogs, JInternalFrames, or other JPanels as the need dictates.

  5. #5
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Internal Frames

    Quote Originally Posted by Fubarable View Post
    Much depends on how you've written your other codes. If you've done well, you'll have your program logic well separated from your GUI code, and you'll have your GUI code geared towards creating JPanels, not top level windows, so that these GUI views can be placed anywhere you need them: JFrames, JApplets, JDIalogs, JInternalFrames, or other JPanels as the need dictates.
    Okay, I understand that.

    Fortunately, I believe I have separated the GUI elements from the program's logic. Most of the elements, if not all, would be in the constructor.

    So if in my desktop class, if I have the following internal frame...
    JInternalFrame frame1 = new JInternalFrame();

    How do I set frame1's GUI elements to my calculator.class? Is there a way I can call the constructor and logic of the other class to reflect the actions of this frame?

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

    Default Re: Internal Frames

    If your Calculator is geared towards making a JPanel as its view, then simply put this view into the JInternalFrame's contentPane.

  7. #7
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Internal Frames

    Ok, I'm trying that and I get this error

    Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null




    Here is the code I am using in the desktop class.
    the calculator class is called Calc, and inside that the content pane is CalcContentPane.

    Java Code:
    private static main (String[] args) {
      JPanel CalcFrame = calc.CalcContentPane;
      JInternalFrame f = createFrame("Calculator");
      f.setContentPane(CalcFrame);
    }
    
    
    
       private static JInternalFrame createFrame(String t) {
          JInternalFrame f = new JInternalFrame(t);
          f.setResizable(true);
          f.setClosable(true);
          f.setMaximizable(true);
          f.setIconifiable(true);
          f.setSize(200,200);
          f.setVisible(true);
          return f;
       }
    Last edited by XavierAnderson; 11-25-2012 at 10:34 PM.

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

    Default Re: Internal Frames

    Which line causes the exception? I'm guessing that its line 4 above, f.setContentPane(CalcFrame);, and that this means that your CalcFrame variable is null. You will have to fix this. Also, please make sure that your coding adheres to Java naming conventions including starting variable and method names with lower case letters and class names with upper case letters. This is for our benefit so we can more easily understand your posted code. If we can more readily understand your code, we can help you better, so this is for your benefit too.

  9. #9
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Internal Frames

    Quote Originally Posted by Fubarable View Post
    Which line causes the exception? I'm guessing that its line 4 above, f.setContentPane(CalcFrame);, and that this means that your CalcFrame variable is null. You will have to fix this. Also, please make sure that your coding adheres to Java naming conventions including starting variable and method names with lower case letters and class names with upper case letters. This is for our benefit so we can more easily understand your posted code. If we can more readily understand your code, we can help you better, so this is for your benefit too.
    I didn't know about that convention, and thats a neat thing to know, thank you.

    The error is at line 4.

    I'm not sure how to not initialize the calcFrame (switched to lowercase), because its supposed to be assigned to my Calc.calcContentPane, which isn't null, its the contents to the entire calculator.
    Last edited by XavierAnderson; 11-25-2012 at 10:49 PM.

  10. #10
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: Internal Frames

    Calc.calcContentPane, which isn't null
    Check that, as the runtime and JPanel class won't lie.

    Java Code:
    private static main (String[] args) {
      JPanel calcFrame = calc.CalcContentPane;
      System.out.println("calcFrame=" + calcFrame);
      JInternalFrame f = createFrame("Calculator");
      f.setContentPane(calcFrame);
    }
    If it turns out that calcFrame is null you need to go to the code for the calc instance (or calc class), find where you thought you had assigned a non null value, and figre out why that didn't happen.

    Is this code a constructor? If so the class should be named Main.

Similar Threads

  1. frames
    By giorgi in forum AWT / Swing
    Replies: 2
    Last Post: 05-04-2011, 09:45 PM
  2. jsp frames
    By vasug in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-16-2010, 06:00 PM
  3. Passing a value between internal frames
    By mali in forum New To Java
    Replies: 3
    Last Post: 03-19-2010, 02:36 PM
  4. Help regarding Frames
    By ramesh.8189 in forum AWT / Swing
    Replies: 14
    Last Post: 02-15-2009, 09:12 AM
  5. [SOLVED] Internal frames inside a MDI form
    By Melki in forum AWT / Swing
    Replies: 3
    Last Post: 07-01-2008, 07:55 AM

Posting Permissions

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