2 개의 간단한 구성 요소를 JFrame에 추가하는 데 문제가 있습니다. 문제는 두 번째 구성 요소가 JFrame에 다르게 위치한 작은 모양 만 포함하더라도 첫 번째 구성 요소를 완전히 포함한다는 것입니다. 잠시 동안 탐색했지만 내 문제에 대한 해결책을 찾을 수 없습니다.간단한 JComponent를 사용하지 않는 부분을 투명하게 만들어서 JFrame에 추가 할 때 다른 구성 요소를 포함하지 않도록하려면 어떻게해야합니까?
public class Main
{
public static void main(String[]args)
{
JFrame frame = new JFrame();
CircleComponent comp = new CircleComponent(400,400);
CircleComponent comp2 = new CircleComponent(200,200);
frame.add(comp);
frame.add(comp2);
frame.setSize(800,800);
frame.setVisible(true);
}
}
//////////////////////////////////////////////////////////////////////////
public class CircleComponent extends JComponent
{
Ellipse2D.Double ellipse;
double x;
double y;
public CircleComponent(int xx, int yy)
{
x = xx;
y = yy;
ellipse = new Ellipse2D.Double(x,y,25,25);
setOpaque(false);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.fill(ellipse);
}
}
야생의 추측이지만 단순히 가짜 작업에 대한 가시성을 두지는 않습니까? comp.setVisible (false); – DerpyNerd
내 마음이 바보 같았습니다.) – DerpyNerd