Skip to main content

constant position pictures - Java SE

No replies
user2129896
Offline
Joined: 2013-04-05
Points: 0

Welcome

I wanted to be nice to ask. To set the image in one position after pressing VK_UP.
Every time when I press the button image inserted into another. One after another.

The situation is as follows:

image
image
image
...

I would want that every time when I press the button was only one image.

Code is as follows:

// imports 

public class Komponentcopy extends JPanel implements ActionListener,
KeyListener {

private BufferedImage image;
protected JButton sprzeglo;
File imageFile;
Dimension dimension;
JLabel picLabel;

public Komponentcopy() {
initialize();
setFocusable(true);

setLayout((LayoutManager) new BoxLayout(this, BoxLayout.Y_AXIS));
sprzeglo = new JButton("JButton 1 ");

imageFile = new File("pp.png");

addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_UP) {

try {

        image = ImageIO.read(imageFile);
        picLabel = new JLabel(new ImageIcon(image));
add(picLabel).setMaximumSize(new Dimension(350, 40));
} catch (IOException error) {
     System.out.print("Błąd wyświetlenia obrazka informującego, że pojazd porusza się do przodu . ");
}
}
}
});

add(sprzeglo);
}

private void initialize() {
this.add(getPnlCiz());
}

}

very nice please help...???