Posted By

unikate on 01/11/11


Tagged


Versions (?)

BAUM ;)


 / Published in: Java
 

  1. import java.awt.Color;
  2.  
  3. public class Baum extends JPanel{
  4.  
  5. private int breite;
  6. private int hoehe;
  7. private int x;
  8. private int y;
  9.  
  10. public Baum(int hoehe, int breite, int x, int y){
  11.  
  12. this.breite = breite;
  13. this.hoehe = hoehe;
  14. this.x = x;
  15. this.y = y;
  16. }
  17.  
  18. public void paintComponent(Graphics g){
  19.  
  20. g.setColor(Color.GREEN);
  21. g.drawRect(x, y, breite, hoehe);
  22. g.setColor(Color.BLACK);
  23. g.drawString("BAUM", x, y);
  24.  
  25. }
  26. }
  27.  
  28.  
  29.  
  30. import java.awt.GridLayout;
  31.  
  32. public class GUI extends JFrame{
  33.  
  34. private Baum a;
  35. private Baum b;
  36.  
  37. public static void main(String[] args){
  38. GUI g = new GUI();
  39. }
  40.  
  41. public GUI(){
  42.  
  43. //der frame muss in teile aufgeteilt werden
  44. this.setLayout(new GridLayout(0,1));
  45.  
  46. a = new Baum(50, 50, 50, 50);
  47. b = new Baum(60, 60, 100, 100);
  48.  
  49. //baum c, d, e, f
  50. //geschenk a, b, c
  51. //nun erweiterbar
  52.  
  53. this.add(a);
  54. this.add(b);
  55.  
  56. this.setSize(400, 400);
  57. this.setVisible(true);
  58.  
  59. }
  60.  
  61. }

Report this snippet  

You need to login to post a comment.