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:
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
Code:
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