Results 1 to 2 of 2
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Rep Power

    Talking Why doesn't the panel update unless I drag the edges?

    Im like total newbie and I'v finaly got a feeling on how to import images =)
    Weee, took me days to find a good example that didnt use 1 quadrilion lines to explain.
    But anyways, I'v made this gui thing. Just a window and a picture.
    Then I got a loop running.
    This loop will change the X and Y values and repaint the picture.
    But the problem is, you can see that the image is moving unless you resize the window, but the x andy is changing so if u wait a long time, then the picture (when drag the edges) will have moves far down.

    So heres my code:
    PHP Code:
     * @(#)
     * TestingArea application
     * @author 
     * @version 1.00 2009/11/2
    import javax.swing.*;
    import javax.imageio.*;
    import java.awt.*; 
    import java.awt.image.*;
    import java.awt.image.BufferedImage;
    import java.util.*;
    public class TestingArea {
        static Vector <Image> list = new Vector<Image>();
        static int X = 0;
        static int Y = 0;
        public static void main(String[] args) {
        	// TODO, add your application code
        	gameFrame gf = new gameFrame();
        	while (true){
        		X += 10;
        		Y += 10;
        		gf.add(new paintIt());
     				 //do what you want to do before sleeping
      				Thread.currentThread().sleep(1000);//sleep for 1000 ms
      				//do what you want to do after sleeptig
    			} catch(Exception ie){
    				//If this thread was intrrupted by nother thread 
    class gameFrame extends JFrame{
    	public gameFrame(){
    		paintIt p = new paintIt();
    		setTitle("Image test");
    class paintIt extends JPanel{
    	public void paintComponent(Graphics g){
    		BufferedImage pic = File("C:\\Users\\Andreas\\Bilder\\CNDF.png"));
    		}catch (Exception e){
    Suggestion on ways/patterns to use for making a 2d game is also appriciated =)

  2. #2
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Rep Power

Similar Threads

  1. Drag polygon
    By cassysumandak in forum New To Java
    Replies: 5
    Last Post: 03-10-2011, 06:30 PM
  2. Drag and Drop
    By carderne in forum New To Java
    Replies: 0
    Last Post: 08-31-2009, 09:18 AM
  3. Replies: 2
    Last Post: 04-14-2009, 10:01 PM
  4. Help with drag from panel
    By fernando in forum AWT / Swing
    Replies: 2
    Last Post: 08-07-2007, 10:19 PM
  5. Rectangle with rounded edges??
    By orchid in forum Java 2D
    Replies: 1
    Last Post: 05-10-2007, 02:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts