2
두 개의 다른 이미지가 두 개의 다른 프레임에 나타나길 원합니다. 문제는이 코드가이 두 이미지 (원)를 표시하지 않지만 마지막 이미지 만 표시한다는 것입니다. 어떤 도움을 주셔서 감사합니다! 고맙습니다.이 표시됩니다.
public class MyCanvas extends JPanel {
private static final long serialVersionUID = 1L;
static int paint=0;
public MyCanvas(){
}
public void paintComponent(Graphics graphics){
System.out.println("mpika!!!");
// super.paintComponent(graphics);
if(paint==0){
graphics.setColor(Color.blue);
graphics.drawOval(250,250,250,250);
}
else{
graphics.setColor(Color.red);
graphics.drawOval(150,150,150,150);
}
}
public static void other(){
JFrame frame2 = new JFrame();
MyCanvas canvas2 = new MyCanvas();
frame2.setSize(700, 700);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.add(canvas2);
frame2.setVisible(true);
Graphics graph2 = canvas2.getGraphics();
canvas2.paintComponent(graph2);
}
public static void main(String[] args){
double t;
JFrame frame = new JFrame();
MyCanvas canvas = new MyCanvas();
frame.setSize(700, 700);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(canvas);
frame.setVisible(true);
Scanner input = new Scanner(System.in);
Graphics graph = canvas.getGraphics();
canvas.paintComponent(graph);
// t = input.nextInt();
paint=1;
other();
}
}
귀하의 답변은 매우 도움이되었습니다. 고마워요! –