Vererbung (Java): Unterschied zwischen den Versionen

Aus Byte-Welt Wiki
Zur Navigation springenZur Suche springen
(Erst mal nur das Grundgerüst meiner alten Beschreibung vom Januar 2010. Nur die Programmcodes sind momentan enthalten.)
 
K
Zeile 2: Zeile 2:
  
 
{|
 
{|
|style="width:25em"|<code=java>     
+
|style="width:30em"|<code=java>     
 
       
 
       
 
                                           
 
                                           
Zeile 26: Zeile 26:
 
</code=java>
 
</code=java>
 
|style="width:1em"|
 
|style="width:1em"|
|style="width:25em"|<code=java>import javax.swing.*;
+
|style="width:30em"|<code=java>import javax.swing.*;
 
import java.awt.*;
 
import java.awt.*;
  
Zeile 57: Zeile 57:
  
 
{|
 
{|
|style="width:25em"|<code=java>import javax.swing.*;
+
|style="width:30em"|<code=java>import javax.swing.*;
  
 
public class myFrame extends JFrame{
 
public class myFrame extends JFrame{
Zeile 81: Zeile 81:
 
</code=java>
 
</code=java>
 
|style="width:1em"|
 
|style="width:1em"|
|style="width:25em"|<code=java>import javax.swing.*;
+
|style="width:30em"|<code=java>import javax.swing.*;
 
import java.awt.*;
 
import java.awt.*;
  
Zeile 118: Zeile 118:
  
 
{|
 
{|
|style="width:25em"|<code=java>import javax.swing.*;
+
|style="width:30em"|<code=java>import javax.swing.*;
 
import java.awt.*;
 
import java.awt.*;
  
Zeile 141: Zeile 141:
 
}</code=java>
 
}</code=java>
 
|style="width:1em"|
 
|style="width:1em"|
|style="width:25em"|<code=java>public class myProgram {
+
|style="width:30em"|<code=java>public class myProgram {
  
 
   public static void main(String[] args) {
 
   public static void main(String[] args) {
Zeile 179: Zeile 179:
  
 
{|
 
{|
|style="width:25em"|<code=java>import javax.swing.*;
+
|style="width:30em"|<code=java>import javax.swing.*;
 
import java.awt.*;
 
import java.awt.*;
  
Zeile 206: Zeile 206:
 
}</code=java>
 
}</code=java>
 
|style="width:1em"|
 
|style="width:1em"|
|style="width:25em"|<code=java>     
+
|style="width:30em"|<code=java>     
 
     
 
     
 
     
 
     
Zeile 245: Zeile 245:
  
 
{|
 
{|
|style="width:25em"|<code=java>import javax.swing.*;
+
|style="width:30em"|<code=java>import javax.swing.*;
 
import java.awt.*;
 
import java.awt.*;
  
Zeile 266: Zeile 266:
 
</code=java>
 
</code=java>
 
|style="width:1em"|
 
|style="width:1em"|
|style="width:25em"|<code=java>import javax.swing.*;
+
|style="width:30em"|<code=java>import javax.swing.*;
  
 
public class myProgram {
 
public class myProgram {
Zeile 296: Zeile 296:
  
 
{|
 
{|
|style="width:25em"|<code=java>import javax.swing.*;
+
|style="width:30em"|<code=java>import javax.swing.*;
 
import java.awt.*;
 
import java.awt.*;
  
Zeile 322: Zeile 322:
 
</code=java>
 
</code=java>
 
|style="width:1em"|
 
|style="width:1em"|
|style="width:25em"|<code=java>import javax.swing.*;
+
|style="width:30em"|<code=java>import javax.swing.*;
 
import java.awt.*;
 
import java.awt.*;
  

Version vom 13. August 2013, 17:35 Uhr

Programm 1

<code=java>     
     

            

           
      
      

                                                                                               </code=java>

<code=java>import javax.swing.*;

import java.awt.*;

public class myProgram {

 public static void main(String[] args) {
   JFrame f = new JFrame("My Window");
   JPanel p = new JPanel();
   JButton b1 = new JButton("Button 1");
   JButton b2 = new JButton("Button 2");
   JButton b3 = new JButton("Button 3");
   b1.setBackground(new Color(255,0,0));
   b3.setBackground(new Color(255,0,0));
   p.add(b1);
   p.add(b2);
   p.add(b3);
   f.add(p);
   f.pack();
   f.setVisible(true);
 }

}</code=java>



Programm 2


<code=java>import javax.swing.*;

public class myFrame extends JFrame{

 myFrame(String name) {
   super(name);
 }

}                                                                                                                               </code=java>

<code=java>import javax.swing.*;

import java.awt.*;

public class myProgram {

 public static void main(String[] args) {
   myFrame f = new myFrame("My Window");
   JPanel p = new JPanel();
   JButton b1 = new JButton("Button 1");
   JButton b2 = new JButton("Button 2");
   JButton b3 = new JButton("Button 3");
   b1.setBackground(new Color(255,0,0));
   b3.setBackground(new Color(255,0,0));
   p.add(b1);
   p.add(b2);
   p.add(b3);
   f.add(p);
   f.pack();
   f.setVisible(true);
 }

}</code=java>






Programm 3


<code=java>import javax.swing.*;

import java.awt.*;

public class myFrame extends JFrame{

 myFrame() {
   super("My Window");
   JPanel p = new JPanel();
   JButton b1 = new JButton("Button 1");
   JButton b2 = new JButton("Button 2");
   JButton b3 = new JButton("Button 3");
   b1.setBackground(new Color(255,0,0));
   b3.setBackground(new Color(255,0,0));
   p.add(b1);
   p.add(b2);
   p.add(b3);
   this.add(p);
   this.pack();
   this.setVisible(true);
 }

}</code=java>

<code=java>public class myProgram {
 public static void main(String[] args) {
   myFrame f = new myFrame();
 }

}                                                                                           </code=java>






Programm 4


<code=java>import javax.swing.*;

import java.awt.*;

public class myFrame extends JFrame{

 myFrame() {
   super("My Window");
   JPanel p = new JPanel();
   JButton b1 = new JButton("Button 1");
   JButton b2 = new JButton("Button 2");
   JButton b3 = new JButton("Button 3");
   b1.setBackground(new Color(255,0,0));
   b3.setBackground(new Color(255,0,0));
   p.add(b1);
   p.add(b2);
   p.add(b3);
   this.add(p);
   this.pack();
   this.setVisible(true);
 }
 public static void main(String[] args) {
   myFrame f = new myFrame();
 }

}</code=java>

<code=java>     

                                                                                                                                                     </code=java>




Programm 5


<code=java>import javax.swing.*;

import java.awt.*;

public class RedButton extends JButton {

 RedButton(String name) {
   super(name);
   this.setBackground(new Color(255,0,0));
 }

}                                                 </code=java>

<code=java>import javax.swing.*;

public class myProgram {

 public static void main(String[] args) {
   myFrame f = new myFrame("My Window");
   JPanel p = new JPanel();
   RedButton b1 = new RedButton("Button 1");
   JButton b2 = new JButton("Button 2");
   RedButton b3 = new RedButton("Button 3");
   p.add(b1);
   p.add(b2);
   p.add(b3);
   f.add(p);
   f.pack();
   f.setVisible(true);
 }

}</code=java>




Programm 6


<code=java>import javax.swing.*;

import java.awt.*;

public class RedButton extends JButton {

 RedButton(String name) {
   super(name);
   this.setBackground(new Color(255,0,0));
 }

}                                                                               </code=java>

<code=java>import javax.swing.*;

import java.awt.*;

public class myFrame extends JFrame{

 myFrame() {
   super("My Window");
   JPanel p = new JPanel();
   RedButton b1 = new RedButton("Button 1");
   JButton b2 = new JButton("Button 2");
   RedButton b3 = new RedButton("Button 3");
   p.add(b1);
   p.add(b2);
   p.add(b3);
   this.add(p);
   this.pack();
   this.setVisible(true);
 }
 public static void main(String[] args) {
   myFrame f = new myFrame();
 }

}</code=java>