[英]JVM does not respond when user clicks button 1/2, it just becomes stuck
I am trying to make a program that user is able to enter a date like: 28 -03 - 2014
.我正在尝试制作一个用户能够输入日期的程序:
28 -03 - 2014
。
This and the program reads that, gives the date of tomorrow like: 29 - march - 2014
.这和程序读取,给出明天的日期,如:
29 - march - 2014
。 The program must check about:该程序必须检查:
-
-
-
-
Here is my code!这是我的代码!
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);
}
}
I think your problem is in this loop:我认为你的问题在这个循环中:
for ( int i = 1; i<31;);
which will never end.这永远不会结束。 Remove that empty loop or change it to:
删除该空循环或将其更改为:
for ( int i = 1; i<31;i++);
I don't really understand what you mean by 1/2 stack.我真的不明白你所说的 1/2 堆栈是什么意思。 But if you make a string of some variables
但是如果你制作一个由一些变量组成的字符串
String Date = day + "-" + month + "-" + year;
and then change the variables it doesn't have any effect on the string.然后更改它对字符串没有任何影响的变量。 So you will still get the same date back.
所以你仍然会得到相同的日期。
And a tip for better readability makes your variables camel cased.一个提高可读性的提示使您的变量采用驼峰式大小写。 So instead of Date call it date.
因此,不要将日期称为日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.