为什么我写的代码编译后textarea没有滚动条了。。。。。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MouseListeners implements
MouseMotionListener,MouseListener,WindowListener {
private JFrame f;
private JTextArea tf;
int x=0,y=0,count=0;
public static void main(String args[])
{
MouseListeners two = new MouseListeners();
two.go(); }
public void go() {
f = new JFrame("mouse event");
tf = new JTextArea(5,40);
f.getContentPane().add(tf);
tf.addMouseMotionListener(this);
tf.addMouseListener(this);
tf.addWindowListener(this);
f.setSize(300,200);
f.setVisible(true);
}
public void mouseDragged (MouseEvent e) {}
public void mouseMoved(MouseEvent e){}
public void mouseClicked(MouseEvent e){ }
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mousePressed(MouseEvent e){
String s=new String();
if(x==e.getX()&&y==e.getY()) count++;
else count=1;
x=e.getX();
y=e.getY();
if(e.getButton()==MouseEvent.BUTTON1){
s = "click left\nposition: x="+x+" y="+y+"\ntimes"+count;}
else if(e.getButton()==MouseEvent.BUTTON3)
{s = "click right\n"+"position: x="+x+" y="+y+"\ntimes"+count;}
tf.setText(s);}
public void mouseReleased(MouseEvent e){ }
public void windowClosing(WindowEvent e) {System.exit(1);}
public void windowOpened(WindowEvent e) {}
public void windowIconified(WindowEvent e){ }
public void windowDeiconified(WindowEvente) { }
public void windowClosed(WindowEvent e) { }
public void windowActivated(WindowEvent e){ }
public void
windowDeactivated(WindowEvent e) { }
}
理想中的界面应该是这样的: