# Kurze Frage - Applet in Applet starten?



## MartinDeluxe (23. Mai 2007)

Hi. Ich hätte mal eine Frage. Ich hab mit Eclipse ein Paar Panel und Buttons erstellt und wollte nun mal fragen ob man in meinen Falle in jPanel2 ein Java-Applet starten kann indem man einen Button klickt. Ich möchte kein neues Fenster also keine neue URL aufrufen lassen. Hier erstmal mein Anfang:


```
import java.applet.Applet;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import javax.swing.BorderFactory;
import java.awt.Rectangle;


public class Innenfeld1 extends Applet {

	
	private static final long serialVersionUID = 1L;
	private JPanel jPanel = null;
	private JButton jButton = null;
	private JButton jButton1 = null;
	private JButton jButton2 = null;
	private JButton jButton3 = null;
	private JButton jButton4 = null;
	private JButton jButton5 = null;
	private JPanel jPanel1 = null;
	private JPanel jPanel2 = null;

	
	public Innenfeld1() {
		super();
		
	}

	
	public void init() {
        this.setLayout(new BorderLayout());
        this.setSize(new Dimension(510, 500));
        this.add(getJPanel(), BorderLayout.NORTH);
        this.add(getJPanel1(), BorderLayout.CENTER);
        
			
	}


	private JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(new FlowLayout());
			jPanel.setBorder(BorderFactory.createLineBorder(java.awt.Color.black, 2));
			jPanel.add(getJButton(), null);
			jPanel.add(getJButton1(), null);
			jPanel.add(getJButton2(), null);
			jPanel.add(getJButton3(), null);
			jPanel.add(getJButton4(), null);
			jPanel.add(getJButton5(), null);
		}
		return jPanel;
	}

	
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setText("Button1");
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jButton;
	}

	
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setText("Button2");
			jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					System.out.println("mouseClicked()"); // TODO Auto-generated Event stub actionPerformed()
					
				}
			});
		}
		return jButton1;
	}


	
	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setText("Button3");
			jButton2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jButton2;
	}

	
	private JButton getJButton3() {
		if (jButton3 == null) {
			jButton3 = new JButton();
			jButton3.setText("Button4");
			jButton3.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jButton3;
	}

	
	private JButton getJButton4() {
		if (jButton4 == null) {
			jButton4 = new JButton();
			jButton4.setText("Button5");
			jButton4.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jButton4;
	}

	
	private JButton getJButton5() {
		if (jButton5 == null) {
			jButton5 = new JButton();
			jButton5.setText("Button6");
			jButton5.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return jButton5;
	}

	
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setLayout(null);
			jPanel1.add(getJPanel2(), null);
		}
		return jPanel1;
	}

	
	private JPanel getJPanel2() {
		if (jPanel2 == null) {
			jPanel2 = new JPanel();
			jPanel2.setLayout(new GridBagLayout());
			jPanel2.setBounds(new Rectangle(15, 15, 481, 432));
			jPanel2.setBorder(BorderFactory.createLineBorder(java.awt.Color.black, 2));
		}
		return jPanel2;
	}

}
```

Ich habe mich noch nicht lange damit beschäftigt also entschuldige ich mich gleich mal wenn ich irgendetwas falsch beschrieben hab. :lol:  :lol: Danke im vorraus!

mfg Martin

_[Edit by Beni: Codetags]
[Edit by L-ectron-X: Dem Beitrag einen ordentlichen Titel verpasst_


----------



## JPKI (23. Mai 2007)

Bin jetzt zu faul um das durchzulesen, aber ich finde es unverschämt, so einen Thread-Titel bei so ner Menge Text zu verwenden, und dann noch nicht einmal Code-Tags zu verwenden :roll: .


----------



## merlin2 (23. Mai 2007)

Ich kann mich meinem Vorredner nur anschließen - und dabei vergisst er, sich über den Titel selbst zu beschweren.
Dass sich die Leute nicht mal einen Betreff ausdenken können!


----------



## HoaX (24. Mai 2007)

er hat sich doch einen ausgedacht, nur eben keinen der annähernd passt


----------



## L-ectron-X (24. Mai 2007)

Ein Applet erbt von Panel. Du kannst also jedes Applet als Panel-Ersatz verwenden, sofern es in deinem Classpath liegt. Nur musst du die Applet-Methoden aus dem Lebenszyklus selbst aufrufen.


----------



## MartinDeluxe (24. Mai 2007)

Erstmal vielen dank an denjenigen der mir da geholfen hat.(Thema+Code) Dann wollt ich mich auch gleich mal Entschuldigen! Sry! Aha und dh? Wie sähe das zum Beispiel aus?

Danke für die Antworten!


----------



## L-ectron-X (24. Mai 2007)

Ich kenne den Code von deinem Applet nicht, welches du in einem anderen Applet anzeigen willst.
Im Prinzip erzeugst du eine Instanz deines Applets, rufst die init()-Methode und dann die start()-Methode deines Applets auf und fügst es als Komponente dem Applet hinzu, welches es anzeigen soll.


----------



## MartinDeluxe (25. Mai 2007)

Ok danke, hat mir sehr geholfen!!


----------



## MartinDeluxe (25. Mai 2007)

```
import java.awt.BorderLayout;

import javax.imageio.ImageIO;
import javax.swing.ButtonGroup;
import javax.swing.JColorChooser;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.UIManager;

import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagLayout;
import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.JRadioButtonMenuItem;

public class Programm extends JApplet {
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 
	 */
	private JPanel jContentPane = null;
	private JPanel jPanel = null;
	private JPanel jPanel1 = null;
	private JButton jButton1 = null;
	private JButton jButton2 = null;
	private JButton jButton3 = null;
	private Color colorRed = null;//  @jve:decl-index=0:
	private int x = 0;  //  @jve:decl-index=0:
	private int y = 0;  //  @jve:decl-index=0:
	private int paintWidth = 1;
	private ArrayList liste = null;  //  @jve:decl-index=0:
	private JButton jButton4 = null;
	public BufferedImage image = null;  //  @jve:decl-index=0:
	private JButton jButton7 = null;
	private JMenuBar jJMenuBar = null;
	private JMenu jMenu = null;
	private JMenuItem jMenuItem = null;
	private JMenuItem jMenuItem1 = null;
	private JMenuItem jMenuItem2 = null;
	private JButton jButton5 = null;
	private JMenu jMenu1 = null;
	private JMenu jMenu2 = null;
	private JMenu jMenu3 = null;
	private JRadioButtonMenuItem jRadioButtonMenuItem = null;
	private JRadioButtonMenuItem jRadioButtonMenuItem1 = null;
	private JRadioButtonMenuItem jRadioButtonMenuItem2 = null;
	private JRadioButtonMenuItem jRadioButtonMenuItem3 = null;
	
	/**
	 * This is the xxx default constructor
	 */
	public Programm() {
		super();
		}
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	public void init() {
		try {
			UIManager.setLookAndFeel(new MetalLookAndFeel());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		this.setSize(500, 500);
		this.setJMenuBar(getJJMenuBar());
		this.setContentPane(getJContentPane());
		 colorRed=Color.black;
		 x=0;
		 y=0;
		 liste = new ArrayList();
		 image = new BufferedImage(1000,1000, BufferedImage.TYPE_INT_RGB);
		 Graphics2D g = (Graphics2D) image.getGraphics();
		 g.setColor(Color.white);
		 g.fillRect(0, 0, image.getWidth(), image.getHeight());
	}
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */

	
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.setBorder(BorderFactory.createMatteBorder(0, 2, 2, 2, Color.black));
			jContentPane.add(getJPanel(), BorderLayout.CENTER);
			jContentPane.add(getJPanel1(), BorderLayout.NORTH);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanel	
	 *
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new PaintPanel(this);
			jPanel.setLayout(new GridBagLayout());
			jPanel.setBackground(Color.white);
			
			jPanel.addMouseListener(new java.awt.event.MouseAdapter() {
				    public void mousePressed(final java.awt.event.MouseEvent e) {
					x=e.getX();
					y=e.getY();
				}
			});
			jPanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
				    public void mouseDragged(final java.awt.event.MouseEvent e) {
					final Graphics2D g = (Graphics2D) image.getGraphics();
					g.setColor(colorRed);
				    g.setStroke(new BasicStroke(paintWidth));
					g.drawLine(x, y, e.getX(), e.getY());
					liste.add(new Linie(x, y, e.getX(), e.getY(), colorRed,paintWidth));
					x=e.getX();
					y=e.getY();
					jPanel.repaint();
				}
			});
			
		}
		return jPanel;
	}
	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setLayout(new FlowLayout());
			jPanel1.setBorder(BorderFactory.createMatteBorder(2, 0, 2, 0, Color.black));
			jPanel1.add(getJButton5(), null);
			jPanel1.add(getJButton1(), null);
			jPanel1.add(getJButton2(), null);
			jPanel1.add(getJButton7(), null);
			jPanel1.add(getJButton4(), null);
			jPanel1.add(getJButton3(), null);
		}
		return jPanel1;
	}
	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setText("Rot");
			jButton1.setForeground(Color.red);
			jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(final java.awt.event.MouseEvent e) {
			        colorRed=Color.red;          
				}
				
			});
		}
		return jButton1;
	}
	/**
	 * This method initializes jButton2	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setText("GrÃ¼n");
			jButton2.setFont(new Font("Dialog", Font.BOLD, 12));
			jButton2.setForeground(Color.green);
			jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(final java.awt.event.MouseEvent e) {
					colorRed=Color.green;
				}
			});
		}
		return jButton2;
	}
	/**
	 * This method initializes jButton3	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton3() {
		if (jButton3 == null) {
			jButton3 = new JButton();
			jButton3.setText("X");
			jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(final java.awt.event.MouseEvent e) {
					dateineu();
					
				}
			});
		}
		return jButton3;
	}
	/**
	 * This method initializes jButton4	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton4() {
		if (jButton4 == null) {
			jButton4 = new JButton();
			jButton4.setText("Back");
			jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
				    long maxts=0;
				    int i;
				    for(i=0; i<liste.size();i++) {
				    	Linie l = (Linie) liste.get(i);
				    	if (l.ts>maxts) maxts = l.ts; 
				    }
				    i=0;
				    while(i<liste.size()) {
				    	Linie l = (Linie) liste.get(i);
				    	if (l.ts>(maxts-400)) liste.remove(i); else i++;
				    }
				    final Graphics2D g = (Graphics2D) image.getGraphics();
				    g.setColor(Color.white);
					g.fillRect(0, 0, image.getWidth(), image.getHeight());
					for(i=0; i<liste.size();i++) {
				    	Linie l = (Linie) liste.get(i);
				    	g.setColor(l.col);
				    	g.setStroke(new BasicStroke(l.width));
				    	g.drawLine(l.x1, l.y1, l.x2, l.y2);
				    }
				   jPanel.repaint();
				}
			});
		}
		return jButton4;
	}
	/**
	 * This method initializes jButton7	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton7() {
		if (jButton7 == null) {
			jButton7 = new JButton();
			jButton7.setText("Go");
			jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					final Graphics2D g = (Graphics2D) image.getGraphics();
					g.setColor(Color.white);
					g.fillRect(0, 0, image.getWidth(), image.getHeight());
					jPanel.repaint();
					Linie l = (Linie) liste.get(0);
					g.setColor(l.col);
					g.setStroke(new BasicStroke(paintWidth));
			    	g.drawLine(l.x1, l.y1, l.x2, l.y2);
			    	jPanel.paint(jPanel.getGraphics());
			    	long lastts = l.ts;
					for(int i=1; i<liste.size();i++) {
				    	l = (Linie) liste.get(i);
				    	long wait = l.ts - lastts;
				    	try {
							Thread.sleep(wait);
						} catch (InterruptedException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
				    	g.setColor(l.col);
				    	g.setStroke(new BasicStroke(paintWidth));    
				    	g.drawLine(l.x1, l.y1, l.x2, l.y2);
				    	jPanel.paint(jPanel.getGraphics());
				    	lastts = l.ts;
				    }
				   
					
				
				}
			
			});
		}
		return jButton7;
	}
	/**
	 * This method initializes jJMenuBar	
	 * 	
	 * @return javax.swing.JMenuBar	
	 */
	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.add(getJMenu());
			jJMenuBar.add(getJMenu1());
			jJMenuBar.add(getJMenu3());
			jJMenuBar.add(getJMenu2());
		}
		return jJMenuBar;
	}
	/**
	 * This method initializes jMenu	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getJMenu() {
		if (jMenu == null) {
			jMenu = new JMenu();
			jMenu.setText("Datei");
			jMenu.add(getJMenuItem());
			jMenu.add(getJMenuItem1());
			jMenu.add(getJMenuItem2());
		}
		return jMenu;
	}
	/**
	 * This method initializes jMenuItem	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem() {
		if (jMenuItem == null) {
			jMenuItem = new JMenuItem();
			jMenuItem.setText("Neu");
			jMenuItem.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dateineu();
				}
			});
		}
		return jMenuItem;
	}
	protected void dateineu() {
		final Graphics2D g = (Graphics2D) image.getGraphics();
		g.setColor(Color.white);
		g.fillRect(0, 0, image.getWidth(), image.getHeight());
		liste.clear();
		jPanel.repaint();
	}
	/**
	 * This method initializes jMenuItem1	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem1() {
		if (jMenuItem1 == null) {
			jMenuItem1 = new JMenuItem();
			jMenuItem1.setText("Laden (lokal)");
			jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					final JFileChooser fc = new JFileChooser();
					int returnVal = fc.showOpenDialog(Programm.this);
					if (returnVal == JFileChooser.APPROVE_OPTION){
						try {
							BufferedImage im = ImageIO.read(fc.getSelectedFile());
							Graphics g = image.getGraphics();
			                g.drawImage(im, 0, 0, null);
							liste.clear();
							BufferedReader fr = new BufferedReader(new FileReader(fc.getSelectedFile().getAbsoluteFile() + ".lst"));
							String zeile;
							while((zeile=fr.readLine())!=null) {
								StringTokenizer zeile_t = new StringTokenizer(zeile,":");
								Linie l = new Linie(Integer.parseInt(zeile_t.nextToken()),
													Integer.parseInt(zeile_t.nextToken()),
													Integer.parseInt(zeile_t.nextToken()),
													Integer.parseInt(zeile_t.nextToken()),
										  new Color(Integer.parseInt(zeile_t.nextToken())), 
										  			Integer.parseInt(zeile_t.nextToken()));
											   l.ts = Long.parseLong(zeile_t.nextToken());
								liste.add(l);
							}
						} catch (Exception e1) {
							// TODO Auto-generated catch block
							System.out.println("Fehler beim Lesen");
							e1.printStackTrace();
						}
					}
				}
			});
		}
		return jMenuItem1;
	}
	/**
	 * This method initializes jMenuItem2	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem2() {
		if (jMenuItem2 == null) {
			jMenuItem2 = new JMenuItem();
			jMenuItem2.setText("Speichern (lokal)");
			jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					final JFileChooser fc = new JFileChooser();
					int returnVal = fc.showSaveDialog(Programm.this);
					if (returnVal == JFileChooser.APPROVE_OPTION){
					File f = fc.getSelectedFile();
						try {
							ImageIO.write(image, "png" , f);
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							System.out.println("Fehler beim Schreiben");
							e1.printStackTrace();
						}

						FileWriter fw;
						try {
							fw = new FileWriter(fc.getSelectedFile().getAbsoluteFile() + ".lst");
						for(int i=0; i<liste.size();i++) {
					    	Linie l = (Linie) liste.get(i);
					    	String zeile = String.valueOf(l.x1) + ":" +  
					    	               String.valueOf(l.y1) + ":" + 
					    	               String.valueOf(l.x2) + ":" +
					    	               String.valueOf(l.y2) + ":" +
					    	               String.valueOf(l.col.getRGB()) + ":" +
					    	               String.valueOf(l.width) + ":" + 
					    	               String.valueOf(l.ts) +"\r\n";
					    	fw.write(zeile);
						}
						fw.close();
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}	
				}
			});
		}
		return jMenuItem2;
	}
	/**
	 * This method initializes jButton5	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton5() {
		if (jButton5 == null) {
			jButton5 = new JButton();
			jButton5.setText("Schwarz");
			jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
		        colorRed=Color.black;
				}
			});
		}
		return jButton5;
	}
	/**
	 * This method initializes jMenu1	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getJMenu1() {
		if (jMenu1 == null) {
			jMenu1 = new JMenu();
			jMenu1.setText("Farben");
			jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					setColor();
				}
			});
		}
		return jMenu1;
	}
	protected void setColor() {
		colorRed = JColorChooser.showDialog(this, "Farbe", colorRed);

}
	/**
	 * This method initializes jMenu2	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getJMenu2() {
		if (jMenu2 == null) {
			jMenu2 = new JMenu();
			jMenu2.setText("Schnellablauf");
			jMenu2.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					System.out.println("mouseClicked()"); // TODO Auto-generated Event stub mouseClicked()
					final Graphics2D g = (Graphics2D) image.getGraphics();
					g.setColor(Color.white);
					g.fillRect(0, 0, image.getWidth(), image.getHeight());
					jPanel.repaint();
					Linie l = (Linie) liste.get(0);
					g.setColor(l.col);
					g.setStroke(new BasicStroke(paintWidth));
			    	g.drawLine(l.x1, l.y1, l.x2, l.y2);
			    	jPanel.paint(jPanel.getGraphics());
			    	long lastts = l.ts;
					for(int i=1; i<liste.size();i++) {
				    	l = (Linie) liste.get(i);
				    	long wait = l.ts - lastts;
				    	try {
							Thread.sleep(5);
						} catch (InterruptedException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
				    	g.setColor(l.col);
				    	g.setStroke(new BasicStroke(paintWidth));
				    	g.drawLine(l.x1, l.y1, l.x2, l.y2);
				    	jPanel.paint(jPanel.getGraphics());
				    	lastts = l.ts;
				    }
				}
			});
		}
		return jMenu2;
	}
	/**
	 * This method initializes jMenu3	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getJMenu3() {
		if (jMenu3 == null) {
			jMenu3 = new JMenu();
			jMenu3.setText("StrichstÃ¤rke");
			jMenu3.add(getJRadioButtonMenuItem());
			jMenu3.add(getJRadioButtonMenuItem1());
			jMenu3.add(getJRadioButtonMenuItem2());
			jMenu3.add(getJRadioButtonMenuItem3());
			ButtonGroup grp = new ButtonGroup();
			grp.add(getJRadioButtonMenuItem());
			grp.add(getJRadioButtonMenuItem1());
			grp.add(getJRadioButtonMenuItem2());
			grp.add(getJRadioButtonMenuItem3());
			
		}
		return jMenu3;
	}
	/**
	 * This method initializes jRadioButtonMenuItem	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonMenuItem() {
		if (jRadioButtonMenuItem == null) {
			jRadioButtonMenuItem = new JRadioButtonMenuItem();
			jRadioButtonMenuItem.setText("1");
			jRadioButtonMenuItem.setSelected(true);
			jRadioButtonMenuItem.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					setPaintWidth();
				}
			});
		}
		return jRadioButtonMenuItem;
	}
	/**
	 * This method initializes jRadioButtonMenuItem1	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonMenuItem1() {
		if (jRadioButtonMenuItem1 == null) {
			jRadioButtonMenuItem1 = new JRadioButtonMenuItem();
			jRadioButtonMenuItem1.setText("2");
			jRadioButtonMenuItem1.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					setPaintWidth();
				}
			});
		}
		return jRadioButtonMenuItem1;
	}
	/**
	 * This method initializes jRadioButtonMenuItem2	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonMenuItem2() {
		if (jRadioButtonMenuItem2 == null) {
			jRadioButtonMenuItem2 = new JRadioButtonMenuItem();
			jRadioButtonMenuItem2.setText("4");
			jRadioButtonMenuItem2.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					setPaintWidth();
				}
			});
		}
		return jRadioButtonMenuItem2;
	}
	/**
	 * This method initializes jRadioButtonMenuItem3	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonMenuItem3() {
		if (jRadioButtonMenuItem3 == null) {
			jRadioButtonMenuItem3 = new JRadioButtonMenuItem();
			jRadioButtonMenuItem3.setText("8");
			jRadioButtonMenuItem3.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					setPaintWidth();
				}
			});
		}
		return jRadioButtonMenuItem3;
	}
	protected void setPaintWidth() {
		if (jRadioButtonMenuItem.isSelected())  paintWidth=1;
		if (jRadioButtonMenuItem1.isSelected()) paintWidth=2;
		if (jRadioButtonMenuItem2.isSelected()) paintWidth=4;
		if (jRadioButtonMenuItem3.isSelected()) paintWidth=8;
		
		
	}}  //  @jve:decl-index=0:visual-constraint="400,15"
```
Das ist mein Programm das in den Appelt laufen soll.


----------



## L-ectron-X (25. Mai 2007)

Guck mal, was ganz einfaches:

```
import java.awt.*;
import javax.swing.*;

public class EmbededApplet extends JApplet {
   private Switch s;
   
   public void init() {
      getContentPane().setBackground(Color.RED);
   }
   
   public void start() {
      if(s == null) {
         s = new Switch();
         s.start();
      }
   }
   
   public void stop() {
      s.interrupt();
      s = null;
   }
   
   class Switch extends Thread {
      public void run() {
         while(!isInterrupted()) {
            try {
               Thread.sleep(500);
            }
            catch(InterruptedException e) {
               interrupt();
            }

            if(getContentPane().getBackground() == Color.RED) {
               getContentPane().setBackground(Color.GREEN);
            }
            else {
               getContentPane().setBackground(Color.RED);
            }
         }
      }

   }
}
```


```
import java.awt.*;
import javax.swing.*;

public class AppletInAppletDemo extends JApplet {
   private EmbededApplet emAp;
   
   public void init() {
      setLayout(new GridLayout(0, 1));
      emAp = new EmbededApplet();
      emAp.init();
      emAp.start();
      getContentPane().add(emAp);
      
      JPanel p = new JPanel();
      p.setBackground(Color.YELLOW);
      getContentPane().add(p);
   }

   public void stop() {
      emAp.stop();
   }
}
```

Kompiliere das mal, lege AppletInAppletDemo in eine HTML-Datei und probiere es mal aus.


----------



## MartinDeluxe (25. Mai 2007)

Ok, danke. Jetzt hab ichs hinbekommen!


----------

