JPanel에 R-G-B 값을 반환하는 JSlider가 있습니다. JPanel의 Costructor에서 생성합니다. 동일한 Panel (paintComponent 사용)에 작은 원을 그려서 슬라이더를 사용하여 색상을 변경합니다. 나는 슬라이더 이동과 동시에 색이 변하기를 바래. 그럼 다시 그리는 방법을 사용합니다. 두 개의 버튼이있는 패널 옆에 다른 패널이 있습니다 .. 첫 번째 패널에서 메소드 repaint를 사용하는 경우 두 번째 패널의 버튼이 첫 번째 패널의 topLeft에 복제됩니다. 왜? 감사합니다.repaint()를 사용하는 이상한 위치 재 지정;
첫 번째 패널 :
public class OptionsPanel extends JPanel {
static JSlider RBG = new JSlider(0,255);
OptionsPanel(){
this.setVisible(false);
this.setSize(350,1000);
this.setLayout(null);
this.setBackground(new Color(200,200,0));
Main.f1.add(this);
RBG.setVisible(true);
RBG.setSize(255,50);
RBG.setLocation(30,240);
this.add(RBG);
LotL lotl = new LotL();
Button save = new Button("Save");
save.setVisible(true);
save.setSize(100,40);
save.setLayout(null);
save.setLocation(60,300);
save.addActionListener(lotl);
save.setBackground(Color.yellow);
save.identificatore=3;
this.add(save);
}
boolean draw=false;
@Override
public void paintComponent(Graphics g){
g.drawOval(50,100,70,70);
g.setColor(new Color(RBG.getValue(),180,200));
g.fillOval(50,100,70,70);
repaint();
}
}
, 제 2 패널 : 당신은 페인트 사슬을 끊었다
public class FirstPanel extends JPanel{
FirstPanel(){
this.setVisible(true);
this.setSize(1000,1000);
this.setLayout(null);
this.setBackground(new Color(255,200,180));
Main.f1.add(this);
Button start = new Button("Start Game!");
Button options = new Button("Options");
LotL LotL = new LotL();
start.setVisible(true);
start.setSize(200,80);
start.setLayout(null);
start.setLocation(400,450);
start.addActionListener(LotL);
start.setBackground(Color.green);
start.identificatore=1;
this.add(start);
options.setVisible(true);
options.setSize(200,70);
options.setLayout(null);
options.setLocation(400,550);
options.addActionListener(LotL);
options.setBackground(Color.green);
options.identificatore=2;
this.add(options);
}
}
JButton 대신 Button을 사용하고 있습니다. 문제에 대한 최소한의 완전하고 실행 가능한 ** 예를 제공하면 더 많은 도움을받을 수 있습니다. –
'save.identificatore = 3;'그'Button'은 무엇입니까? 이것은 당신의 커스텀 클래스입니까? 그것은 무엇을 연장합니까? –
죄송합니다 이유가 있습니다. Button은 JButton의 확장 클래스입니다. 광고 속성 'id'를 추가하십시오. identificatore .. 감사합니다 MadProgrammer! 이제 모든 작품! – alessandroAmedei