第1个回答 2017-07-25
把你的getJTextArea()函数改一下就行了。
完整的程序如下:(注意getJTextArea()函数)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//package cn.edu.jnu.www;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
public class first extends JFrame{
private JLabel jLabel;
private JTextField jTextField;
private JButton jButton,jButton1,jButton2;
private JTextArea jtextarea;
private JScrollPane sp;
public first()
{
super();
this.setSize(700, 500);
this.getContentPane().setLayout(null);
this.add(getJLabel(), null);
this.add(getJTextField(), null);
this.add(getJButtonok(), null);
this.add(getJButtoncancel(),null);
this.add(getJButtonzero(),null);
this.setBackground(Color.red);
this.add(getJTextArea(), null);
this.setTitle("calculator");
}
private JScrollPane getJTextArea(){
if(jtextarea==null){
jtextarea=new JTextArea();
//jtextarea.setBounds(5, 45, 650, 400);
}
//jtextarea.setLineWrap(true);
sp=new JScrollPane(jtextarea);
sp.setBounds(5, 45, 650, 400);
//sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
return sp;
}
private JLabel getJLabel() {
if(jLabel == null) {
jLabel = new javax.swing.JLabel();
jLabel.setBounds(10, 10, 150, 30);
jLabel.setText("请输入需要输出的位数:");
}
return jLabel;
}
private JTextField getJTextField() {
if(jTextField == null) {
jTextField = new javax.swing.JTextField();
jTextField.setBounds(150, 10, 160, 30);
}
return jTextField;
}
private JButton getJButtonok() {
if(jButton == null) {
jButton = new javax.swing.JButton();
jButton.setBounds(400, 10, 100,30);
jButton.setText("begin");
}
return jButton;
}
private JButton getJButtoncancel() {
if(jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(530, 10, 100, 30);
jButton1.setText("stop");
}
return jButton1;
}
private JButton getJButtonzero() {
if(jButton2 == null) {
jButton2 = new JButton();
jButton2.setBounds(310, 10, 80, 30);
jButton2.setText("清零");
}
return jButton2;
}
public static void main(String[] args)
{
first w = new first();
w.setVisible(true);
}
}