Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.zetcode.main;
- import javax.swing.*;
- public class Zetcode extends JFrame
- {
- private static final int WIDTH = 280;
- private static final int HEIGHT = 280;
- public Zetcode()
- {
- add(new Board());
- setVisible(true);
- setTitle("Donut");
- setSize(WIDTH, HEIGHT);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLocationRelativeTo(null);
- setResizable(false);
- }
- public static void main(String args[])
- {
- new Zetcode();
- }
- }
- -------------------------------------------------------------------------------------------------------------------------------------
- // The Board is a panel, where the game takes place.
- package com.zetcode.main;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import javax.swing.ImageIcon;
- import javax.swing.*;
- @SuppressWarnings("serial")
- public class Board extends JPanel
- {
- Image img;
- // We display an image of a town on the Board. The image is drawn inside the paint() method.
- public Board()
- {
- // We create an ImageIcon
- ImageIcon ii = new ImageIcon(this.getClass().getResource("house.jpeg"));
- // We get an Image out of the ImageIcon
- img = ii.getImage();
- }
- public void paint(Graphics g)
- {
- Graphics2D g2d = (Graphics2D) g;
- // We draw the image on the window
- g2d.drawImage(img, 10, 10, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment