0
일부 게임에서 매 초마다 JLabel을 편집하는 방법 (시간 남음 또는 점수). 이 내 코드 여기Jlabel을 매 초 편집하는 방법?
static int l = 1;
static int s = 5000;
static int t = 90;
public static void main(String[] args) {
//Frame
final JFrame f = new JFrame();
f.setTitle("Picture Puzzle");
f.setSize(500,500);
f.setLocationRelativeTo(null);
f.setResizable(false);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setVisible(true);
// 몇 가지 추가 거즈 여기
JLabel blevel00 = new JLabel("Level:" + l);
JLabel bscore00 = new JLabel("Score:" + s);
JLabel btime00 = new JLabel("Time:" + t);
p2.add(blevel00);
p2.add(bscore00);
p2.add(btime00);
// 몇 가지 추가 거즈
start.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
while(t != 0) { //the t is the static int t = 90;
f.add(p2);
f.remove(p1);
f.setVisible(true);
f.revalidate();
f.repaint();
}
t--;
}
});
} }
이다 나는이 아무것도 시도 일어난다. 어떤 도움을 주시면 감사하겠습니다.
그래서 난 내 코드에서 while 루프를 사용하지 못할 간단한 예제와
업데이트
에 대한 Concurrency in Swing 및 How to use Swing Timers에서보세요? –'actionPerformed' 메소드가 실행되는 이벤트 디스패치 스레드의 컨텍스트 내에 있지 않습니다 ... – MadProgrammer
샘플 코드를 보내 주셔서 감사합니다. 그것은 내 프로젝트에서 많이 도움이 될 것입니다. –