posted 20 years ago
I have the following piece of code but unfortunately the graphical user interface doesn't behave as I would like it to. For instance, each instruction should be followed by the relevant textfield underneath ie,
INSTRUCTION
TEXTFIELD
INSTRUCTION
TEXTFIELD
INSTRUCTION
TEXTFIELD
But unfortunately this does not happen. Also when I enlarge the screen the layout changes. How can I ammend this code to make it the way I want it. I have tried all sort but can't seem to get round this!
private void connectionForm(){
//Container d = getContentPane();
JPanel all = new JPanel();
/* The following code provides a text box and asks for the URL of the database that needs to be
* connected to.*/
JPanel northPanel = new JPanel();
urllabel = new JLabel(" Enter the name of the database.");
northPanel.add(urllabel,BorderLayout.NORTH);
//all.add(northPanel,BorderLayout.NORTH);
url = new JTextField(15);
northPanel.add(url,BorderLayout.SOUTH);
all.add(northPanel,BorderLayout.NORTH);
/* The following code provides a text box and asks for the User-ID to allow a connection to the
* database to be established. */
JPanel centrePanel = new JPanel();
uidlabel = new JLabel(" Enter the User-ID for the specified database."
+ "NB: If no User-ID exists enter 'null'.");
centrePanel.add(uidlabel, BorderLayout.NORTH);
//all.add(centrePanel,BorderLayout.CENTER);
uid = new JTextField(15);
centrePanel.add(uid,BorderLayout.SOUTH);
all.add(centrePanel,BorderLayout.CENTER);
/* The following code provides a text box and asks for the Password to allow a connection to the
* database to be established. */
JPanel southPanel = new JPanel();
passwordlabel = new JLabel(" Enter the Password for the specified" +
"database. NB: If no Password exists enter 'null'.");
southPanel.add(passwordlabel, BorderLayout.NORTH);
//all.add(southPanel, BorderLayout.CENTER);
password = new JPasswordField(15);
southPanel.add(password, BorderLayout.SOUTH);
all.add(southPanel, BorderLayout.SOUTH);
JPanel minePanel= new JPanel();
mine = new JButton("Mine!");
minePanel.add(mine, BorderLayout.SOUTH);
all.add(minePanel, BorderLayout.SOUTH);
ActionHandler handler = new ActionHandler();
url.addActionListener(handler);
uid.addActionListener(handler);
password.addActionListener(handler);
mine.addActionListener(handler);
setContentPane(all);
validate();
setSize(600, 300);
show();
}