准备:
JTextArea 文本区,一个可以输入文字的文本框
常用方法:
1.setText(String t)设置文本区中显示的文本
2.getText() 获取文本区中显示的文本
JScrollPane 滑动窗格容器,一般放入长度或者宽度特别长的控件,通过滑动来查看控件中由于太长而显示不出来的部分
首先创建一个可以输入文本:
1 packageswing;2
3 importjava.awt.Dimension;4 importjava.awt.EventQueue;5
6 importjavax.swing.JButton;7 importjavax.swing.JFrame;8 importjavax.swing.JScrollPane;9 importjavax.swing.JTextArea;10 importjava.awt.BorderLayout;11
12 public classMyTextArea {13
14 privateJFrame frame;15 privateJTextArea textArea;16
17 /**
18 * Launch the application.19 */
20 public static voidmain(String[] args) {21 EventQueue.invokeLater(newRunnable() {22 public voidrun() {23 try{24 MyTextArea window = newMyTextArea();25 window.frame.setVisible(true);26 } catch(Exception e) {27 e.printStackTrace();28 }29 }30 });31 }32
33 /**
34 * Create the application.35 */
36 publicMyTextArea() {37 initialize();38 }39
40 /**
41 * Initialize the contents of the frame.42 */
43 private voidinitialize() {44
45 //创建一个对话框
46 frame = newJFrame();47 //创建一个文本区
48 textArea = newJTextArea();49 //将文本区添加到弹出框框
50 frame.add(te