Mercurial > hg > ristipolku
comparison Ristipolku.java @ 4:e0e8fd08331e
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 28 Jan 2011 17:37:01 +0200 |
parents | 1785f66a7beb |
children | be0bf7544069 |
comparison
equal
deleted
inserted
replaced
3:b8fd19e2d879 | 4:e0e8fd08331e |
---|---|
1 /* | 1 /* |
2 * Ristipolku | 2 * Ristipolku |
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org> | 3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
4 * | 4 * |
5 * Ohjelmointiprojekti Java-kurssille . | 5 * Ohjelmointiprojekti 2010-2011 Java-kurssille T740306. |
6 */ | 6 */ |
7 import java.awt.*; | 7 import java.awt.*; |
8 import java.awt.geom.*; | 8 import java.awt.geom.*; |
9 import java.awt.event.*; | 9 import java.awt.event.*; |
10 import javax.swing.*; | 10 import javax.swing.*; |
50 { | 50 { |
51 for (int y = 0; y < boardSize; y++) | 51 for (int y = 0; y < boardSize; y++) |
52 for (int x = 0; x < boardSize; x++) | 52 for (int x = 0; x < boardSize; x++) |
53 if (board[x][y] != null) | 53 if (board[x][y] != null) |
54 { | 54 { |
55 board[x][y].paint(g, sx + (x * scale), sy + (y * scale), scale - scale/10); | 55 board[x][y].paint(g, |
56 sx + (x * scale), | |
57 sy + (y * scale), | |
58 scale - scale / 10); | |
56 } | 59 } |
57 } | 60 } |
58 | 61 |
59 private boolean isEmpty(int x, int y) | 62 private boolean isEmpty(int x, int y) |
60 { | 63 { |
90 } | 93 } |
91 } | 94 } |
92 } | 95 } |
93 | 96 |
94 | 97 |
95 public class gfxtest extends JApplet | 98 public class Ristipolku extends JApplet |
96 implements KeyListener | 99 implements KeyListener |
97 { | 100 { |
98 GameBoard lauta; | 101 GameBoard lauta = null; |
102 BufferedImage lautaBG = null; | |
99 | 103 |
100 public void init() | 104 public void init() |
101 { | 105 { |
102 getContentPane().setBackground(Color.white); | 106 getContentPane().setBackground(Color.white); |
107 | |
108 try | |
109 { | |
110 lautaBG = ImageIO.read(new File("tausta.png")); | |
111 } | |
112 catch (IOException e) | |
113 { | |
114 JOptionPane.showMessageDialog(null, | |
115 "Could not load background image.", | |
116 "Initialization error", | |
117 JOptionPane.ERROR_MESSAGE); | |
118 } | |
119 | |
103 lauta = new GameBoard(); | 120 lauta = new GameBoard(); |
104 addKeyListener(this); | 121 addKeyListener(this); |
105 } | 122 } |
106 | 123 |
107 public void paint(Graphics g) | 124 public void paint(Graphics g) |
108 { | 125 { |
109 Graphics2D g2 = (Graphics2D) g; | 126 Graphics2D g2 = (Graphics2D) g; |
127 | |
110 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, | 128 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
111 RenderingHints.VALUE_ANTIALIAS_ON); | 129 RenderingHints.VALUE_ANTIALIAS_ON); |
130 | |
112 lauta.paint(g2, 15, 15, 60); | 131 lauta.paint(g2, 15, 15, 60); |
113 } | 132 } |
114 | |
115 | 133 |
116 public void keyPressed(KeyEvent e) | 134 public void keyPressed(KeyEvent e) |
117 { | 135 { |
118 } | 136 } |
119 | 137 |