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:
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