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:
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?
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.