Advertisement
Raider_Nagib

Untitled

Apr 7th, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public class Surface extends JPanel {
  2. private BufferedImage img;
  3. public int[][] pixels;
  4. private int width, height;
  5.  
  6. private Surface() {
  7.  
  8. }
  9.  
  10. public Surface(int width, int height) {
  11. img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  12. pixels = new int[width][height];
  13. this.width = width;
  14. this.height = height;
  15. }
  16.  
  17. public void fillSurface() {
  18. for (int x = 0; x < pixels.length; x++) {
  19. for (int y = 0; y < pixels[x].length; y++) {
  20. img.setRGB(x, y, pixels[x][y]);
  21. }
  22. }
  23. }
  24.  
  25. @Override
  26. public void paintComponent(Graphics g) {
  27. Graphics2D g2 = (Graphics2D) g;
  28. g2.drawImage(img, 0, 0, null);
  29. g2.dispose();
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement