2 Replies - 1159 Views - Last Post: 25 November 2010 - 03:06 AM Rate Topic: -----

#1 Zylox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 24-November 10

XY Coordinates in label showing Null Null

Posted 24 November 2010 - 01:06 PM

Hey all. First of all im new here so i don't know if this question got answered before, but i couldn't find anything simular to it.

What i have made so far is a frame that has multiple screens connected to it with a LinkedList

However, my question is about one of the screens that has a few pictures on it.
I know i can't put a eventhandler in a picture, so i wanted to use X and Y coordinates to make the event happens.

So like this:
Posted Image
As you can see for now im using a button to go to the "Assortiment" page, but i want to remove the button and make the picture "clickable" by looking at the x and y coordinates of the mouse.

So far i tried:

public class Hoofdscherm extends JPanel {

    private JLabel testlabel;

    static JLabel lblx;
    static JLabel lbly;

Frame frame;

    Hoofdscherm(Frame f) {
        frame = f;
        f.setTitle("IIP Bouwmarkt - Hoofdscherm");
        this.setLayout(null);
        this.setBackground(new Color(13,62,138));
        f.setSize(1280, 1024);

        this.addMouseListener(new FindLocation(lblx,lbly));

        JLabel testlabel = new JLabel("test" + lblx + lbly);

        add(testlabel);

<Skipped some code>

class FindLocation extends MouseAdapter {

			public FindLocation(JLabel lbx,JLabel lby){
				lblx = lbx;
				lbly = lby;
			}

			@Override
			public void mouseClicked(MouseEvent e) {
				String textx = lblx.getText();
				lblx.setText("X=" + e.getX());
				lbly.setText("Y=" + e.getY());
			}
		}



However, when i run the page it says "Test Null Null" in the label

Can anyone tell me what i am doing wrong?

This post has been edited by Zylox: 24 November 2010 - 01:09 PM


Is This A Good Question/Topic? 0
  • +

Replies To: XY Coordinates in label showing Null Null

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,262
  • Joined: 27-December 08

Re: XY Coordinates in label showing Null Null

Posted 24 November 2010 - 02:37 PM

Why don't you make a JButton and use the setIcon() method so it will display the picture and be clickable? Much easier than reinventing the wheel. :)
Was This Post Helpful? 1
  • +
  • -

#3 Zylox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 24-November 10

Re: XY Coordinates in label showing Null Null

Posted 25 November 2010 - 03:06 AM

Thank you for your response.

I've tried using the button.setIcon(image);

but now im getting this:
The buttons are bigger then the picture and the picture is too much to the left
Even tho they have the same size

Posted Image

The only strange thing is that i've made the buttons as big as the pictures but still its showing up like that.

asoknop.addActionListener(new AssortimentHandler());
        asoknop.setBounds(80,480,240,40);
        asoknop.setIcon(headerAssortiment);
        
        proknop.addActionListener(new ProjectHandler());
        proknop.setBounds(380,480,240,40);
        proknop.setIcon(headerKlusadvies);

        folknop.addActionListener(new FolderHandler());
        folknop.setBounds(660,480,260,40);
        folknop.setIcon(headerFolder);
        
        
        eveknop.addActionListener(new EvenementenHandler());
        eveknop.setBounds(1010,480,160,40);
        eveknop.setIcon(headerActie);

        serknop.addActionListener(new ServicesHandler());
        serknop.setBounds(980,780,230,40);
        serknop.setIcon(headerService);


Picture sizes:
assortiment: 240 X 40
Klusadvies: 240 X 40
Folder: 260 X 40
Actie: 160 X 40
Service: 240 X 40

Got any more hints?

This post has been edited by Zylox: 25 November 2010 - 03:07 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1