简体   繁体   English

当用户单击按钮 1/2 时 JVM 没有响应,它只是卡住了

[英]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:该程序必须检查:

  • String max 10.字符串最多 10 个。
  • date of day(2 digit): 1 - 31日期(2 位数):1 - 31
  • String: -字符串: -
  • month (two digit): 1 - 12月份(两位数):1 - 12
  • String: -字符串: -
  • year : four digits年份:四位数

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.

相关问题 当用户单击单选按钮时 JVM 生成哪种事件类型? 是动作事件还是物品事件? - Which event type does JVM generate when a user clicks a radio button? Is it an action event or an item event? 用户单击主页按钮时终止活动 - Killing the activity when user clicks the home button 当用户单击按钮时,动画会将按钮滑动到屏幕顶部 - Animation slide a Button to the top of the screen when The User Clicks a Button 按钮不响应 - Button does not respond JavaFX:当用户单击 X 按钮时显示对话框窗口? - JavaFX: Show a Dialog window when a user clicks the X button? 注销后,当用户单击“后退”按钮时,停留在同一页面上 - After logout stay on same page when user clicks on back button 当用户单击GUI中的按钮时,我想打开一个图像 - I would like to open an image when a user clicks on a button in GUI 如何检查用户何时单击了正确的按钮? - How do I check when a user clicks the correct button? 当用户单击按钮时,输入框中会出现奇怪的文本 - When user clicks a button weird text appears in inputbox 用户单击webView上的“提交”按钮时如何完成活动 - How to finish the activity when user clicks on the submit button on webView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM