App scans for a properties file. If it cannot be found, a dialog is displayed, given user option to browse for file, or create a new one.

My issue relates to the second one. When user chooses create new one, I would to display a second JFrame containg a button and a jtextarea where the user fills in the properties. After pressing save, the frame should be closed and application to first frame.

However, the second JFrame will not display properly. It's there, but the first JFrame can be seen through this one.

I'm not sure whether I should post the topic in this topic, or in the threads topic.

My code:

DatabaseGenerator
Java Code:
package nl.group2000.databasegenerator.common;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

//import nl.group2000.databasegenerator.controller.DatabaseConnection;
import nl.group2000.databasegenerator.gui.PropertiesGui;

public class DatabaseGenerator implements Runnable {

    private static Properties properties = new Properties();
    JPanel top;
    JPanel bottom;
    JFrame frame;
    private static PropertiesGui propsFrame =  null;
    
    /**
     * @param args
     */
    public static void main(String[] args) {
	DatabaseGenerator app = new DatabaseGenerator();
	SwingUtilities.invokeLater(app);
    }

    private void init() {
	FileInputStream props = loadProperties();
	if (props != null) {

	    try {
		properties.load(props);
	    } catch (IOException e) {
		System.out.println("Unable to load properties file.");
		System.exit(0);
	    }
	    //boolean result = DatabaseConnection.testDbConnection(properties);
	} else {
	    System.out.println("No props.");
	    System.exit(0);
	}
    }

    
    @Override
    public void run() {
	createAndShowGUI();
	System.out.println("Hereeeee!");
    }

    private void createAndShowGUI() {
	JFrame frame = new JFrame("Configuration Tool");

	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	Container rootPane = frame.getContentPane();
	rootPane.setLayout(new BorderLayout());
	frame.setLayout(new GridBagLayout());

	top = new JPanel();
	top.setLayout(new FlowLayout());
	top.setPreferredSize(new Dimension(140, 125));
	JButton button = new JButton("Button");
	top.add(button);
	top.setBorder(BorderFactory.createLoweredBevelBorder());
	JLabel label = new JLabel();
	label.setText("Some label");
	top.add(label);

	bottom = new JPanel();
	bottom.setLayout(new FlowLayout());
	bottom.setPreferredSize(new Dimension(140, 125));
	bottom.setBorder(BorderFactory.createLoweredBevelBorder());

	JButton button1 = new JButton("Button1");
	bottom.add(button1);
	JLabel label1 = new JLabel();
	label1.setText("Some label1");
	bottom.add(label1);

	frame.add(top);
	frame.add(bottom);
	frame.pack();
	frame.setVisible(true);
	init();
    }

    public FileInputStream loadProperties() {
        FileInputStream is = null;
        try {
            is = new FileInputStream("config\\1database.properties");
        } catch (FileNotFoundException e1) {
            System.out.println("Default file not found.");
    
            String[] options = { "Create a new properties file.",
        	    "Search for a properties file." };
    
            int result = JOptionPane.showOptionDialog(null // Center in window.
        	    , "What do you want to do?" // Message
        	    , "Default properties not found." // Title in titlebar
        	    , JOptionPane.YES_NO_OPTION // Option type
        	    , JOptionPane.PLAIN_MESSAGE // messageType
        	    , null // Icon (none)
        	    , options // Button text as above.
        	    , "Create a new properties file." // Default button's label
            );
    
            System.out.println("Result " + result);
            if (result == 0) {
        	createProperties();
            } else if (result == 1 ){
        	JFileChooser chooser = new JFileChooser();
        	chooser.setCurrentDirectory(new File("."));
        	result = chooser.showOpenDialog(null);
        	if (result != 1) {
        	    File file = chooser.getSelectedFile();
        	    try {
        		is = new FileInputStream(file);
        	    } catch (FileNotFoundException e) {
        		// Should never come here!
        		e.getMessage();
        		System.exit(0);
        	    }
        	} else {
        	    System.out.println("No file selected. Exiting...");
        	    System.exit(0);
        	}
            }else{
        	return null;
            }
    
        }
        return is;
    }

    private Properties createProperties() {
        propsFrame = new PropertiesGui();
        
        propsFrame.run();
        System.out.println("Locked ? "+propsFrame.getLocked());
        while (propsFrame.getLocked()){
            //System.out.println("Is locked!!");
            //System.out.println("Activ");
        }
       
        Properties prop = new Properties();
        File props = propsFrame.getProperties();
        if (props != null) {
            try {
        	FileInputStream is = new FileInputStream(props);
            } catch (FileNotFoundException e) {
        	System.out.println("Error creating properties.");
        	return null;
            }
        } else {
            System.out.println("Hmm");
    
        }
        return prop;
    }
}
PropertiesGui:
Java Code:
package nl.group2000.databasegenerator.gui;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class PropertiesGui extends JFrame implements Runnable{
    private static JFrame frame = null;
    /**
     * 
     */
    private static final long serialVersionUID = -5515218998371172013L;
    private boolean locked = false;
    private volatile boolean finished = false;

    public File getProperties() {
	// TODO Auto-generated method stub
	return null;
    }
    
    public void createProperties(){
	frame.repaint();
	System.out.println("Finished?");
	while (!finished){
	    
	}
	setLocked(false);
	
    }

    @Override
    public void run() {
	frame = new JFrame("Create propertiesfile");

	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
	Container rootPane = frame.getContentPane();
	rootPane.setLayout(new FlowLayout());
	
	JTextArea textArea = new JTextArea();
	textArea.setText("#Database configuration");
	textArea.setText("DATABASE=192.168.1.100");
	
	
	JPanel panel = new JPanel();
	panel.add(textArea);
	
	
	JPanel buttonPanel = new JPanel();
	
	JButton saveButton = new JButton("Save file");
	saveButton.addActionListener(new ActionListener() {
	    
	    @Override
	    public void actionPerformed(ActionEvent e) {
		finished = true;
		
	    }
	});
	
	buttonPanel.add(saveButton);
	frame.add(panel,"South");
	frame.add(buttonPanel,"North");
	frame.pack();
	frame.setVisible(true);
	setLocked(true);
	createProperties();
    }
    
    private void setLocked(boolean locked) {
	System.out.println("Now " +locked);
	this.locked = locked;
	
    }

    public synchronized boolean getLocked(){
	return locked;
    }
}
Thnx in advance.