想不通,你这样试试,看行不行啊。 g.setXormode(Color.red);
g.setcolor(Color.red);
g.fillrect(10,10,100,100);
g.setcolor(Color.red);
g.fillrect(10,10,100,100);
解决方案 »
- 请问swing中jtable单元格里面的内容怎么实现自动换行,求一个简单的例子,网上的都不行
- CronExpression中如何配置每个月最后2个工作日?
- 必须要自己写函数对字符串数组中的字符串排序啊?有没有现成的函数?
- 如果一字符串内容为"true && false || true",那如何得到其含义(值)为boolean 的ture?
- 报错:/by zero
- 小程序段,帮忙查错,谢谢
- 为什么setText 不会即时刷新?
- 紧急求救!1000分大奉送!!!!
- String类型数据与Date类型转换的问题?
- tomcat使用db2的驱动程序为什么会出问题?
- 新学菜鸟求助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