NEED HELP FAST please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #16
    Originally posted by SpecialKay
    No No i believe you.
    I have no idea what is wrong with mine.
    Ok, try to change mouseClicked to mousePressed... ..

    Sometimes, that device( the mouse ) did three data sent.... when it just pressed, holds( another data), and released(anothe r data again)....

    Clicked is different in that scenario... maybe your mouselisteners won't listen because they encountered strange data sometimes....

    But at my machine, nothing's wrong with you code.....

    Update us,
    sukatoa

    Comment

    • SpecialKay
      New Member
      • Mar 2008
      • 109

      #17
      Update:
      Found the problem.

      [code=java]
      public void paintComponent ( Graphics g) {
      if(shapeList.si ze() > 0)
      {
      for ( int i = 0; i < shapeList.size( ); i++)
      {
      Graphics2D g2 = (Graphics2D)g;
      Shape shape = (Shape)shapeLis t.get(i);
      shape.draw(g2);
      }
      }
      }
      [/code]


      [code=java]
      public void paintComponent ( Graphics g) {
      <b>super.paintC omponent(g);</b>
      if(shapeList.si ze() > 0)
      {
      for ( int i = 0; i < shapeList.size( ); i++)
      {
      Graphics2D g2 = (Graphics2D)g;
      Shape shape = (Shape)shapeLis t.get(i);
      shape.draw(g2);
      }
      }
      }
      [/code]

      Comment

      • sukatoa
        Contributor
        • Nov 2007
        • 539

        #18
        Originally posted by SpecialKay
        Update:
        Found the problem.

        [code=java]
        public void paintComponent ( Graphics g) {
        if(shapeList.si ze() > 0)
        {
        for ( int i = 0; i < shapeList.size( ); i++)
        {
        Graphics2D g2 = (Graphics2D)g;
        Shape shape = (Shape)shapeLis t.get(i);
        shape.draw(g2);
        }
        }
        }
        [/code]


        [code=java]
        public void paintComponent ( Graphics g) {
        <b>super.paintC omponent(g);</b>
        if(shapeList.si ze() > 0)
        {
        for ( int i = 0; i < shapeList.size( ); i++)
        {
        Graphics2D g2 = (Graphics2D)g;
        Shape shape = (Shape)shapeLis t.get(i);
        shape.draw(g2);
        }
        }
        }
        [/code]
        What happen? after removing it?

        Update us,
        sukatoa

        Comment

        • SpecialKay
          New Member
          • Mar 2008
          • 109

          #19
          not removing it, adding it
          super.paintcomp onent(g);
          Not exactly sure why i needed it. But i did!

          Comment

          • BigDaddyLH
            Recognized Expert Top Contributor
            • Dec 2007
            • 1216

            #20
            Originally posted by SpecialKay
            not removing it, adding it
            super.paintcomp onent(g);
            Not exactly sure why i needed it. But i did!
            Sorry I got to the party late. You should always start paintComponent with a call to super:

            [CODE=Java]@Override()
            protected void paintComponent( Graphics g) {
            super.paintComp onent(g);
            ...
            }[/CODE]

            Why? The base version erases the background (by covering it with the background color). If you don't do this you end up seeing random stuff.

            Comment

            • SpecialKay
              New Member
              • Mar 2008
              • 109

              #21
              Accually what is happening,
              is paintcomponent repaints the entire window, that is why i was seeing my menubar doubled.
              super.paintcomp onent repaints only the frame. super is a call to the parent. and since my canvas extends a Jpanel... the panel is repained other then the entire window.

              an equivalent command to super.paintcomp onent would be frame.paintcomp nent. they both do the same thing.

              Comment

              • sukatoa
                Contributor
                • Nov 2007
                • 539

                #22
                Originally posted by SpecialKay
                Accually what is happening,
                is paintcomponent repaints the entire window, that is why i was seeing my menubar doubled.
                super.paintcomp onent repaints only the frame. super is a call to the parent. and since my canvas extends a Jpanel... the panel is repained other then the entire window.

                an equivalent command to super.paintcomp onent would be frame.paintcomp nent. they both do the same thing.
                Have you solved your problem now?

                Update us,
                sukatoa

                Comment

                Working...