Im really sorry to bother you guys with these questions. I tried to make 2 textfields one on top of the other reading name and last name, (I tried to put labels defining each textfield but gave problem) with two buttons insert and delete at the bottom. This code puts all in one line...Why?thank you in advance.
public class DBGUIMain extends JFrame {
final static boolean RIGHT_TO_LEFT = false;
final static boolean SHOULD_FILL = true;
final static boolean SHOULD_WEIGHT_X = true;
JButton Insert,Delete;
JTextField firstNameTextField, lastNameTextField;
public DBGUIMain() {
super("TEST");
JLabel label1, label2;
label1 = new JLabel("First Name:");
label2 = new JLabel("Last Name:");
if (RIGHT_TO_LEFT) {
getContentPane().setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
}
firstNameTextField = new JTextField("", 15);
lastNameTextField = new JTextField("", 15);
getContentPane().setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
if (SHOULD_FILL) {
c.fill = GridBagConstraints.HORIZONTAL;
}
if (SHOULD_WEIGHT_X) {
c.weightx = 1.0;
c.ipady = 10;
c.ipadx = 10;
}
c.gridx = 0;
c.gridy = 0;
//add(label1); gives prob here!
getContentPane().add(firstNameTextField);
c.gridx = 0;
c.gridy = 1;
//add(label2); and here
getContentPane().add(lastNameTextField);
Insert = new JButton(" INSERT ");
c.gridx = 2;
c.gridy = 4;
getContentPane().add(Insert, c);
Insert.addMouseListener(new MyMouseListener());
Delete = new JButton(" DELETE ");
c.gridx = 3;
c.gridy = 4;
getContentPane().add(Delete, c);
Delete.addMouseListener(new MyMouseListener());
}
public static void main(String argv[]) {
JFrame.setDefaultLookAndFeelDecorated(true);
DBGUIMain frame = new DBGUIMain();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
class MyMouseListener extends MouseAdapter {
public void mouseClicked(MouseEvent evt) {
if (evt.getSource().equals(Insert)) {
//do insert
}
}
}
}
public class DBGUIMain extends JFrame {
final static boolean RIGHT_TO_LEFT = false;
final static boolean SHOULD_FILL = true;
final static boolean SHOULD_WEIGHT_X = true;
JButton Insert,Delete;
JTextField firstNameTextField, lastNameTextField;
public DBGUIMain() {
super("TEST");
JLabel label1, label2;
label1 = new JLabel("First Name:");
label2 = new JLabel("Last Name:");
if (RIGHT_TO_LEFT) {
getContentPane().setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
}
firstNameTextField = new JTextField("", 15);
lastNameTextField = new JTextField("", 15);
getContentPane().setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
if (SHOULD_FILL) {
c.fill = GridBagConstraints.HORIZONTAL;
}
if (SHOULD_WEIGHT_X) {
c.weightx = 1.0;
c.ipady = 10;
c.ipadx = 10;
}
c.gridx = 0;
c.gridy = 0;
//add(label1); gives prob here!
getContentPane().add(firstNameTextField);
c.gridx = 0;
c.gridy = 1;
//add(label2); and here
getContentPane().add(lastNameTextField);
Insert = new JButton(" INSERT ");
c.gridx = 2;
c.gridy = 4;
getContentPane().add(Insert, c);
Insert.addMouseListener(new MyMouseListener());
Delete = new JButton(" DELETE ");
c.gridx = 3;
c.gridy = 4;
getContentPane().add(Delete, c);
Delete.addMouseListener(new MyMouseListener());
}
public static void main(String argv[]) {
JFrame.setDefaultLookAndFeelDecorated(true);
DBGUIMain frame = new DBGUIMain();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
class MyMouseListener extends MouseAdapter {
public void mouseClicked(MouseEvent evt) {
if (evt.getSource().equals(Insert)) {
//do insert
}
}
}
}