1.java Graphics2D说明中有关user space(用户空间)和device space(设备空间)是什么意思?有什么区别?
2.java Graphics2D paint的图形为什么在切换窗口后会消失呢?下面是我的代码:
import java.awt.*;
import javax.swing.*;
import java.awt.Graphics2D;
public class DemoDraw extends JFrame{
/** Creates a new instance of DemoDraw */
//creates main window
public DemoDraw() {
super("Draw方法演示");
setLocation(new Point(400,200));
setSize(200,400);
setVisible(true);
}
//demo draw()
public void paint(Graphics g){
super.paint(g);
Graphics2D g2d=(Graphics2D)g;
g2d.setColor(Color.red);
g2d.draw(new Rectangle(20,50,100,30));
g2d.setColor(Color.blue);
g2d.fill(new Rectangle(20,90,100,30));
g2d.draw3DRect(20,130,100,30,true);
g2d.draw3DRect(20,170,100,30,false);
g2d.drawString("Graphics2D演示程序",20,210);
}
public static void main(String[] args){
DemoDraw application=new DemoDraw();
}
}