24.11.4 Paint方法_Java从入门到精通_[共2页]

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

477
28 String whiteMessage ="无限制";
24.11.3 主类的构造函数
01 public FiveChessFrame() {
02 // 设置标题
03 this.setTitle("五子棋");
04 // 设置窗体大小
05 this.setSize(500, 500);
06 // 设置窗体出现位置
07 this.setLocation((width - 500) / 2, (height - 500) / 2);
08 // 将窗体设置为大小不可改变
09 this.setResizable(false);
10 // 将窗体的关闭方式设置为默认关闭后程序结束
11 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
12 // 为窗体加入监听器
13 this.addMouseListener(this);
14 // 将窗体显示出来
15 this.setVisible(true);
16 t.start();
17 t.suspend();
18 // 刷新屏幕,防止开始游戏时出现无法显示的情况
19 this.repaint();
20 String imagePath ="" ;
21 try {
22 imagePath =System.getProperty("user.dir")+"/bin/image/background.jpg" ;
23 bgImage =ImageIO.read(new File(imagePath.replaceAll("\\\\", "/")));
24 } catch (IOException e) {
25 // TODO Auto-generated catch block
26 e.printStackTrace();
27 }
28 }
24.11.4 Paint方法
01 public void paint(Graphics g) {
02 // 双缓冲技术防止屏幕闪烁
03 BufferedImage bi =new BufferedImage(500, 500,
04 BufferedImage.TYPE_INT_RGB);。

相关文档
最新文档