for your first question, after your code:
Code:
ImageIcon icon = new ImageIcon(filename);
JLabel background = new JLabel(icon);
mapPanel.add(background);
try just adding the line:
just like that, nothin before it. That should do it.
as for the second question you need to use the JFileChooser class. Here is an example from sun:
The following code pops up a file chooser for the user's home directory that sees only .jpg and .gif images:
Code:
JFileChooser chooser = new JFileChooser();
// Note: source for ExampleFileFilter can be found in FileChooserDemo,
// under the demo/jfc directory in the Java 2 SDK, Standard Edition.
ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension("jpg");
filter.addExtension("gif");
filter.setDescription("JPG & GIF Images");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}