18보다 큰 값을 입력하면 JLabel
에 하나를 추가하는 프로그램을 만들지 만, 버튼을 클릭 할 때마다 프로그램은 추가 할 때마다 1로 다시 설정됩니다. 당신은 얻을 필요가JButton이 활성화 될 때마다 재설정하지 않고 JLabel에 값을 저장하는 방법은 무엇입니까?
int age = Integer.parseInt(jTextField1.getText()); // gets the value from the button click
if(age >= 18){ // determines if it is greater then 18
int totalOne = 0;
totalOne = totalOne + 1;
String totalAgeOne = Integer.toString(totalOne);
jLabel3.setText(totalAgeOne); // sets the jlabel to One
}else{
int totalTwo = 0;
totalTwo = totalTwo + 1;
String totalAgeTwo = Integer.toString(totalTwo);
jLabel5.setText(totalAgeTwo);
}
도움이 더 필요하면 [MCVE] 또는 [Short, Self Contained, Correct Example] (http://www.sscce.org/)를 게시하십시오. –
'int totalOne = 0;처럼 보일 것입니다.'int totalOne = age;'가되어야합니다. 그러나 모호한 이론 이상에 대해서는 제 첫 코멘트를보십시오. BTW - 이것은'JLabel' /'JButton' 콤보 대신'JSpinner'에 더 적합합니다. –