O
otto
Gast
en =)
Also ich klicke auf einen Button und dann wird das dazugehörige Bild gezeichnet =) und was vorher da war ist weg =)
Ich bekomme es leider nicht hin auch google kann nicht wirklich helfen, ich hoffe von euch hat jemand einen Plan.
Vielen Dank im voraus !
Mfg,
otto
Also ich klicke auf einen Button und dann wird das dazugehörige Bild gezeichnet =) und was vorher da war ist weg =)
Ich bekomme es leider nicht hin auch google kann nicht wirklich helfen, ich hoffe von euch hat jemand einen Plan.
Vielen Dank im voraus !
Code:
package uebung2aufgabe2;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import uebung2aufgabe1.MyJFrame;
public class MyJFrame2 extends JFrame {
JButton draw1;
JButton draw2;
JButton draw3;
JPanel unteresPanel = new JPanel();
JPanel oberesPanel = new JPanel();
BildVersuch2 bild3 = new BildVersuch2();
Schach bild1 = new Schach();
Schnecke bild2 = new Schnecke();
// Graphics graphicb1 = bild1.getGraphics();
// Graphics graphicb2 = bild2.getGraphics();
// Graphics graphicb3 = bild3.getGraphics();
public MyJFrame2(){
super.setTitle("My next GUI");
this.setSize(700,700);
this.setLayout(new BorderLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = getContentPane();
contentPane.add(this.unteresPanel,BorderLayout.SOUTH);
contentPane.add(this.oberesPanel,BorderLayout.NORTH);
this.createAndShowIt();
}
public void createAndShowIt(){
this.draw1=new JButton("draw Bild 1");
this.draw2=new JButton("draw Bild 2");
this.draw3=new JButton("draw Bild 3");
this.unteresPanel.setLayout( new GridLayout(1,2 ) );
this.unteresPanel.add(draw1);
this.unteresPanel.add(draw2);
this.unteresPanel.add(draw3);
draw1.addActionListener( new ActionListener () {
public void actionPerformed ( ActionEvent e ) {
oberesPanel.paintComponents(bild1.getGraphics());
}
} );
draw2.addActionListener( new ActionListener () {
public void actionPerformed ( ActionEvent e ) {
oberesPanel.paintComponents(bild2.getGraphics());
}
} );
draw3.addActionListener( new ActionListener () {
public void actionPerformed ( ActionEvent e ) {
oberesPanel.paintComponents(bild3.getGraphics());
}
} );
this.setVisible(true);
}
public static void main(String[] args) {
MyJFrame2 jframe = new MyJFrame2();
}
}
Mfg,
otto