Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package flappybird;
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import javax.swing.JFrame;
- public class Game extends Canvas {
- public static final int HEIGHT = 400;
- public static final int WIDTH = HEIGHT * 4 / 3;
- public static final String NAME = "Flappy Bird";
- private JFrame frame;
- public Game() {
- frame = new JFrame();
- // Configuration JFrame
- Dimension dim = new Dimension(WIDTH, HEIGHT);
- frame.setPreferredSize(dim.getSize());
- frame.setMinimumSize(dim.getSize());
- frame.setMaximumSize(dim.getSize());
- frame.setTitle(NAME);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.add(this);
- frame.pack();
- frame.setVisible(true);
- // Configuration Canvas
- setBackground(Color.BLACK);
- }
- public void update() {
- System.out.println("test");
- }
- public void paint(Graphics g) {
- g.setColor(Color.WHITE);
- g.drawRect(10, 10, 100, 100);
- }
- public void start() {
- while (true) {
- update();
- paint(getGraphics());
- try {
- Thread.sleep(50);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- public static void main(String[] a) {
- Game game = new Game();
- game.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment