Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.67 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.io.*;
  3. import java.awt.*;
  4. import java.util.*;
  5. import java.lang.Math;
  6. import java.util.Arrays;
  7. import java.util.Random;
  8.  
  9. final class Fenster {
  10.     public static final int BREITE = 1200, HOEHE = 800;
  11.  
  12.     private final JFrame fenster;
  13.     private final Leinwand leinwand;
  14.  
  15.     public Fenster() {
  16.         leinwand = new Leinwand();
  17.         fenster = new JFrame("");
  18.         initialisiereFenster();
  19.     }
  20.  
  21.     private void initialisiereFenster() {
  22.         fenster.setSize(Fenster.BREITE, Fenster.HOEHE);
  23.         fenster.setDefaultCloseOperation(fenster.EXIT_ON_CLOSE);
  24.         fenster.setVisible(true);
  25.         fenster.setResizable(false);
  26.         fenster.add(leinwand);
  27.         fenster.setLocationRelativeTo(null);
  28.     }
  29. }
  30.  
  31. final class Leinwand extends JPanel {
  32.  
  33.     int zeit = 0;
  34.     public Leinwand() {
  35.         setBackground(Color.BLACK);
  36.     }
  37.  
  38.     public void paintComponent(final Graphics g) {
  39.         super.paintComponent(g);
  40.         g.setColor(Color.RED);
  41.  
  42.         if(zeit <= 6000){
  43.             zeichneEins(g);
  44.         } else if(zeit >= 6000 && zeit <= 12000) { // die 2
  45.             zeichneZwei(g);
  46.         }
  47.  
  48.         ++zeit;
  49.         repaint();
  50.     }
  51.  
  52.     public void zeichneEins(final Graphics g) { //Erstelle die eins
  53.         for (int i = 30; i < 50; i++) {
  54.             g.fillRect(randomBetween(130, 140), randomBetween(90, 100), 4, 4); //hier sollen verschiedene rechtecke enstehen die den Kopf bilden
  55.             g.fillRect(randomBetween(120, 130), randomBetween(100, 110), 4, 4); //voll geil :O
  56.             g.fillRect(randomBetween(110, 120), randomBetween(110, 120), 4, 4);
  57.             g.fillRect(randomBetween(100, 110), randomBetween(120, 130), 4, 4);
  58.         }
  59.         for (int j = -80; j < 50; j++) {
  60.             g.fillRect(randomBetween(130, 140), randomBetween(100, 180), 4, 4); // hier das gleiche bloss fΓΌr |
  61.  
  62.         }
  63.     }
  64.     //ende der eins
  65.     public void zeichneZwei(final Graphics g) { //zeichneZwei
  66.         for(int i = -60; i < 100; i++){
  67.             g.fillRect(randomBetween(130,140), randomBetween(100,110), 4, 4);
  68.             g.fillRect(randomBetween(140,150), randomBetween(90,100), 4, 4);
  69.             g.fillRect(randomBetween(150,160), randomBetween(80,90), 4, 4);
  70.             g.fillRect(randomBetween(160,170), randomBetween(80,81), 4, 4);
  71.         }
  72.     }
  73. //beendet
  74.  
  75.     private static int randomBetween(final int min, final int max) {
  76.         return new Random().nextInt(max - min) + min; //Befehl randomBetween berechnen und erstellen
  77.     }
  78. }
  79. // ende ^^
  80.  
  81. public class BauplanFensterMitAnimation {
  82.     public static void main(final String[] args) {
  83.         new Fenster();
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement