Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- public class Class {
- public static void main(String[] args){
- int x = 500; int y = 500;
- JFrame f = new JFrame("Pixels");
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- GUI p = new GUI();
- p.setBackground(Color.WHITE);
- f.add(p);
- f.setSize(x,y);
- f.setVisible(true);
- }
- }
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.util.Random;
- public class GUI extends JPanel {
- private final static int MAX_X = 1920;
- private final static int MAX_Y = 1080;
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- for (int x = 0; x < MAX_X; x++) {
- for (int y = 0; y < MAX_Y; y++) {
- Color randomColor = Color.BLACK; //Black because it wouldn't work uninitialized.
- //Slightly inefficient?
- int number; Random rColor = new Random();
- number = rColor.nextInt(3);
- if(number == 0){randomColor = Color.RED;}
- else if(number ==1){randomColor = Color.GREEN;}
- else if(number == 2){randomColor = Color.BLUE;}
- g.setColor(randomColor); //Red, Blue, or Green. Depends on if number is 0, 1 or 2.
- g.drawRect(x, y, 1, 1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement