Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. public class Field extends JPanel {
  2.     public static final int width = 8;
  3.     public static final int height = 8;
  4.     public static final int scale = 40;
  5.     public static JFrame frame = new JFrame();
  6.  
  7.     public void paint(Graphics g) {
  8.  
  9.         g.setColor(color(230, 230, 230));
  10.         g.fillRect(0, 0, width * scale, height * scale);
  11.         g.setColor(color(100, 100, 100));
  12.         for (int i = 0; i < width * scale; i = i + scale * 2) {
  13.             g.drawLine(i, 0, i, height * scale);
  14.             g.drawLine(0, i, width * scale, i);
  15.         }
  16.         Font myFont = new Font("Times New Roman", Font.BOLD, 20);
  17.         g.setFont(myFont);
  18.         int y = 0;
  19.         for (int i = 0; i < 4; i++) {
  20.             int x = 0;
  21.             for (int j = 0; j < 4; j++) {
  22.                 g.drawString("" + Game.num[i][j], scale - 5 + x, scale + 5 + y);
  23.                 x = x + scale * 2;
  24.             }
  25.             y = y + scale * 2;
  26.         }
  27.     }
  28.  
  29.     public Color color(int red, int green, int blue) {
  30.         return new Color(red, green, blue);
  31.     }
  32.  
  33.  
  34.     public static JFrame Frame(String s) {
  35.         JFrame Frame = new JFrame(s);
  36.         Frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  37.         Frame.setResizable(false);
  38.         Frame.setSize(width * scale + 5, height * scale + 30);
  39.         Frame.setLocationRelativeTo(null);
  40.         Frame.add(new Field());
  41.         Frame.setVisible(true);
  42.         return Frame;
  43.  
  44.     }
  45.  
  46.     public static void main(String[] args) {
  47.         Game.start();
  48.         frame = Frame("2048");
  49.         Game gamer = new Game();
  50.  /*       frame.addKeyListener(new KeyAdapter() {
  51.                 public void keyPressed(KeyEvent e) {
  52.                     if (e.getKeyCode() == KeyEvent.VK_DOWN) {
  53.                         Game.down();
  54.                     }
  55.                     if (e.getKeyCode() == KeyEvent.VK_RIGHT)
  56.                         Game.right();
  57.                     if (e.getKeyCode() == KeyEvent.VK_UP)
  58.                         Game.up();
  59.                     if (e.getKeyCode() == KeyEvent.VK_LEFT)
  60.                         Game.left();
  61.                 }
  62.  
  63.             });
  64.  
  65.     }*/
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement