Results 1 to 6 of 6
  1. #1
    hadyelsahar is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Question BUG in PaintBrush application

    i 've developed a chatting , paint application using J2se
    but unfortunately i had some bugs considering the painting
    i've used a Jpanel to draw inside and graphics object to draw

    the Bug is that when i draw something like this
    NewPicture.png - Bilder und Fotos kostenlos auf ImageBanana hochladen



    then i put the window down to the taskbar and when i show it again
    it appears like that

    NewPicture1.png - Bilder und Fotos kostenlos auf ImageBanana hochladen


    the last circle only appears as if the panel is painted again , and


    the Other Bug , is that i the MouseMotionListener is too slow to response the mouse drag event so the lines appears to be separated circles -watch screen shot 1 -
    anyone have a recommendation todo inorder to make the response to MouseDrag event faster ?



    thanks alot

    THIS IS A PART OF THE CODE :
    Java Code:
    public class paintArea extends JPanel implements MouseMotionListener  {
      
        private int x ; 
        private int y ;
        private int width ;
        private int height ;
        private Color color ; 
        boolean taskflag = true  ;  // if true then draw , if flase then upddate image
        private editor editor ;
    
        // constructor
          public paintArea(editor editor ) {
    
            this.editor = editor ; 
            width = getWidth() ;
            height = getHeight();
    
            this.setSize(800, 500);
            addMouseMotionListener(this);
    
        }
    
    
    
    
    
    
        @Override
        public void paint (Graphics g){
            update (g);
        }
    
        @Override
        public void update (Graphics graphics) {
    
            if (taskflag)
            {
                int size = editor.getsize();
                color = editor.getcolor() ;
                graphics.setColor(color); 
                graphics.fillOval(x-5, y-5, size, size);
            }
    
             else {
                try {
                  Image img = ImageIO.read(new File("img.jpeg"));
                } catch (IOException ex) {
                  Logger.getLogger(paintArea.class.getName()).log(Level.SEVERE, null, ex);
                }
    
             taskflag = true ;
             System.out.println("image reloaded");
         }
    
        }
    
    
      
    
    
        public void mouseDragged(MouseEvent e) {
           // throw new UnsupportedOperationException("Not supported yet.");
    
            this.x = e.getX();
            this.y = e.getY();
            repaint () ; 
            e.consume();
    
    
        }

  2. #2
    Ruuhkis is offline Member
    Join Date
    Feb 2011
    Posts
    19
    Rep Power
    0

    Default

    You must store every coordinate somewhere, like in list or so :)

  3. #3
    hadyelsahar is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    i think i don't have to do so
    that's because Java an Update () ; method that updates the Panel
    not clearing it

  4. #4
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default

    Use a offscreen image. Paint to a BufferedImage, and the update will paint this image.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default

    Zombie alert. Spammer reported.

    db

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default

    For any future readers of this thread, the whole approach to custom painting discussed above is wrong. The correct approach can be found in Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db

Similar Threads

  1. need help for rmi application
    By princessayu in forum Java Applets
    Replies: 1
    Last Post: 01-29-2010, 03:19 AM
  2. Replies: 3
    Last Post: 12-04-2009, 01:10 PM
  3. Replies: 0
    Last Post: 04-22-2009, 02:30 PM
  4. Replies: 0
    Last Post: 02-16-2008, 10:31 PM
  5. Replies: 0
    Last Post: 02-16-2008, 10:29 PM

Posting Permissions

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