Auf Thema antworten

Ich hab mit Absicht überall addGap() eingestellt und man sieht dass in den ganz obere Ecke und ganz untere Ecke dass es tatsächlich gezeichnet wird aber überdeckt wird.. (sind verschiedene Rechtecken)


[code=Java]public class EditPanel extends JPanel

{

   

    Image img;

    private int xPos, yPos;

    boolean pressOut = false;

 

    Color grayRect = new Color(230,227,224);

    Color orangeRect = new Color(211,111,53);

   

    Rectangle bausteinRect = new Rectangle(0, 0, 70, 70);


    public  EditPanel()

    {

        /* ********************* Mouse Listener ***************************  */

        addMouseListener(new MouseAdapter()

        {

          

            public void mousePressed(MouseEvent e)

            { 

                xPos = bausteinRect.x - e.getX();

                yPos = bausteinRect.y - e.getY();

               

                if (bausteinRect.contains(e.getX(), e.getY()))

                {

                    updateLocation(e);

                    System.out.println("im Baustein");

                }

                else

                {

                    pressOut = true;

                    System.out.println("auserhalb");

                } 

            }

           

            public void mouseReleased(MouseEvent e)

            {

                  if (bausteinRect.contains(e.getX(), e.getY()))

                  {

                       updateLocation(e);

                       System.out.println("mouseReleased");

                  }

                  else

                  {

                      pressOut = false;

                  }

            }

           

        });


    

        /* ****************** Mouse Motion Listener ***********************  */

        addMouseMotionListener(new MouseMotionAdapter()

        {

      

            public void mouseDragged(MouseEvent e)

            {

              if (!pressOut)

              {

                updateLocation(e);

             

              }

              else

              {

                 

              }

           }

        });

       

  

    }


    public void updateLocation(MouseEvent e)

    {

        bausteinRect.setLocation(xPos + e.getX(), yPos + e.getY());

        System.out.println("update");

        repaint();

  }


    protected void paintComponent(Graphics g)

    {

        super.paintComponent(g);

  

            int centerX = getWidth()/2;    

            int beginPosition = (getHeight()-(CreateFile.cf.headerH + CreateFile.cf.contentH+ CreateFile.cf.footerH+CreateFile.cf.tile1H+CreateFile.cf.tile3H))/2;


           

            //header

            Rectangle headerRect = new Rectangle(centerX-CreateFile.cf.headerW/2,beginPosition,CreateFile.cf.headerW,CreateFile.cf.headerH);     

            g.setColor(grayRect);

            headerRect.translate(-CreateFile.cf.tile2W/2,CreateFile.cf.tile1H);

            g.fill3DRect(headerRect.x, headerRect.y, headerRect.width, headerRect.height,true);

           

//            MediaTracker mt = new MediaTracker(this);

//            img = Toolkit.getDefaultToolkit().getImage("C:\\Images\\szlogo.jpg");

//            mt.addImage(img,0);

//

//            g.drawImage(img,centerX-CreateFile.cf.headerW/2,beginPosition,this);

  

            //content

            Rectangle contentRect = new Rectangle(centerX-CreateFile.cf.contentW/2,beginPosition + CreateFile.cf.headerH,CreateFile.cf.contentW,CreateFile.cf.contentH);

            g.setColor(grayRect);

            contentRect.translate(-CreateFile.cf.tile2W/2,CreateFile.cf.tile1H);  

            g.fill3DRect(contentRect.x, contentRect.y, contentRect.width, contentRect.height,true);



            //footer

            Rectangle footerRect = new Rectangle(centerX-CreateFile.cf.footerW/2,beginPosition+CreateFile.cf.headerH+CreateFile.cf.contentH,CreateFile.cf.footerW,CreateFile.cf.footerH);

            g.setColor(grayRect);

            footerRect.translate(-CreateFile.cf.tile2W/2,CreateFile.cf.tile1H+CreateFile.cf.tile3H);  

            g.fill3DRect(footerRect.x, footerRect.y, footerRect.width, footerRect.height,true);



            //tile 1

            Rectangle tile1Rect = new Rectangle(centerX-CreateFile.cf.headerW/2-CreateFile.cf.tile2W/2,beginPosition,CreateFile.cf.tile1W,CreateFile.cf.tile1H);

            g.setColor(orangeRect); 

            g.fill3DRect(tile1Rect.x, tile1Rect.y, tile1Rect.width, tile1Rect.height,true);



            //tile 2   

            Rectangle tile2Rect = new Rectangle(centerX+CreateFile.cf.headerW/2-CreateFile.cf.tile2W/2,beginPosition+CreateFile.cf.tile1H,CreateFile.cf.tile2W,CreateFile.cf.tile2H);

            g.setColor(orangeRect); 

            g.fill3DRect(tile2Rect.x, tile2Rect.y, tile2Rect.width, tile2Rect.height,true);



            //tile3     

            contentRect.translate(0,CreateFile.cf.tile3H);

            Rectangle tile3Rect = new Rectangle(centerX-CreateFile.cf.headerW/2-CreateFile.cf.tile2W/2,beginPosition+CreateFile.cf.tile1H+CreateFile.cf.headerH+CreateFile.cf.contentH,CreateFile.cf.tile3W,CreateFile.cf.tile3H);

            g.setColor(orangeRect); 

            g.fill3DRect(tile3Rect.x, tile3Rect.y, tile3Rect.width, tile3Rect.height,true);



            //baustein

    

            bausteinRect = new Rectangle(getX(), getY(),CreateFile.cf.bausteinW,CreateFile.cf.bausteinH);

            g.setColor(orangeRect); 

            g.fill3DRect(bausteinRect.x, bausteinRect.y, bausteinRect.width, bausteinRect.height,true);       

      

           

    }


   

}[/code]



Oben