想不通,你这样试试,看行不行啊。 g.setXormode(Color.red);
g.setcolor(Color.red);
g.fillrect(10,10,100,100);
g.setcolor(Color.red);
g.fillrect(10,10,100,100);
解决方案 »
- 如下文:foot变量没有初始化为什么可以进行比较?
- 跪求交如何把数据库的数据写入table
- 关于两个List组合成为一个新List的问题!
- 【高手来帮忙2个问题】jni加载dll文件后,程序中能否手动代码卸载???另外如何让程序代码运行n个小时候退出,1分钟后再重启程序
- jframe如何调整边框大小?
- GUI界面出错了!!
- socket 关闭出异常
- 请问定义问题
- ·········itext 问题!!!
- 高分求救:请问当窗口最小化时,如何把它放到屏幕的右下角的图标栏内呢?
- 新学菜鸟求助java环境问题,简单,但是我不会
- why????????关于application中画图的问题!!!!!!!高分求解
顺便再说明一点:
我在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();
}
}
public void paint(Graphics g)
{
}
{
//在这里加上super.paint(g);}
时候会把想显示的图形刷新掉。
这样有利于类的独立性,另外,我想用异或覆盖
的方法来画,因为使用frame中的paint()时,
我的程序就需要不断的刷新frame中paint()函数,
导致效果很差。另外,我使用的是jbuilder7
有四五个类都需要在frame上画东西,而不可能每一个
类都继承一个frame吧,所以才会想到把application中
的frame的graphics g传给其他类的方法。
一个panel,专门将图形画在上面,如果是多个东西要画,你只有创建一个BufferedImage,在它上面先画好图,将这个graphics g传给其他类。你可以将可以在frame中加入这个panel,到时候就一起把这个BufferedImage画到panel上。
ok