首页上一页 1 下一页尾页 3 条记录 1/1页
这个地方好像不妥
发表在Java图书答疑
2009-12-13
是否精华
是
否
版块置顶:
是
否
package awt;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Ellipse2D.Double;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Example extends JFrame {
private Container con;
public Example() {
con = getContentPane();
setSize(200, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
con.add(new Test());
}
public static void main(String[] args) {
new Example();
}
private class Test extends JPanel {
@Override
public void paint(Graphics arg0) {
super.paint(arg0);
Graphics2D graphics2D = (Graphics2D) arg0;
Shape sh[] = new Shape[4];
sh[0] = new Ellipse2D.Double(5, 5, 100, 100);
sh[1] = new Rectangle2D.Double(110, 5, 100, 100);
sh[2] = new Rectangle2D.Double(15, 15, 80, 80);
sh[3] = new Ellipse2D.Double(120, 15, 80, 80);
for (Shape s : sh) {
Rectangle2D bo = s.getBounds();
//这个地方好像不妥,为什么把值付给Rectangle2D,如果能是否也能付给Ellipse2D,s.getBounds()的值是怎样的一个值?
if (bo.getWidth() == 80) {
graphics2D.fill(s);
} else {
graphics2D.draw(s);
}
}
}
}
}
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Ellipse2D.Double;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Example extends JFrame {
private Container con;
public Example() {
con = getContentPane();
setSize(200, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
con.add(new Test());
}
public static void main(String[] args) {
new Example();
}
private class Test extends JPanel {
@Override
public void paint(Graphics arg0) {
super.paint(arg0);
Graphics2D graphics2D = (Graphics2D) arg0;
Shape sh[] = new Shape[4];
sh[0] = new Ellipse2D.Double(5, 5, 100, 100);
sh[1] = new Rectangle2D.Double(110, 5, 100, 100);
sh[2] = new Rectangle2D.Double(15, 15, 80, 80);
sh[3] = new Ellipse2D.Double(120, 15, 80, 80);
for (Shape s : sh) {
Rectangle2D bo = s.getBounds();
//这个地方好像不妥,为什么把值付给Rectangle2D,如果能是否也能付给Ellipse2D,s.getBounds()的值是怎样的一个值?
if (bo.getWidth() == 80) {
graphics2D.fill(s);
} else {
graphics2D.draw(s);
}
}
}
}
}