位置、大小和對齊

Java Swing. 基礎篇,這本書的p.68有一段的程式碼:
Rectangle r = new Rectangle( );
r = frame.getBounds(r);
System.out.println("X = " + r.x());
System.out.println("Y = " + r.y());
System.out.println("Width = " + r.width());
System.out.println("Height = " + r.height());

這一段是錯的,我用java 1.6的去編譯,發現找不到方法,查了手冊:
http://java.sun.com/javase/6/docs/api/java/awt/Rectangle.html.
The Rectangle class has the fields:
Field Summary
int height
The height of the Rectangle.
int width
The width of the Rectangle.
int x
The X coordinate of the upper-left corner of the Rectangle.
int y
The Y coordinate of the upper-left corner of the Rectangle.
我想這是屬性不是方法吧,改成這樣:
Rectangle r = new Rectangle( );
r = frame.getBounds(r);
System.out.println("X = " + r.x);
System.out.println("Y = " + r.y);
System.out.println("Width = " + r.width);
System.out.println("Height = " + r.height);

之後再編譯,就對了!

感謝你看到這裡,很快就可以離開了,但最好的獎勵行動就是按一下幫我分享或留言,感恩喔~

點我分享到Facebook

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *