the frame is okay but the text2, textfield has occupy the whole frame. what's wrong with my code?
image: http://img68.imageshack.us/my.php?image=73815503ku1.png
here's the code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JFrameTest extends JFrame implements ActionListener {
JButton button;
JLabel label1, label2, label3;
JTextField text1, text2;
Container con = getContentPane();
public JFrameTest() {
button = new JButton("Submit");
button.addActionListener(this);
button.setBounds(400, 75, 75, 20);
button.setVisible(true);
label1 = new JLabel("Name: ");
label1.setBounds(10, 10, 75, 20);
label1.setVisible(true);
label2 = new JLabel("Address: ");
label2.setBounds(10, 30, 75, 20);
label2.setVisible(true);
label3 = new JLabel("Output");
label3.setBounds(10, 100, 200, 20);
label3.setVisible(true);
text1 = new JTextField();
text1.setBounds(75, 10, 400, 20);
text1.setVisible(true);
text2 = new JTextField();
text2.setBounds(75, 30, 400, 20);
text2.setVisible(true);
con.add(button);
con.add(label1);
con.add(label2);
con.add(label3);
con.add(text1);
con.add(text2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == button) {
label3.setText("The name is "+text1.getText()+" and the address is "+text2.getText());
}
}
public static void main (String args[]) {
JFrameTest frame = new JFrameTest();
frame.setTitle("JFrame Test");
frame.setBounds(50, 50, 500, 200);
frame.setVisible(true);
}
}