Results 1 to 3 of 3
Thread: Why the picture is not moving?
- 09-15-2015, 04:26 PM #1
Member
- Join Date
- Jun 2015
- Posts
- 14
- Rep Power
- 0
Why the picture is not moving?
Hi everyone.
My require of the program is : when I click on the image , image should go down slowly.
The problem is that when I'm clicking nothing happens.
Maybe the problem is at MouseClickedEvent.
I would be thankful if any of you guys help me with this.
Thanks in advance.
Here's my code.
Java Code:public class PlayNow extends JFrame { public static Image image; int x; int y; int dy; Timer t; public PlayNow() throws IOException{ initComponents(); //setLayout(null); x = 100; y = 50; dy = 1; setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(800,600); image = ImageIO.read(new File("D:\\Ertani\\JAVA Program by me\\Birra\\src\\birra\\bottle2.png")); JLabel picLabel = new JLabel(new ImageIcon(image)); picLabel.setLocation(x, y); picLabel.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jLabel1MouseClicked(evt); } }); } public void paint(Graphics g) { g.drawImage(image, x, y, this); } private void jLabel1MouseClicked(MouseEvent evt) { // TODO add your handling code here: t = new Timer(15,new ActionListener(){ public void actionPerformed(ActionEvent e){ while(y <= 200) { y += dy; repaint(); } } }); t.start(); } private void initComponents() { setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 457, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 1503, Short.MAX_VALUE) ); pack(); } }
- 09-15-2015, 05:01 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Why the picture is not moving?
You need to add it to the Frame
Java Code:add(picLabel);
There are a bunch of things you are doing that you should not do. So check out the tutorials in my signature. They cover painting.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 09-15-2015, 05:26 PM #3
Re: Why the picture is not moving?
Also posted at: Problem with MouseClickEvent , the picture is not moving
If you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
One picture for each texture, or all in one picture
By JG4m3r in forum AndroidReplies: 1Last Post: 05-24-2012, 05:44 PM -
Picture zoom
By hades7 in forum New To JavaReplies: 1Last Post: 02-02-2012, 07:10 PM -
Picture manipulating help
By evolutiongsr8 in forum New To JavaReplies: 0Last Post: 03-26-2011, 07:47 AM -
Getting a picture out of a jar?
By Zman3359 in forum New To JavaReplies: 4Last Post: 02-03-2011, 12:55 AM -
Picture help
By deathnote11 in forum AWT / SwingReplies: 13Last Post: 06-03-2008, 06:46 PM
Bookmarks