小白求解为什么repaint()不能调用前面的paint()啊?
public void paint(Graphics g){
g.drawImage(bgImage, 0, 20, this);
g.setFont(new Font("黑体",Font.BOLD,20));
g.drawString("游戏信息:", 100, 60);
g.setFont(new Font("宋体",Font.BOLD,15));
g.drawString("黑方时间:", 60,480);
g.drawString("白方时间:", 250,480);
//绘制棋盘
for(int i=0;i<381;i++){
g.drawLine(13, 80+i, 394, 80+i);
g.drawLine(14+i, 81, 14+i,457 );
i+=20;
}
//标注点位
g.fillOval(74, 139, 5, 5);
g.fillOval(75, 394, 5, 5);
g.fillOval(328, 140, 5,5 );
g.fillOval(328, 393, 5, 5);
g.fillOval(202, 267, 5, 5);
//绘制棋子
for(int i=0;i<19;i++){
for(int j=0;j<19;j++){
if(allChess[i][j]==1){
int tempX=i*20+13;
int tempY=j*20+81;
g.fillOval(tempX-7, tempY-7, 14, 14);
}
if(allChess[i][j]==2){
int tempX=i*20+13;
int tempY=j*20+81;
g.setColor(Color.WHITE);
g.fillOval(tempX-7, tempY-7, 14, 14);
g.setColor(Color.BLACK);
g.drawOval(tempX-7, tempY-7, 14, 14);
}
}
}
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
//System.out.println("x:"+e.getX());
//System.out.println("y:"+e.getY());
x=e.getX();
y=e.getY();
if(x <=394 && x >= 13&& y >= 81&& y <= 457){
//JOptionPane.showMessageDialog(this, "已超出棋盘范围");
int i=(x-13)/20;
int j=(y-81)/20;
this.repaint();
}
g.drawImage(bgImage, 0, 20, this);
g.setFont(new Font("黑体",Font.BOLD,20));
g.drawString("游戏信息:", 100, 60);
g.setFont(new Font("宋体",Font.BOLD,15));
g.drawString("黑方时间:", 60,480);
g.drawString("白方时间:", 250,480);
//绘制棋盘
for(int i=0;i<381;i++){
g.drawLine(13, 80+i, 394, 80+i);
g.drawLine(14+i, 81, 14+i,457 );
i+=20;
}
//标注点位
g.fillOval(74, 139, 5, 5);
g.fillOval(75, 394, 5, 5);
g.fillOval(328, 140, 5,5 );
g.fillOval(328, 393, 5, 5);
g.fillOval(202, 267, 5, 5);
//绘制棋子
for(int i=0;i<19;i++){
for(int j=0;j<19;j++){
if(allChess[i][j]==1){
int tempX=i*20+13;
int tempY=j*20+81;
g.fillOval(tempX-7, tempY-7, 14, 14);
}
if(allChess[i][j]==2){
int tempX=i*20+13;
int tempY=j*20+81;
g.setColor(Color.WHITE);
g.fillOval(tempX-7, tempY-7, 14, 14);
g.setColor(Color.BLACK);
g.drawOval(tempX-7, tempY-7, 14, 14);
}
}
}
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
//System.out.println("x:"+e.getX());
//System.out.println("y:"+e.getY());
x=e.getX();
y=e.getY();
if(x <=394 && x >= 13&& y >= 81&& y <= 457){
//JOptionPane.showMessageDialog(this, "已超出棋盘范围");
int i=(x-13)/20;
int j=(y-81)/20;
this.repaint();
}
...全文
相关推荐
Graphics 与 repaint 方法
Graphics 与 repaint 方法
Java中Graphics的paint和repaint方法.pdf
Java中Graphics的paint和repaint方法.pdf 学习资料 复习资料 教学资源
java——Graphics[定义].pdf
java——Graphics[定义].pdf
第章Java图形与事件处理2022优秀文档.ppt
第章Java图形与事件处理2022优秀文档.ppt
简单的数字时钟
简单的数字时钟 public void run(){ //运行进程 while (clock!=null){ repaint(); //调用paint方法重绘界面 try{ Thread.sleep(1000); //线程暂停一秒(1000毫秒) } catch (InterruptedException ex){ ex.printStackTrace(); //输出出错信息 } } }


