各位高手们,请帮帮我,谢谢!!!!
各位大侠们:我是个新手才学java两天,遇到一个问题想请教,有个程序编译能通过,但执行的时候提示如下:
Exception in thread "main" java.lang.IllegalArgumentException: cannot add to lay
out: unknown constraint: BorderLayout.NORTH
at java.awt.BorderLayout.addLayoutComponent(BorderLayout.java:437)
at java.awt.BorderLayout.addLayoutComponent(BorderLayout.java:399)
at java.awt.Container.addImpl(Container.java:664)
at java.awt.Container.add(Container.java:518)
at TwoListen.go(Xue.java:16)
at TwoListen.main(Xue.java:10)
Press any key to continue...
请问是什么意思,为什么会出现这种情况,是哪个地方逻辑出错了吗?
程序如下:
import java.awt.*;
import java.awt.event.*;
class TwoListen implements MouseMotionListener, MouseListener {
private Frame f;
private TextField tf;
public static void main(String args[]) {
TwoListen two = new TwoListen();
two.go();
}
public void go() {
f = new Frame("Two listeners example");
f.add (new Label ("Click and drag the mouse"), "BorderLayout.NORTH");
tf = new TextField (30);
f.add (tf, "BorderLayout.SOUTH");
f.addMouseMotionListener(this);
f.addMouseListener (this);
f.setSize(300, 200);
f.setVisible(true);
}
// These are MouseMotionListener events
public void mouseDragged (MouseEvent e) {
String s = "Mouse dragging: X = " + e.getX() + " Y = " + e.getY();
tf.setText (s);
}
public void mouseMoved (MouseEvent e) {
}
// These are MouseListener events
public void mouseClicked (MouseEvent e) {
}
public void mouseEntered (MouseEvent e) {
String s = "The mouse entered";
tf.setText (s);
}
public void mouseExited (MouseEvent e) {
String s = "The mouse has left the building";
tf.setText (s);
}
public void mousePressed (MouseEvent e) {
}
public void mouseReleased (MouseEvent e) {
}
}
注:我的程序是在jcreator中运行并编译的java环境是sdk1.4.1