Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package project;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import javax.swing.JPanel;
- public class Panel extends JPanel{
- int x;
- int y;
- final static int width = 20;
- final static int height = 20;
- int [][]array = new int[20][20];
- public Panel(){
- this.setBackground(Color.WHITE);
- this.setPreferredSize(new Dimension(600,400));
- this.setVisible(true);
- fillArray();
- }
- public void fillArray(){
- array[5][3] = 1;
- array[12][1] = 1;
- array[0][0] = 1;
- array[11][3] = 2;
- array[2][1] = 2;
- array[0][7] = 2;
- }
- public void paint(Graphics g){
- for (int i = 0; i < 20; i++) {
- for (int j = 0; j < 20; j++) {
- if(array[i][j] == 1){
- g.setColor(Color.RED);
- g.fillRect(x+i*20, y+j*20, width, height);
- }
- else if(array[i][j] == 2){
- g.setColor(Color.BLUE);
- g.fillRect(x+i*20, y+j*20, width, height);
- }
- else{
- g.setColor(Color.WHITE);
- g.fillRect(x+i*20, y+j*20, width, height);
- }
- g.setColor(Color.BLACK);
- g.drawRect(x+i*20, y+j*20, width, height);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement