Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Field extends JPanel {
- public static final int width = 8;
- public static final int height = 8;
- public static final int scale = 40;
- public static JFrame frame = new JFrame();
- public void paint(Graphics g) {
- g.setColor(color(230, 230, 230));
- g.fillRect(0, 0, width * scale, height * scale);
- g.setColor(color(100, 100, 100));
- for (int i = 0; i < width * scale; i = i + scale * 2) {
- g.drawLine(i, 0, i, height * scale);
- g.drawLine(0, i, width * scale, i);
- }
- Font myFont = new Font("Times New Roman", Font.BOLD, 20);
- g.setFont(myFont);
- int y = 0;
- for (int i = 0; i < 4; i++) {
- int x = 0;
- for (int j = 0; j < 4; j++) {
- g.drawString("" + Game.num[i][j], scale - 5 + x, scale + 5 + y);
- x = x + scale * 2;
- }
- y = y + scale * 2;
- }
- }
- public Color color(int red, int green, int blue) {
- return new Color(red, green, blue);
- }
- public static JFrame Frame(String s) {
- JFrame Frame = new JFrame(s);
- Frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- Frame.setResizable(false);
- Frame.setSize(width * scale + 5, height * scale + 30);
- Frame.setLocationRelativeTo(null);
- Frame.add(new Field());
- Frame.setVisible(true);
- return Frame;
- }
- public static void main(String[] args) {
- Game.start();
- frame = Frame("2048");
- Game gamer = new Game();
- /* frame.addKeyListener(new KeyAdapter() {
- public void keyPressed(KeyEvent e) {
- if (e.getKeyCode() == KeyEvent.VK_DOWN) {
- Game.down();
- }
- if (e.getKeyCode() == KeyEvent.VK_RIGHT)
- Game.right();
- if (e.getKeyCode() == KeyEvent.VK_UP)
- Game.up();
- if (e.getKeyCode() == KeyEvent.VK_LEFT)
- Game.left();
- }
- });
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement