簡體   English   中英

當用戶單擊按鈕 1/2 時 JVM 沒有響應,它只是卡住了

[英]JVM does not respond when user clicks button 1/2, it just becomes stuck

在此處輸入圖片說明

我正在嘗試制作一個用戶能夠輸入日期的程序: 28 -03 - 2014

這和程序讀取,給出明天的日期,如: 29 - march - 2014 該程序必須檢查:

  • 字符串最多 10 個。
  • 日期(2 位數):1 - 31
  • 字符串: -
  • 月份(兩位數):1 - 12
  • 字符串: -
  • 年份:四位數

這是我的代碼!

    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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM