请帮我........... [英] please help me...........

查看:73
本文介绍了请帮我...........的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较使用以下方法的两个Jlabels的值,但它总是存储假我意味着总是执行其他部分我如何解决这个问题?

 < span class =code-keyword> if (lblslctdop1.getText()== lblcorrectans1.getText())
{
lblrightwrong1.setText( TRUE);
得分++;
}
else
{
lblrightwrong1.setText( FALSE);
}

解决方案

在Java中,您需要使用.equals(..)来比较字符串。



您评论中的代码不起作用,因为您没有检查字符串是否相等而是标签。



这应该有效:

  if (lblslctdop1.getText()。equals(lblcorrectans1.getText()) )
/ * ... * /


i want to compare values of two Jlabels i using below method but it always store false i mean always execute else portion how i can fix that problem ?

if ( lblslctdop1.getText( ) == lblcorrectans1.getText ( ) )
    {
    lblrightwrong1.setText ( "TRUE" );
    score++;
    }
else
    {
    lblrightwrong1.setText ( "FALSE" );
    }

解决方案

In Java you need to use .equals(..) to compare strings.

The code from your comment doesn't work because you're not checking the strings for equality but the labels.

This should work:

if( lblslctdop1.getText().equals(lblcorrectans1.getText()) )
/* ... */


这篇关于请帮我...........的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆