Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Surface extends JPanel {
- private BufferedImage img;
- public int[][] pixels;
- private int width, height;
- private Surface() {
- }
- public Surface(int width, int height) {
- img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- pixels = new int[width][height];
- this.width = width;
- this.height = height;
- }
- public void fillSurface() {
- for (int x = 0; x < pixels.length; x++) {
- for (int y = 0; y < pixels[x].length; y++) {
- img.setRGB(x, y, pixels[x][y]);
- }
- }
- }
- @Override
- public void paintComponent(Graphics g) {
- Graphics2D g2 = (Graphics2D) g;
- g2.drawImage(img, 0, 0, null);
- g2.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement