1

So I have a mini program that is going to show 2 JFrames, one with a face drawn of shapes, and another with some editing options. Whenever I run the program, it shows both of the frames, but for some reason it is showing the buttons from the tool bar frame on the face frame. They are not active buttons, its just an image of them basically. Here is a Screenshot: enter image description here http://i1318.photobucket.com/albums/t659/brianbolnick1/scrnshot_zps524c99ee.png)

I have tried to keep my main as simple as possible:

    //draw face panel
    Face face = new Face();
    JFrame frame = new JFrame();
    frame.add(face);
    frame.setSize(600,400);
    frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true); 

    //draw toolbar panel
    JFrame frame1 = new FaceClass ();
    frame1.setTitle("Toolbar");
    frame1.setSize(200,150);
    frame1.setLocation(200,100);
    frame1.setDefaultCloseOperation(frame1.EXIT_ON_CLOSE);
    frame1.setVisible(true);  

and from what I can see I don't think there are any issues. Can anyone see anything that might be wrong with that? Or is it possible that the issue is elsewhere (constructor or paintComponent of the "Face" class)? Please help! I have been working on this forever and can't seem to figure it out... If you need to see more of the code just ask, I don't want to wall post with code.

Here's the bulk of the face class:

public Face () {
    //register mouse click activity
    addMouseMotionListener(new MouseMotionAdapter() {
        @Override public void mouseDragged (MouseEvent event) {
            selectShapeUnder(event.getX(), event.getY());
            repaint();
        }
    });
    addMouseListener(new MouseAdapter() {
        @Override public void mousePressed (MouseEvent event) {
            selectShapeUnder(event.getX(), event.getY());
            repaint();
        }
    });

}

 protected void paintComponent (Graphics g) {
        Graphics2D graphics = (Graphics2D)g;

        graphics.setColor((selected == face) ? Color.CYAN : Color.GREEN);
        graphics.fill(face);

        graphics.setColor((selected == mouth) ? Color.YELLOW : Color.RED);
        graphics.fill(mouth);

        graphics.setColor((selected == eyeLeft || selected == eyeRight) ? Color.RED     
: Color.WHITE);
        graphics.fill(eyeLeft);
        graphics.fill(eyeRight);

        graphics.setColor(Color.BLACK);
        graphics.fill(pupilLeft);
        graphics.fill(pupilRight);
        g.drawLine(220, 185, 270, 185);
        g.drawLine(220, 185, 260, 130);

        repaint();

    }//end pC


public void selectShapeUnder (int x, int y) {
        Shape oldSelected = selected;

        if (eyeLeft.contains(x, y)){
            selected = eyeLeft; 
        }//end if 
        else if (eyeRight.contains(x, y)){
            selected = eyeRight;    
        }//end else if
        else if (mouth.contains(x, y)){
            selected = mouth; 
        }//end else if
        else if (face.contains(x, y)) {
            selected = face;
        }//end else if
        else
            selected = null;
        if (selected != oldSelected)
            repaint();
    }//end selectShapeUnder
Luminusss
  • 571
  • 1
  • 6
  • 27
  • `"If you need to see more of the code just ask..."` -- yep, we'll need to see more code. Probably most important the code you use to draw on your face. – Hovercraft Full Of Eels Nov 15 '13 at 05:14
  • show us paint or paintComponent method – iShaalan Nov 15 '13 at 05:15
  • 1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) 3) For better help sooner, post an [SSCCE](http://sscce.org/). 4) One way to get image(s) for an example is to hot-link to the images seen in [this answer](http://stackoverflow.com/a/19209651/418556). – Andrew Thompson Nov 15 '13 at 05:18
  • 1
    1) Never call `repaint();` from within `paintComponent(Graphics g)`. 2) Always call the `super.paintComponent(Graphics g)` from within your override. – Hovercraft Full Of Eels Nov 15 '13 at 05:20
  • that did it! Thank you! Why was that happening by the way? I'm very new to all this still..just trying to understand it all – Luminusss Nov 15 '13 at 05:24
  • 1
    By not calling the super method, you don't let the GUI clean up "dirty" regions on the GUI. – Hovercraft Full Of Eels Nov 15 '13 at 05:29

0 Answers0