![](/img/trans.png)
[英]Which event type does JVM generate when a user clicks a radio button? Is it an action event or an item event?
[英]JVM does not respond when user clicks button 1/2, it just becomes stuck
我正在嘗試制作一個用戶能夠輸入日期的程序: 28 -03 - 2014
。
這和程序讀取,給出明天的日期,如: 29 - march - 2014
。 該程序必須檢查:
-
-
這是我的代碼!
public String month()
{
int month = 0;
switch(month){
case 1 :monthString = " Janauri";
break;
case 2: monthString = "February"
.......
ublic String dateOfTomorrow(int day, int month, int year)
{
String Date = day+ "-" + month+ "- " + year;
day++;
if(day > totalDaysInMonth(month));
{// new month
day = 1;
month++;
if(month > 12)
{//new year
month= 1;
year ++;
}
}
return Date;
}
private boolean totalDaysInMonth(int day)
{
if( day >= 1 && day < 31)
{
return true;
}
else {
return false;
}
}
public void actionPerformed(ActionEvent e)
{
for ( int i = 1; i<31;);
String s = tf.getText();
if ( e.getSource() == b1)
{
l2.setText(s);
}
else if (e.getSource ()== b2)
{
l2.setText(monthString);
}
}
我認為你的問題在這個循環中:
for ( int i = 1; i<31;);
這永遠不會結束。 刪除該空循環或將其更改為:
for ( int i = 1; i<31;i++);
我真的不明白你所說的 1/2 堆棧是什么意思。 但是如果你制作一個由一些變量組成的字符串
String Date = day + "-" + month + "-" + year;
然后更改它對字符串沒有任何影響的變量。 所以你仍然會得到相同的日期。
一個提高可讀性的提示使您的變量采用駝峰式大小寫。 因此,不要將日期稱為日期。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.