© 2005 pohlig informatik jg. 11 mfh michael pohlig 1 zum jframe step by step by step by step by...

13
Informatik Jg. 11 mfH Michael Pohlig 1 © 2005 Pohlig Zum JFrame Step by step by step by step by step by step by step by step by

Upload: meike-gierhart

Post on 06-Apr-2015

127 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 1

© 2005 Pohlig

Zum JFrame

Step by step by step by step by step by step by step by step by

Page 2: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 2

© 2005 Pohlig

step 1

public class HalloWelt2{ public static void main(String[] args){

}}

Page 3: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 3

© 2005 Pohlig

step 2

public class HalloWelt{ public HalloWelt(){

}

public static void main(String[] args){

}}

Mit Konstruktor, wird aber nicht aufgerufen

Page 4: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 4

© 2005 Pohlig

Step 3

public class HalloWelt{ public HalloWelt(){

}

public static void main(String[] args){ new HalloWelt(); }}

Konstruktor wird aufgerufen

Page 5: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 5

© 2005 Pohlig

Step 4

import javax.swing.*;public class HaloWelt extends JFrame{ public HalloWelt(){

}

public static void main(String[] args){ new HalloWelt(); }}

Man sieht aber nichts!

Page 6: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 6

© 2005 Pohlig

Step 5

import javax.swing.*;public class HalloWelt extends JFrame{ public HalloWelt(){ setVisible(true); }

public static void main(String[] args){ new HaloWelt(); }}

Bilderrahmen hat keinen Titel und das Objekt existiert noch, auch wenn es weggeklickt wird.

Page 7: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 7

© 2005 Pohlig

step 6

import javax.swing.*;public class HalloWelt extends JFrame{ public HalloWlet(String titel){ setVisible(true); }

public static void main(String[] args){ new HalloWelt("Ich bin ein JFrame-Objekt"); }}

Page 8: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 8

© 2005 Pohlig

step 7

import javax.swing.*;public class HalloWelt extends JFrame{ public HalloWelt(String titel){ super(titel); setVisible(true); }

public static void main(String[] args){ new HalloWelt("Ich bin ein JFrame-Objekt"); }}

Page 9: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 9

© 2005 Pohlig

step 8import javax.swing.*;public class HalloWelt extends JFrame{ public HalloWelt(String titel){ super(titel); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); }

public static void main(String[] args){ new HalloWelt("Ich bin ein JFrame-Objekt"); }}

Jetzt hört das JFrame-Objekt auf zu "existieren", wenn man es wegklickt.

Page 10: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 10

© 2005 Pohlig

step 9import javax.swing.*;public class HalloWelt extends JFrame{ public HalloWelt(String titel){ super(titel); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(300, 300); setVisible(true); }

public static void main(String[] args){ new HalloWelt("Ich bin ein JFrame-Objekt"); }}

Das JFrame-Objekt hat jetzt von Anfang an eine vernünftige Größe.

Page 11: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 11

© 2005 Pohlig

step 10import javax.swing.*;import java.awt.*;public class HalloWelt extends JFrame{ public HalloWelt(String titel){ super(titel); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(300, 300); Container cp = getContentPane(); cp.setLayout(new BorderLayout()); setVisible(true); }

public static void main(String[] args){ new HalloWelt("Ich bin ein JFrame-Objekt"); }}

Jetzt haben wir einen Behälter, der grafische Objekte aufnehmen kann.

Page 12: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 12

© 2005 Pohlig

Aufruf der Vorlage für einen JFrame

Vorlage JFrame

Page 13: © 2005 Pohlig Informatik Jg. 11 mfH Michael Pohlig 1 Zum JFrame Step by step by step by step by step by step by step by step by

Informatik Jg. 11 mfH Michael Pohlig 13

© 2005 Pohlig

Hallo Welt als JFrame

schriftzug wird als JLabel deklariert

schriftzug wird durch Erzeugen initialisiert und dem Behälter zugefügt