帮我看看这个java程序哪里错了?

yoshubom 2006-01-30 12:11:14
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TextAreaDemo extends JFrame{
private JTextArea textArea1,textArea2;
private JButton copyButton;

//set up GUI
public TextAreaDemo(){
super("TextArea Demo");
Box box=Box.createHorizontalBox();

String string="This is a demo string to\n"+
"illustrate copying text\n"+
"from on TextArea to \n"+
"another TextArea using an\n"+"external event\n";

//set up textArea1
textArea1 = new JTextArea(string,10,15);
box.add(new JScrollPane(textArea1));

//set up copyButton
copyButton = new JButton("Copy >>>");
copyButton.addActionListener(
//anonymous inner class to handle copyButton event
new ActionListener(){
//set text in textArea2 to selected
//text from textArea1
public void actionPerformed(ActionEvent event){
textArea2.setText(textArea1.getSelectedText());
}
}//end anonymous inner class
);//end call to addActionListener
box.add(copyButton);

//set up textArea2
textArea2= new JTextArea(10,15);
textArea2.setEditalbe(false);
box.add(new JScrollPane(textArea2));

//add box to content pane
Container container=getContentPane();
container.add(box); //place in BorderLayout.CENTER

setSize(425,200);
setVisible(true);
}
//execute application
public static void main(String [] args){
TextAreaDemo application= new TextAreaDemo();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}//end class TextAreaDemo
...全文
87 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yoshubom 2006-01-30
  • 打赏
  • 举报
回复
//set up textArea2
textArea2= new JTextArea(10,15);
textArea2.setEditalbe(false); //这里应该是textArea2.setEditable(false);
box.add(new JScrollPane(textArea2));

呵呵自己解决了。
M3tdw2A7tVe8Xxhd 2006-01-30
  • 打赏
  • 举报
回复
新年快乐,恭喜了

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧