想不通,你这样试试,看行不行啊。    g.setXormode(Color.red);
  g.setcolor(Color.red);
    g.fillrect(10,10,100,100);

解决方案 »

  1.   

    我试过楼上这样的做法,但是也不行!
    顺便再说明一点:
    我在application中的frame重写了paint()
    否则,原函数会通过repaint()把我要画的图形刷掉,
    这样的话,就无论如何都看不到所画的矩形了。
    另外,说明以下我是在哪调用car.show()的,如下:
    public class Application1 {
      private boolean packFrame = false;  //Construct the application
      public Application1() {
        Frame1 frame = new Frame1();
        //Validate frames that have preset sizes
        //Pack frames that have useful preferred size info, e.g. from their layout
        if (packFrame) {
          frame.pack();
        }
        else {
          frame.validate();
        }
        //Center the window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = frame.getSize();
        if (frameSize.height > screenSize.height) {
          frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
          frameSize.width = screenSize.width;
        }
        frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
        frame.setVisible(true);    /****************我调用画图的代码************/
        Car car1 = new Car(null,1,1,Color.red,frame.getGraphics());
        car1.show();
      }
      //Main method
      public static void main(String[] args) {
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch(Exception e) {
          e.printStackTrace();
        }
        new Application1();
      }
    }
      

  2.   

    再补充一点,我重写的paint()为
    public void paint(Graphics g)
    {
    }
      

  3.   

    public void paint(Graphics g)
    {
    //在这里加上super.paint(g);}
      

  4.   

    xor mode是不是异或模式,跟位运算的道理差不多
      

  5.   

    加super.paint(g)不对,这样系统调用repaint()的
    时候会把想显示的图形刷新掉。
      

  6.   

    Frame1 frame = new Frame1();Application1 为什么不直接继承 Frame 在内部重写 print() ?我不确定是不是关键,但总觉得有点别扭。
      

  7.   

    哦,是这样的,我想在别的类中直接画图形,
    这样有利于类的独立性,另外,我想用异或覆盖
    的方法来画,因为使用frame中的paint()时,
    我的程序就需要不断的刷新frame中paint()函数,
    导致效果很差。另外,我使用的是jbuilder7
      

  8.   

    还有,我是想在同一个frame中画各种各样的东西,
    有四五个类都需要在frame上画东西,而不可能每一个
    类都继承一个frame吧,所以才会想到把application中
    的frame的graphics g传给其他类的方法。
      

  9.   

    建议使用
    一个panel,专门将图形画在上面,如果是多个东西要画,你只有创建一个BufferedImage,在它上面先画好图,将这个graphics g传给其他类。你可以将可以在frame中加入这个panel,到时候就一起把这个BufferedImage画到panel上。
    ok