import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestComponentFrame {
public static void main(String[]args){
EventQueue.invokeLater(new Runnable()
{
public void run()
{
TextComponentFrame frame=new TextComponentFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class TextComponentFrame extends JFrame
{
public TextComponentFrame()
{
setTitle("TextComponentTest");
setSize(300,300);
 final JTextField textField=new JTextField();
final JPasswordField passwordField=new JPasswordField();
JPanel northPanel=new JPanel();
northPanel.setLayout(new GridLayout(2,2));
northPanel.add (new JLabel("User name:",SwingConstants.RIGHT));
northPanel.add(textField);
northPanel.add(new JLabel("Password:",JLabel.RIGHT));
northPanel.add(passwordField);

add(northPanel,BorderLayout.NORTH);
final JTextArea textArea=new JTextArea(8,40);
JScrollPane scrollPane=new JScrollPane(textArea);
add(scrollPane, BorderLayout.CENTER);
JPanel southPanel=new JPanel();
JButton insertButton=new JButton("Insert");
southPanel.add(insertButton);
insertButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event){
textArea.append("User name:"+textField.getText()+"Password:"+
new String(passwordField.getPassword())+"\n");
}
});
add(southPanel,BorderLayout.SOUTH);
}
//public static final int DEFAULT_WIDTH=300;
//ublic static final int DEFAULT_HEIGHT=300;

}
1.在这个程序中,先定义//public static final int DEFAULT_WIDTH=300;
//ublic static final int DEFAULT_HEIGHT=300;
和直接setSize(300,300);有何不同???
2.final JTextArea textArea=new JTextArea(8,40);8和40这两个参数应该是行数和列数吧,但
改动数值后好难看出区别.
3.JScrollPane scrollPane=new JScrollPane(textArea);
add(scrollPane, BorderLayout.CENTER);
这两个语句不是增加滚动条吗???为什么去掉后在文本域就不能显示内容呢??
请大侠帮忙,谢谢...