Advertisement
Guest User

Compito

a guest
Apr 8th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import javax.swing.JFrame;
  4. /**
  5.  *
  6.  *
  7.  * @author Giacinto Di Santis
  8.  * @version 02.04.2020
  9.  */
  10.  
  11. public class IdenticonFrame extends JFrame {
  12.  
  13.     public final int MARGIN = 50;
  14.  
  15.     public IdenticonFrame() {
  16.         super("IdemticonFrame");
  17.         this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  18.         this.setSize(300,300);
  19.     }
  20.  
  21.     public boolean avatar[][]={
  22.         {true,  true,  true,  true,  true},
  23.         {false, false, false, false, false},
  24.         {true,  false, true,  false, true},
  25.         {true,  false, false, false, true},
  26.         {true,  false, false, false, true}
  27.     };
  28.  
  29.     public void paint(final Graphics g) {
  30.         super.paint(g);
  31.         int x;
  32.         int y;
  33.         for(x = 0; x < avatar.length; x++){
  34.             for(y = 0; y < avatr[x].length; y++){
  35.                 if(avatar[x][y] == true){
  36.                     g.setColor(Color.BLACK);
  37.                 }else{
  38.                     g.setColor(Color.WITHE);
  39.                 }
  40.                 if(getHeight() > getWidth()){
  41.                     g.fillRect(0, 0, (getWidth() - (2 * MARGIN)) / 5, (getWidth() - (2 * MARGIN)) / 5);
  42.                 }else{
  43.                     g.fillRect(0, 0, (getHeigth() - (2 * MARGIN)) / 5, (getHeigth() - (2 * MARGIN)) / 5);
  44.                 }
  45.             }
  46.         }
  47.     }
  48.  
  49.     public static void main(final String[] args) {
  50.         java.awt.EventQueue.invokeLater(new Runnable() {
  51.             public void run() {
  52.                 new IdenticonFrame().setVisible(true);
  53.             }
  54.         });
  55.     }
  56.    
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement