//以下是我的源代码
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
public class Myframe extends JFrame{
private static final long serialVersionUID = 1L;
File file=null;
JTextArea namearea;
Myframe(String s){
super(s);
final JTextField namefield=new JTextField(15);
namearea=new JTextArea(20,20);
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
JButton button1=new JButton("添加文件");
JButton button2=new JButton("保存");
JButton button3=new JButton("加密");
JButton button4=new JButton("解密");
panel1.add(namefield);
panel1.add(button1);
panel1.add(button2);
panel2.add(button3);
panel2.add(button4);
add(namearea,"Center");
add(namearea,"North");
add(namearea,"South");
JScrollPane scrollPane=new JScrollPane(namearea);
add(scrollPane);
setSize(750,600);
setLocation(100,100);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
new Myframe("加密与解密");
}
}
------解决思路----------------------
add(namearea,"Center");
add(namearea,"North");
add(namearea,"South");
JScrollPane scrollPane=new JScrollPane(namearea);
add(scrollPane);
一个组件只能被添加一次,namearea被添加了很多次