Click here to Skip to main content
15,914,221 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class GUI extends JFrame{

	private JLabel pic;
	private JButton up,down,right,left;
	private int a = 10;
	private int b = 10;

	
	public GUI(){
		super("AWESOME");
		setLayout(null);
		
		Icon xbox = new ImageIcon(getClass().getResource("xbox.png"));
		pic = new JLabel(xbox);
		pic.setBounds(a, b,50,50);
		pic.setVisible(true);
		
		up = new JButton("");
		up.setBounds(40, 200, 20, 20);
		up.setVisible(true);
		up.addActionListener(
			new ActionListener(){
				public void actionPerformed(ActionEvent event){
					b+=5;
				}
			}
		);
                add(up);
                add(pic);




public class bro {
    public static void main(String args[]) {


        GUI fr = new GUI();
        fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fr.setSize(300, 300);
        fr.setVisible(true);




    }
}
Posted
Updated 27-Jul-13 20:33pm
v2

1 solution

Replace b+=5 with
Java
pic.setBounds(a, b,50,50);

The values of a and b are copied by the setBounds call so changing them afterwards have no impact unless you call setBounds again.

Hope this helps,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900