Results 1 to 2 of 2
  1. #1
    b2271916 is offline Member
    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Default New to Java and completely lost...

    I'm coming from C# and I am completely lost when it comes to Java... I currently have a Java Project with a JFrame (named frmMain) and a JInternalFrame (named frmPanel). I want to be able to add instances of frmPanel during runtime, but cannot figure out how to do it. Here is the code:
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.JDesktopPane;
    import java.awt.SystemColor;
    
    
    public class frmMain extends JFrame {
    
    	private JPanel contentPane;
    
    	/**
    	 * Launch the application.
    	 */
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					frmMain frame = new frmMain();
    					frame.setVisible(true);
    					[B]desktopPane.add(new frmPanel());[/B]
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}
    
    	/**
    	 * Create the frame.
    	 */
    	public frmMain() {
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setBounds(100, 100, 796, 546);
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    		contentPane.setLayout(new BorderLayout(0, 0));
    		setContentPane(contentPane);
    		
    		JDesktopPane desktopPane = new JDesktopPane();
    		desktopPane.setBackground(SystemColor.menu);
    		contentPane.add(desktopPane, BorderLayout.CENTER);
    		desktopPane.setLayout(null);
    	}
    
    }
    I get the error "desktopPane cannot be resolved".
    Also, how would I remove the title bar of a JInternalFrame?
    Last edited by b2271916; 02-18-2013 at 02:16 AM.

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

    Default Re: New to Java and completely lost...

    Your problem would be no different if you were coding this in C# since it has similar scoping rules as Java does. You declare your desktopPane inside of the frmMain constructor and so the variable is local to the constructor and only visible from within it.

Similar Threads

  1. For Loop Help! Completely Lost
    By whileloop in forum New To Java
    Replies: 8
    Last Post: 04-17-2012, 12:01 PM
  2. Replies: 2
    Last Post: 07-19-2011, 10:07 PM
  3. Calendars in Java are completely unintuitive.
    By caibbor in forum New To Java
    Replies: 2
    Last Post: 06-30-2011, 12:42 AM
  4. Is JAVA completely object-oriented???
    By venkateshk in forum New To Java
    Replies: 2
    Last Post: 11-17-2008, 10:17 AM
  5. Completely new to Java problem
    By Seamo14 in forum New To Java
    Replies: 4
    Last Post: 10-09-2008, 01:50 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
  •