Hallo, leider habe ich noch eine Frage.
Drücke ich den Button *random* so wird ein Bild in meinen JFrame mit Container geladen. Das Funktioniert einwandfrei. Nun möchte ich aber beim 2ten Button-Klick, dass das vorhandene Bild durch das neue ersetzt, oder wenigstens *überblendet*, wird. Bei mir ist es so, dass das erste Bild immer im Vordergrund ist. Gibt es da eine möglichkeit ?
Hier mein kurzgefasster Code
Vielen dank schonmal für die Mühe.
Mfg Velow
Drücke ich den Button *random* so wird ein Bild in meinen JFrame mit Container geladen. Das Funktioniert einwandfrei. Nun möchte ich aber beim 2ten Button-Klick, dass das vorhandene Bild durch das neue ersetzt, oder wenigstens *überblendet*, wird. Bei mir ist es so, dass das erste Bild immer im Vordergrund ist. Gibt es da eine möglichkeit ?
Hier mein kurzgefasster Code
Code:
package GUI;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.awt.Toolkit;
import javax.swing.JFrame;
import org.apache.commons.httpclient.HttpException;
public class GUI {
public GUI() {
JFrame f = new JFrame("XX");
Container c = f.getContentPane();
c.setLayout(null);
JButton random = new JButton();
random.setText("Random Funktion");
random.setBounds(250, 180, 140, 25);
c.add(random);
JButton eingabe = new JButton();
eingabe.setText("Eingabe ausführen");
eingabe.setBounds(250, 120, 140, 25);
c.add(eingabe);
JTextField a = new JTextField("xxxxxx");
a.setBounds(60, 80, 240, 20);
c.add(a);
JTextField b = new JTextField("Madonna");
b.setBounds(400, 80, 170, 20);
c.add(b);
JTextField d = new JTextField("Informations-Zeile");
d.setHorizontalAlignment(JLabel.CENTER);
d.setBounds(130, 220, 370, 20);
d.setEditable(false);
c.add(d);
action action = new action(random, eingabe, a, b, d, c);
random.addActionListener(action);
eingabe.addActionListener(action);
f.setSize(660, 530);
f.setResizable(false);
f.setVisible(true);
}
class action implements ActionListener {
JButton random, eingabe;
JTextField a, b, d;
Container c;
action(JButton random, JButton eingabe,
JTextField a, JTextField b, JTextField d
,Container c) {
this.random = random; this.eingabe = eingabe;
this.a = a; this.b = b; this.d = d;
this.c = c;
}
public void actionPerformed(ActionEvent e) {
Object button = e.getSource();
if (button == this.random) {
Icon _icon = new ImageIcon("xx.jpg");
JLabel _label = new JLabel(_icon);
_label.setBounds(20, 330, 130, 130);
this.c.add(_label);
this.c.validate();
this.c.repaint();
} else if (button == this.eingabe) {
} else {
}
}
}
}
Vielen dank schonmal für die Mühe.
Mfg Velow