mouseClicked ImageIcon

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 459 Views - Last Post: 21 June 2020 - 11:41 AM Rate Topic: -----

#16 ronald1127   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 22-September 19

Re: mouseClicked ImageIcon

Posted 21 June 2020 - 08:41 AM

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Image extends JFrame implements MouseListener
{
	public Image()
	{
		addMouseListener(this);
	}
	
	@Override
	public void mouseClicked(MouseEvent me) {
		// TODO Auto-generated method stub
		ImageIcon icon1 = new ImageIcon("icons/Femme-Femme.png");
		JLabel label1 = new JLabel();
		label1.setIcon(icon1);
		
	}
	@Override
	public void mousePressed(MouseEvent me) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseReleased(MouseEvent me) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseEntered(MouseEvent me) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseExited(MouseEvent me) {
		// TODO Auto-generated method stub
		
	}
	
	public static void main(String[] args) 
	{
		
		ImageIcon icon = new ImageIcon("icons/Button.png");
	    JLabel label = new JLabel();
	    label.setIcon(icon);
	    
	    JFrame frame = new JFrame();
	    frame.add(label);
	    
	    frame.setTitle(""); 
	    frame.setSize(900, 600);
	    frame.setLocationRelativeTo(null);
	    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    frame.setVisible(true);
	    
	}
}
	

I redid this code according to someone else's code from coderanch
Was This Post Helpful? 0
  • +
  • -

#17 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: mouseClicked ImageIcon

Posted 21 June 2020 - 08:55 AM

Quote

according to someone else's code from coderanch

Ok, I see it is being explained at https://coderanch.co...icked-ImageIcon
Was This Post Helpful? 0
  • +
  • -

#18 ronald1127   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 22-September 19

Re: mouseClicked ImageIcon

Posted 21 June 2020 - 09:19 AM

I now understand that the computer does not do everything I think to do following the explanation of coderanch, I say that the computer has limits,
Was This Post Helpful? 0
  • +
  • -

#19 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: mouseClicked ImageIcon

Posted 21 June 2020 - 09:37 AM

Yes, of course. It will only do what you tell it to do, not what you think you want it to do.
Was This Post Helpful? 0
  • +
  • -

#20 ronald1127   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 22-September 19

Re: mouseClicked ImageIcon

Posted 21 June 2020 - 11:41 AM

thank you, i changed the code a bit and it works well
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2