当前位置: 代码迷 >> Java相关 >> JAVA 帮我找一下错误
  详细解决方案

JAVA 帮我找一下错误

热度:204   发布时间:2005-10-16 16:19:00.0
JAVA 帮我找一下错误
1 (Example8_7)

我定义了一个十行十列的文本区,但发现它可以随便的输入字符而不受行和数量的限制。请指教。

2(Example8_7)

如下程序:
TextArea text1,text2;
  Button button;
  { button=new Button("确定");
    text1=new TextArea(10,10);
    text2=new TextArea(10,10);
    text2.setEditable(false);
     add(text1); add(text2); add(button);
    button.addActionListener(this);
  }
  
  public void actionPerformed(ActionEvent e)
  { /*if(e.getSourec()==button)*/
      { text2.append("\n"+text1.getSelectedText());}
  }
  为何当注释段加上时,编译不下去呢
搜索更多相关的解决方案: JAVA  

----------------解决方案--------------------------------------------------------
[CODE]import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyButtonDemo extends JFrame implements ActionListener
{
  JTextArea text1JTA,text2JTA;
  JScrollPane text2JSP;
  JButton button;
  MyButtonDemo()
  {
    super("MyButtonDemo");

    button = new JButton("确定");
    text1JTA = new JTextArea(10,10);
    text2JTA = new JTextArea(10,10);
    text2JTA.setEditable(false);
    text2JSP = new JScrollPane(text2JTA);
   
    JPanel workJP = new JPanel();
    workJP.add(text1JTA);
    workJP.add(text2JSP);
    workJP.add(button);
    button.addActionListener(this);
   
    setContentPane(workJP);
    setSize(600, 400);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
  }
  
  public void actionPerformed(ActionEvent e)
  {
    if(e.getSource()==button)
    {
      String selectedText = text1JTA.getSelectedText();
      if(selectedText != null)
        text2JTA.append(selectedText + "\n");
    }
      
  }
  public static void main(String [] args)
  {
    MyButtonDemo b = new MyButtonDemo();
  }
}[/CODE]
----------------解决方案--------------------------------------------------------
  相关解决方案