BufferedImage bgImage是什么意思思

java程序设计(五子棋)一个文件_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
13页免费8页免费3页免费13页免费33页2下载券14页3下载券89页5下载券7页免费7页1下载券3页免费
喜欢此文档的还喜欢19页1下载券18页免费9页5下载券33页2下载券35页免费
java程序设计(五子棋)一个文件|j​a​v​a​五​子​棋​代​码
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢Java五子棋源代码注释_百度知道
Java五子棋源代码注释
然后帮我写一个简单的文档!,采用的技术特点!.任选不少于20行连续的代码作出解释.帮我看一下这端程序,实现了什么如何实现的。谢谢了
急,个各类的作用。21,就是说一下这个程序开发的思路
提问者采纳
* g, &&#47, &quot, 130; 3600 + &= 5) {
flag = true, 4.getX() &\ 3600 + &quot:&
*/&#47:// 现在重新开始游戏
g2; &#47,游戏结束; } if
* (count2 &= 320
&& e.showConfirmDialog(this,游戏结束;
System.checkCount(1.
} catch (IOException e) {
&#47, this).showConfirmDialog( } public void run() {
&#47.fillOval(68.canPlay = true.getDefaultToolkit();&#47. 60 - maxTime / 2;
if (result == 0) {
if (isBlack) {
* S五子棋& } i4 = 1;设置完成!&&#47, 128;宋体&quot, 14)).fillOval(308, 14);= 70
&&.checkCount(1;
String imagePath = &) + & 通过循环来做棋子相连的判断
&#47.setFont(new Font(& j &/; + whiteM/
message = &
g2; + whiteTime);
} } public void mouseReleased(MouseEvent e) {
&quot:&quot.repaint();白方&quot.getY() &= 470 && e.getX() &
if (allChess[i][j] == 2) {
&#47:& 取得屏幕的宽度 int width = T游戏结束;
xChange = tempX.getY();请输入游戏的最大时间(单位, 30;
if (blackTime == 0) {
JOptionP / g.drawString(&quot.printStackTrace(); TODO Auto-generated catch block
e, 470), 14);
&#47.canPlay = 0) {
while (true) {
if (isBlack) {
blackTime--, 260, &quot.awt,&
+ (blackTime - blackTime /黑方先行&
&#47,特点 纵坐标 是相同; 19, 128;);
yChange++;/ TODO Auto-generated method stub
bgImage = ImageIO.WHITE);
isBlack = true!= 0) {
if (yChange &gt, 248;这个一个五子棋游戏程序;))),当某一方连到五子时.fillOval(188; 判断是否有时间限制
if (maxTime &;
g.createGraphics(); int y = 0;&#47:&&#47, 70 + 20 * i);获胜;= 300) {
int result = JOptionP /, color);/ 3600 + &= 150) {
String input = JOptionPane
, 4). if (color ==
* allChess[x+2][y]) { count++; 60 * 60)!&quot:分钟);;黑方已经认输;
int tempX = xC/
if (allChess[x][y] == 0) {
JOptionP&#47.repaint():& while (color == allChess[x + i3][y - i3]) { count3++;&#47, 70 + 20 */= 0
&& y + yChange & 斜方向的判断(右上 + 左下) int i3 = 1 ; } i2 = 1;/import java, this); ; 点击 退出 按钮
if (e.jpg&
message = &
t, &quot, 0; 设置窗体大小
this, int yChange.getY() & 60 * 60);
if (count & 保存黑方与白方的剩余时间 int blackTime = 0;
g2.showMessageDialog(/ i &\
&#47?&quot, 4;&#47.JFrame.F/;&#47,黑白双方轮流下棋; &#47: 1)把棋盘清空.MouseEvent.parseInt(input) * 60;
} catch (InterruptedException e) {
whiteMessage = maxTime /
if (maxTime &gt:&&#47 TODO Auto-generated method stub } public void mouseEntered(MouseEvent e) {
&#47.showMessageDialog( y = (y - 70) &#47.ImageIO;= 0 && x - xChange &lt.println(blackTime + &quot, 470); i++) {
for (int j = 0;/
isBlack = false!= 0)
xChange++.showConfirmDialog(this, & 3) 将下一步下棋的改为黑方
for (int i = 0;).dir& 点击 关于 按钮
+ (maxTime - maxTime / i &lt:&quot., 4), 0, 14);
if (result == 0) {
for (int i = 0;& } &#47!& i2++.setLocation((width - 500) &#47.showMessageDialog(this.fillOval(68;\
g2:&import javax.getX() & 19; 点击 认输 按钮
if (e. 3600 + &
g2; 输出标题信息
g2; i++) {
for (int j = 0!&quot, 368.width.JOptionP 19;黑方先行&*
imagePath = S黑方时间; j++) {
allChess[i][j] = 0;public class FiveChessFrame extends JFrame implements MouseL);= 270
while (x + xChange &gt, 14););
// 绘制背景
g2.showMessageDialog(/ i++) {
for (int j = 0.getY() &白方时间;&#47, 1; 其中数据内容 0;
} 将窗体显示出来
this, Runnable { // 60 * 60), 500; /;
+ (maxTime &#47.
/ 点击 开始游戏 按钮
/;&#47.getX() &lt.start().getDefaultToolkit();
g2;.WHITE) , 4).println(e:&quot,
&).image,表示没有时间限制;= 70 && y &!= 0) {
if (yChange &gt.showInputDialog(&
blackTime = maxTime.getX() &
g2; &#47, 500);).setSize(500; 取得屏幕的高度 int height = T
g2.getX() &lt.getY() &
+ (maxTime / 标识当前游戏是否可以继续 boolean canPlay = " target="_blank">www.getX() &lt.getScreenSize();无限制&
isBlack == 470 && e.drawLine(10.height, &quot,不允许输入负数; 黑子
int tempX = i * 20 + 10:&quot.getY() &黑方&当前位置已经有棋子;*
* int i = 1,即判断游戏是否结束
boolean winFlag == 430) {
x = (x - 10) /是否确认认输; 白子
int tempX = i * 20 + 10;白子 g,
&quot.setFont(new Font(&&quot, & / &#47, 14.
+ (whiteTime - whiteTime &#47, y - 7.F 背景图片 BufferedImage bgImage =轮到白方&quot,
BufferedImage, 4.getX() &lt:&= 170
&& e, 4.repaint().getY());&#47: 表示这个点并没有棋子;
message = &黑体&
*/ } i3 = 1?&quot.printStackTrace();
blackTime = maxT= 470 && 刷新屏幕;, 1; }
* i = 1; int count2 = 1 , 70; 保存棋子的坐标 int x = 0, 4, color);
if (xC&#47, 4); 0) {
blackMessage = maxTime &#47:&/= 5) {
flag = while (color == allChess[x - i3][y + i3]) { count3++, 370;&#47.fillOval(x - 7.repaint(); 将窗体的关闭方式设置为默认关闭后程序结束
this.resume(), &/ 保存之前下过的全部棋子的坐标 /+e;&#47.getX() + &
&#47.drawOval(tempX - 7; -- &quot.setTitle(&, &quot.fillOval(308, 368;= 400 &&.setDefaultCloseOperation(JF/= 470 && e. while (color == allChess[x - i][y - 0]) { count++;&#47.suspend(), 1;);
if (count & } if (count4 &gt, 14, 0;= 18 && y + yChange & 60 - whiteTime /);= 350) {
JOptionP 判断这个棋子是否和其他的棋子连成5连;
whiteTime = maxT
+ (allChess[x][y] == 1 ;= 370
&& 19; int whiteTime = 0;/ 19.exit(0);= 400 && e,有相关问题可以访问<a href="http?&import java, 2;
blackMessage = maxTime &#47, 0;
message = &quot:表示这个点是白子 int[][] allChess = new int[19][19]; 标识当前应该黑棋还是白棋下下一步 boolean isBlack = 3600 + &quot、左下
g2.fillOval(188;
if (whiteTime == 0) {
JOptionP黑子
if (count &
&#47.event.getX() & 判断横向是否有5个棋子相连; j++) {
allChess[i][j] = 0, 20)).getX()), 4;= 5) { flag =/ 3600 + &请输入正确信息, int color) {
int count = 1!= 0)
xChange++;
blackMessage = & / 输出时间信息
int result = JOptionPane, &quot.game, 即allChess[x][y]中y值是相同
int color = allChess[x][y]; j & 0) {
whiteTime = maxT
message = &
whiteMessage = whiteTime /
if (x &gt, 14.showMessageDialog(
y = (y - 70) / 3600 * 60) + &quot, &quot:&quot, 248;= 470 && public FiveChessFrame() {
&#47.fillOval(68; 标注点位
g2;黑方先行&= 400 && 20 * 20 + 70 ; 60 - maxTime /= 18 && y - yChange &;无限制& 60 - blackTime //
JOptionPane.io:&quot,游戏结束;
/= 400 &&/黑方超时; /bin&#47.BLACK);;
Graphics g2 = .addMouseListener(this);// 做倒计时的线程类 Thread t = new Thread(this);&#47.TYPE_INT_RGB);/ 20; 19, color).fillOval(308.repaint();
} } public void paint(Graphics g) {
/是否重新开始游戏;
int tempY = j * 20 + 70;
* &#47, 14).getX() &
} 2) 将 游戏信息; + blackM 保存双方剩余时间的显示信息 String blackMessage = &&#92;轮到黑方& 判断纵向
+ (maxTime /&#47.cn&quot, 4);
+ (whiteTime &#47: 表示这个点是黑子; -- &游戏信息;
allChess[x][y] = 2;无限制&无限制&quot.sleep(1000);
g2;, y - 7, color)!&;
&#47,是否重新开始游戏。&quot, tempY - 7;
whiteTime = maxT/ i++) {
for (int j = 0;
+ (maxTime - maxTime / 设置窗体出现位置&#47, (height - 500) &#47.getY() &白方已经认输;
} 2).drawImage(bi.setColor(C/= 120
&&= 5) { flag == 5) {
flag = i++; 另一种方式 allChess = new int[19][19].getScreenSize(),allChess这个数组中全部数据归0; } } }
+ (blackTime &#47.EXIT_ON_CLOSE);&quot.read(new File(imageP 为窗体加入监听器
this. 3600 * 60) + &); 60 * 60);
t.setColor(C;
if (yChange .
g2; 将窗体设置为大小不可改变 i++) {
+ (maxTime //
while (x - xChange &gt,防止开始游戏时出现无法显示的情况;
if (maxTime &Y.canPlay = ; / 重新开始所要做的操作;/););
if (count &= 100) {
int result = JOptionP
+ (maxTime - maxTime /
/ } /user:& TODO Auto-generated catch block
JOptionP)+&quot.println(& + e? &quot.fillOval(tempX - 7;image/
} catch (NumberFormatException e1) {
/ *&#47.BLACK); 19;= 10 && x &/&#47.awt.getY() &= 200) {
JOptionP/ 60 * 60);
y = e.setColor(C
* while (color == allChess[x - 0][y - i2]) { count2++;= 18
&& color == allChess[x + xChange][y + yChange]) {
count++;= 470 && e, 4).showConfirmDialog( 3600 * 60) + &+e;/ i++;* S 双缓冲技术防止屏幕闪烁
BufferedImage bi = new BufferedImage(500; i4++;).getX() &
blackMessage = blackTime /
whiteMessage = maxTime &#47, 14,如果输入0.drawLine(10 + 20 * i, tempY - 7; 0)
yChange++, 4.setColor(Color./ TODO Auto-generated method stub } public void mouseExited(MouseEvent e) {
&#47.getY());;黑方先行&quot.showMessageDialog(this.MouseL/ 20;
maxTime = I
&#47, 248; int count4 = 1 , Font.BOLD;
this, 368; i4++;
whiteMessage = &&#47: 的显示改回到开始位置
if (maxTime == 0) {
int result = JOptionPane, 128; j & 60 * 60); TODO Auto-generated method stub
&#47.drawString(&= 18
&& color == allChess[x - xChange][y - yChange]) {
/; 60 - maxTime / i &lt, 60)./ 20 * 20 + 10 ;
&#47, 4;无限制&quot.fillOval(188;);
&& y - yChange & 点击 游戏设置 按钮
g2;白方超时.drawString(&&#47.getProperty(&quot.BLACK) ; } public void mouseClicked(MouseEvent e) {
this!&quot, -1;/ } /&#47,游戏结束;), 1.BufferedI i &lt: & TODO Auto-generated catch block
e, 4), 10 + 20 * i, 430).out, 4.getY() & String whiteMessage = &
* while (color == allChess[x + 0][y + i2]) { count2++;;
yChange--;= 0 && x + xChange & j++) {
if (allChess[i][j] == 1) {
whiteTime--;,是否重新开始游戏; while (color == allChess[x + i4][y + i4]) {
* count4++;
/ 判断当前要下的是什么颜色的棋子
if (isBlack == true) {
allChess[x][y] = 1;
&#47.绘制棋子 x = (x - 10) / 判断右下;
if (winFlag == true) {
JOptionPane.checkCount(1;= 5) {
flag = 斜方向的判断(右下 + 左上) int i4 =
* 1 .fillOval(x - 7;X,游戏结束; } / /
g2.showMessageDialog(this, &quot.setColor(C j++) {
allChess[i][j] = 0.getX(), y - 7;游戏结束& 3600 * 60) + &
this, 14.getX() &
yChange = tempY; 点击 游戏说明 按钮
if (e;= 370 && y &
&#47.drawOval(x - 7, 14; } if (count3 &gt.setResizable(false)./ 19.getY() &
&#47!&quot.replaceAll(& 判断右上!&&#47.fillOval(tempX - 7;
/ i &lt, tempY - 7;
/ TODO Auto-generated method stub } public void mousePressed(MouseEvent e) {
&#47:& i2++; while (color == allChess[x - i4][y - i4]) {
* count4++; System.println(& 绘制全部棋子
for (int i = 0;; 判断棋子连接的数量 private int checkCount(int xC }
if (canPlay == true) {
x = e. 保存共有相同颜色多少棋子相连
int count = 1,请重新落子.checkWin().showMessageDialog( + message.showMessageDialog(
* i3++.showMessageDialog(
yChange--;
JOptionPane.getY() &lt.getY() &
if (result == 0) {
* (count & 19;
if (maxTime &; 绘制棋盘
for (int i = 0; 60 - maxTime /请正确输入信息;
if (result == 0) {
for (int i = 0; int
* count3 = 1 ; 3600 * 60) + &quot.resume(); 判断横向
count == 400 &&
blackMessage = &本游戏由MLDN制作;&#47.repaint();设置完成;; while (color == allChess[x + i][y + 0]) { count++、左上
/ 另一种方式 allChess = new int[19][19];);
blackTime = maxT
* i3++;/ 保存显示的提示信息 String message = &&#47:&
+ (maxTime - maxTime /
int tempY = j * 20 + 70.showMessageDialog(this, 14).getY() & TODO Auto-generated method stub } private boolean checkWin() {
boolean flag =*
* if (color == allChess[x+1][y]) { count++; 3600 * 60) + & if (color == allChess[x+3][y]) {
* count++;= 400 && 纵向的判断 int i2 = 1 ; 保存最多拥有多少时间(秒) int maxTime = 0.checkCount(0;&#47.Graphics.Color.awt?&
&#47. 设置标题
this.drawImage(bgI/; j &/= 5) { flag =
int tempY = yChange:&= 5) { flag =
whiteMessage = &quot.IOEimport java, 4); 另一种方式 allChess = new int[19][19].liky.setVisible(true)
提问者评价
谢了 哥们!
其他类似问题
五子棋的相关知识
您可能关注的推广回答者:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Java五子棋游戏源代码
-------------
新增文件夹...
新增文件夹
(多个标签用逗号分隔)
FiveChessFrame.java
package myGameF
import java.awt.C
import java.awt.F
import java.awt.G
import java.awt.T
import java.awt.event.MouseE
import java.awt.event.MouseL
import java.awt.image.BufferedI
import java.io.F
import java.io.IOE
import java.util.C
import javax.imageio.ImageIO;
import javax.swing.JF
import javax.swing.JOptionP
public class FiveChessFrame extends JFrame implements MouseListener {
int width=Toolkit.getDefaultToolkit().getScreenSize().
int height=Toolkit.getDefaultToolkit().getScreenSize().
BufferedImage bgImage=
//保存棋子的坐标
int x=0;int y=0;
//保存之前下过的全部棋子的坐标
//其中的数据内容:0,没有棋子 1,黑子
int[][] allChess=new int[19][19];
//标识当前是黑棋还是白棋
boolean isBlack=
//表示当前游戏是否可以继续
boolean canPlay=
public FiveChessFrame()
setTitle("五子棋");
setSize(500, 500);
setLocation((width-500)/2,(height-500)/2);
setResizable(false);
addMouseListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
bgImage=ImageIO.read(new File("D:/bg.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
setVisible(true);
public void paint(Graphics g)
g.drawImage(this.bgImage, 0,20,this);
g.setFont(new Font("黑体",Font.BOLD,20));
g.drawString("游戏信息", 120, 60);
g.setFont(new Font("送体",Font.BOLD,12));
g.drawString("黑方时间", 60, 480);
g.drawString("白方时间", 260, 480);
//横360,竖360,左上12,73,右上372,73,左下12,433,右下372,433
int y_index=0;
for (int i = 0; i & 19; i++) {
g.drawLine(12, 73+y_index, 372, 73+y_index);
y_index+=20;
int x_index=0;
for (int i = 0; i & 19; i++) {
g.drawLine(12+x_index, 73, 12+x_index, 433);
x_index+=20;
g.fillOval(70, 131, 4, 4);
g.fillOval(310, 131, 4, 4);
g.fillOval(70, 371, 4, 4);
g.fillOval(310, 371, 4, 4);
//绘制全部棋子
for (int i = 0; i&19; i++) {
for (int j = 0; j & 19; j++) {
if(this.allChess[i][j]==1)
int tempX=i*20+12;
int tempY=j*20+73;
g.fillOval(tempX-7, tempY-7, 14, 14);
if(this.allChess[i][j]==2)
int tempX=i*20+12;
int tempY=j*20+73;
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 static void main(String[] args) {
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
public void mousePressed(MouseEvent e) {
if(canPlay==false)
System.out.println(e.getX()+"---"+e.getY());
x=e.getX();
y=e.getY();
if(x&=12&&x&=372&&y&=73&&y&433)
x=(x-12)/20;
y=(y-73)/20;
if(allChess[x][y]==0)
if(this.isBlack==true)
allChess[x][y]=1;
allChess[x][y]=2;
//判断这个棋子是否和其他棋子连成5个
boolean winFlag=this.Check_Win();
if(winFlag)
JOptionPane.showMessageDialog(this, "游戏结束,"+(allChess[x][y]==1?"黑方":"白方")+"获胜");
JOptionPane.showMessageDialog(this, "当前已有棋子,不能再下了!");
this.repaint();
private boolean Check_Win()
boolean flag=
//保存共有多少相同颜色的棋子相连
int count=1;
//先判断横向,特点,y坐标相同,即allChess[x][y]中y相同
//判断这个棋子的颜色
int color=this.allChess[x][y];
if(color==allChess[x+1][y])
if(color==allChess[x+2][y])
//用循环来做棋子相连的判断!
int i=1;//横向向右判断
while(color==this.allChess[x+i][y])
//横向向左判断
while(color==this.allChess[x-i][y])
if(count&=5)
//综向判断
int count2=1;
while(color==this.allChess[x][y+i2])
while(color==this.allChess[x][y-i2])
if(count2&=5)
//斜方向判断,y=x方向
int count3=1;
while(color==this.allChess[x+i3][y-i3])
while(color==this.allChess[x-i3][y+i3])
if(count3&=5)
//斜方向,y=-x
int count4=1;
while(color==this.allChess[x-i4][y-i4])
while(color==this.allChess[x+i4][y+i4])
if(count4&=5)
//判断横向
count=Check_Count(1, 0, color);
if(count&=5)
//判断纵向
count=Check_Count(0, 1, color);
if(count&=5)
//判断右上,左下
count=Check_Count(1, -1, color);
if(count&=5)
//判断左上,右下
count=Check_Count(1, 1, color);
if(count&=5)
//判断棋子连接的数量
private int Check_Count(int xChange,int yChange,int color)
int count=1;
int tempX=xC
int tempY=yC
while(color==this.allChess[x+xChange][y+yChange])
if(xChange!=0)
xChange++;
if(yChange!=0)
if(yChange&0)
yChange++;
if(yChange&0)
yChange--;
xChange=tempX;yChange=tempY;
while(color==this.allChess[x-xChange][y-yChange])
if(xChange!=0)
xChange++;
if(yChange!=0)
if(yChange&0)
yChange++;
if(yChange&0)
yChange--;
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
myChessFrame.java
package myGameF
import java.awt.C
import java.awt.G
import java.awt.T
import java.awt.event.MouseE
import java.awt.event.MouseL
import java.awt.image.BufferedI
import java.io.F
import java.io.IOE
import javax.imageio.ImageIO;
import javax.swing.JF
import javax.swing.JOptionP
public class myChessFrame extends JFrame implements MouseListener {
public myChessFrame()
this.setTitle("五子棋");
this.setSize(500,400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addMouseListener(this);
this.setVisible(true);
public void mouseClicked(MouseEvent e) {
repaint();
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
public void paint(Graphics g)
g.setColor(new Color(244,100,20));
g.setColor(Color.red);
g.drawString("asdjkadslkd",10,10);
g.drawOval(10, 10, 300, 100);
BufferedImage image=
image = ImageIO.read(new File("D:/1.bmp"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
g.drawImage(image,100,100,this);
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
package myGameT
import myGameFrame.*;
import java.awt.T
import javax.swing.JF
import javax.swing.JOptionP
public class Test {
* @param args
public static void main(String[] args) {
new FiveChessFrame();
int x=130;
System.out.println((x-10)/20);
相关资讯  — 
相关文档  — 
发布时间: 23:11:19
同类热门经验
11152次浏览
6973次浏览
6083次浏览
5882次浏览
3890次浏览
6865次浏览
OPEN-OPEN, all rights reserved.需要class,interface或enum java运行_百度知道
需要class,interface或enum java运行
swing.AutoPlay.Evaluate.MouseEvent.event.IOException.io.frame.awt每一带import的行 都提示这个错误
一共16个 也就是这16行 别的地方没提示错误 代码无法全放上来
只好截了这一点 .getDefaultToolkit().game。.import java.game.game.height。:&#47.Font.import java.Graphics.image。.getScreenSize(); 取得屏幕的高度 int height = Toolkit。.JOptionP 背景图片 BufferedImage bgImage =public class FiveChess
extends JFrame implements MouseListener { &#47;&#47;&#47。;import java。.frame。;package com.Sort.width.ImageIO;&#47。.frame.awt.event.getScreenSize();&#47.frame.Color.Toolkit.BufferedI&#47.game。;import java。.awt.import java.awt.主类fivechess. 取得屏幕的宽度 int width = Toolkit.MouseLimport javax。.Scan.import java.awt.JFrame.; &#47.F &#47。&#47.getDefaultToolkit();import java
我有更好的答案
按默认排序
文件的编码,是不是保存成unicode或带bom的utf-8文件了
其他类似问题
enum的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁求解~java窗体显示图片和画图问题_百度知道
求解~java窗体显示图片和画图问题
getScreenSize();
}}为什么只显示了paint()函数的画图效果,this); , 470).swing.宋体&quot.getProperty(&quot.println(f;);public class FiveChessFrame extends JFrame implements MouseListener.setVisible(true);
}}&#47.BOLD .public class LoginDefault {
public static void main(String[] args) {
FiveChessFrame fcf = new FiveChessFrame().*.drawImage(&#47;
&#47.println(f;bin&#47.drawString(&quot.JFrame.&#47.Color.Font, 80 + 40 * i).getScreenSize().drawString(&
} catch (IOException e) {
public FiveChessFrame(){
} 取得屏幕的宽度
int width = Toolkit.awt, 0 ;import javax.setLocation((width - 500)&#47, 80 , 440).setSize(500.FiveChessF主类文件import frame, (height - 500)&#47.MouseE
String imagePath = S i++){ .jpg&
&#47.setResizable(false).getDefaultToolkit();
Graphics g = bi.Toolkit.EXIT_ON_CLOSE).width.TYPE_INT_ARGB).dir&quot.getAbsolutePath());
System.createGraphics();&#47. 取得屏幕的高度
int height = Toolkit, 500).drawLine(20 ;)+&2).G
for(int i = 0 .user.printStackTrace(),却没有背景图片, 0 ; 10 ;
System.getPath())package frame, 80 + 40 * i .
g.height.awt, 0 ;白方时间&quot, 260 .jpg&g;
this.read(f).awt, 20 + 40 *黑方时间;
this, 470);
this, 30 .IOE黑体&quot:&quot,14));五子棋&quot,
BufferedI i &background.imageio, 14)).event.setFont(new Font(&quot.setFont(new Font(&
BufferedImage bgImage = ImageIO;import javax.getDefaultToolkit().println(f.image.drawImage(
System, 380 , Runnable{
gg.setColor(C
public void paint(Graphics gg){
BufferedImage bi =new BufferedImage(500 .event. ;&#47, y.repaint();import java, observer)
g.black).getName()).MouseL).setTitle(&&#47.ImageIO, 500 .F2 ; ;import java.out.Point.setDefaultCloseOperation(JFrame, Font.io,
File f = new File(& ,bin&#47.drawLine(20 + 40 * i , height
,public class FiveChessFrame extends JFrame
implements MouseListener,忘记删了, Runnable多了Runnable
提问者采纳
bgIg, bgImage.getHeight(),BufferedIbgImage&就是你的背景图片;bgImage&nbsp,&把&nbspBufferedImage bi = new BufferedImage(500;Graphics g = bi.getWidth().TYPE_INT_ARGB), 500.drawImage(bgImage.createGraphics(),null)
怎么在构造函数外面把图片赋给bgimage? OnlyGetBackground bg = new OnlyGetBackground(); class OnlyGetBackground{
public OnlyGetBackground(){ try {
File f = new File(&bin&#47;background.jpg&);
bgImage = ImageIO.read(f);
} catch (IOException e) {
e.printStackTrace();
} }我在FiveChessFrame类里又弄了一个类,在调试的时候,bgImage已经读取到了,为什么还是只显示线条而已?
把 File f = new File(&bin&#47;background.jpg&);BufferedImage
bgImage = ImageIO.read(f); 把这2行代码放到 public FiveChessFrame() 的上面
这个需要try-catch才行,函数外面不可以执行呀!!!
BufferedImage
bgImage =这个放到 public FiveChessFrame() 的上面 bgImage = ImageIO.read(f);这个放到 public FiveChessFrame() 的 try 中
我原来的不就是这样的吗?try块中把多余的几句去掉不就是你说的吗?怎么又跑回来了?
import java.awt.Cimport java.awt.Fimport java.awt.Gimport java.awt.Timport java.awt.image.BufferedIimport java.io.Fimport java.io.IOEimport javax.imageio.ImageIO;import javax.swing.JFpublic class FiveChessFrame extends JFrame {// 取得屏幕的宽度int width = Toolkit.getDefaultToolkit().getScreenSize().// 取得屏幕的高度int height = Toolkit.getDefaultToolkit().getScreenSize().BufferedImage bgIpublic FiveChessFrame() {this.setTitle("五子棋");this.setSize(500, 500);this.setLocation((width - 500) / 2, (height - 500) / 2);this.setResizable(false);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);try {String imagePath = System.getProperty("user.dir")+ "/bin/background.jpg";File f = new File("bin/background.jpg");System.out.println(f.getPath());System.out.println(f.getName());System.out.println(f.getAbsolutePath());bgImage = ImageIO.read(f);} catch (IOException e) {e.printStackTrace();}this.setVisible(true);this.repaint();}public void paint(Graphics gg) {BufferedImage bi = new BufferedImage(500, 500,BufferedImage.TYPE_INT_ARGB);Graphics g = bi.createGraphics();g.drawImage(bgImage, 5,25,null);g.setColor(Color.black);g.setFont(new Font("宋体", 0, 14));g.drawString("黑方时间:", 30, 470);g.setFont(new Font("黑体", Font.BOLD, 14));g.drawString("白方时间", 260, 470);for (int i = 0; i & 10; i++) {g.drawLine(20, 80 + 40 * i, 380, 80 + 40 * i);g.drawLine(20 + 40 * i, 80, 20 + 40 * i, 440);}gg.drawImage(bi, 0, 0, this);}}
提问者评价
其他类似问题
按默认排序
其他1条回答
是是先画背景,重画棋盘,要是再加上一个棋子,我们当年都是那么干的设计一个repint函数,最后画棋子,再画棋盘,那就重画背景,重画棋子,一下子就画出来背景加棋盘就好了啊
java的相关知识
您可能关注的推广
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 hold是什么意思 的文章

 

随机推荐