Advertisement
Zidinjo

Labor2

Apr 7th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1. package de.marvin.oopLabor2;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args)
  6.     {
  7.         MyFrameA ersteFenster = new MyFrameA();
  8.         ersteFenster.setTitle(1111);
  9.         MyFrameB zweitesFenster = new MyFrameB();
  10.         zweitesFenster.setTitle(2013);
  11.         new MyFrameC("zahlen",300,100);
  12.     }
  13. }
  14.  
  15. //-------------------------------------------------------
  16.  
  17. package de.marvin.oopLabor2;
  18.  
  19. import javax.swing.JFrame;
  20.  
  21. public class MyFrameA extends JFrame {
  22.    
  23.     private static final long serialVersionUID = 1L;
  24.  
  25.     MyFrameA()
  26.     {
  27.         this.setSize(200,200);
  28.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  29.         this.setLocation(300,300);
  30.         this.setResizable(false);
  31.         this.setVisible(true);
  32.     }
  33.    
  34.     protected void setTitle(int titel)
  35.     {
  36.         this.setTitle(Integer.toString(titel));
  37.     }
  38.  
  39. }
  40.  
  41. //-------------------------------------------------------
  42.  
  43. package de.marvin.oopLabor2;
  44.  
  45. import javax.swing.JLabel;
  46. import javax.swing.JPanel;
  47.  
  48. public class MyFrameB extends MyFrameA {
  49.    
  50.     private static final long serialVersionUID = 1L;
  51.    
  52.     MyFrameB()
  53.     {
  54.         this.setLocation(600,300);
  55.         this.setLabels();
  56.     }
  57.    
  58.     protected void setLabels()
  59.     {
  60.         JPanel FensterInFenster = new JPanel();
  61.         FensterInFenster.add(new JLabel("Hallo Flensburg"));
  62.         FensterInFenster.add(new JLabel("Hallo Deutschland"));
  63.         FensterInFenster.add(new JLabel("Hallo Welt"));
  64.         this.add(FensterInFenster);
  65.     }
  66.    
  67.     protected void setTitle(int titel)
  68.     {
  69.         this.setTitle(Integer.toString(titel));
  70.     }
  71.  
  72. }
  73.  
  74. //-------------------------------------------------------
  75.  
  76. package de.marvin.oopLabor2;
  77.  
  78. import java.awt.FlowLayout;
  79. import javax.swing.JFrame;
  80. import javax.swing.JLabel;
  81.  
  82. public class MyFrameC extends MyFrameA {
  83.  
  84.     private static final long serialVersionUID = 1L;
  85.  
  86.     MyFrameC(String title,int groesse,int anzahlDerWerte)
  87.     {
  88.         this.setSize(groesse,groesse);
  89.         this.setLocation(900,300);
  90.         this.setTitle(title);
  91.         this.setLayout(new FlowLayout());
  92.         this.unsereLabels(anzahlDerWerte,this);
  93.     }
  94.    
  95.     protected void unsereLabels(int anzahlDerWerte,JFrame meinFenster)
  96.     {
  97.         JLabel[] vieleFenster = new JLabel[anzahlDerWerte+1];
  98.        
  99.         for(int i =1;i < vieleFenster.length;i++)
  100.         {
  101.             if(i%2==0)
  102.             {
  103.                 vieleFenster[i] = new JLabel(Integer.toString(i));
  104.                 meinFenster.add(vieleFenster[i]);
  105.             }
  106.         }  
  107.     }
  108.    
  109.     protected void setTitle(int titel)
  110.     {
  111.         this.setTitle(Integer.toString(titel));
  112.     }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement