Šta je novo?

Java pomoc

Blue Master

Poštovan
Učlanjen(a)
01.06.2014
Poruke
9
Poena
51
Treba mi pomoc, kako da mi se na pritisak jednog dugmeta prikazi prikazu ove slike sto mi izbacuje na keyeventove


public class KeyEventDemo extends JFrame {
private final KeyboardPanel keyboardPanel = new KeyboardPanel();

public static ImageIcon image1= new ImageIcon("images/1.jpg");

public static ImageIcon image3=new ImageIcon("images/4.jpg");
public static ImageIcon image2 =new ImageIcon("images/9.jpg");
public static ImageIcon image4=new ImageIcon("images/7.jpg");


public KeyEventDemo() {
JButton prikazi=new JButton("Prikazi");






keyboardPanel.add(prikazi);
add(keyboardPanel);

keyboardPanel.setFocusable(true);
}

public static void main(String[] args) {
KeyEventDemo frame = new KeyEventDemo();
frame.setTitle("Domaci");
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

static class KeyboardPanel extends JPanel {
private final int x = 100;
private final int y = 100;
private final char keyChar = 'A';

public KeyboardPanel() {
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()== KeyEvent.VK_1){
super.keyPressed(e);
add(new JLabel(image1, JLabel.CENTER));
validate();
}

if(e.getKeyCode()==KeyEvent.VK_9){
super.keyPressed(e);
add(new JLabel(image2,JLabel.CENTER));
validate();
}

if(e.getKeyCode()==KeyEvent.VK_4){
super.keyPressed(e);
add(new JLabel(image3,JLabel.CENTER));
validate();
}

if(e.getKeyCode()==KeyEvent.VK_7){
super.keyPressed(e);
add(new JLabel(image4,JLabel.CENTER));
validate();
}
}
}
 
Nazad
Vrh Dno