java - 我的“if-else”语句有问题,我不知道如何将我的文本字段转换为整数(或其他东西)
问题描述
我不知道如何将我的文本字段(txtGood 和 txtBad)转换为整数,所以我尝试了字符串,但没有用。我应该使用什么?
如您所见,尝试了“字符串”:
private void btnSubstituteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String o, p;
o = txtGood.getText();
p = txtBad.getText();
if(o = p) {
JOptionPane.showMessageDialog(null, "SampleQuoteGood", "Inspirational quote of the day:", JOptionPane.PLAIN_MESSAGE);
}
我运行了程序,但我的按钮 (btnSubstitute) 不起作用。删除代码中的“if”和“String”是可行的。它显示了 JOptionpane 等等。
解决方案
你解析String
. _ 喜欢int one = Integer.parseInt("1");
和比较==
使用=
的是赋值。所以,像
if (Integer.parseInt(o) == Integer.parseInt(p)) {
推荐阅读
- testing - TestCafe 可以支持的最大并发是多少
- php - 安装 Composer,在设置检查期间出现错误“PHP 警告:PHP 启动:无法加载动态库 'php_wincache.dll'”
- sql - 按月优化 postgres 查询平均值 [已编辑]
- r - 显式语句有效,但以语句为模型的函数返回空列表
- ios - Obj-C - 将tableview行设置为在加载时选择?
- c++ - 这里的 const 变量有什么意义吗?
- javascript - 如何在重定向时销毁离子组件
- html - 如何在 CSS 中倾斜悬停
- flutter - 未处理的异常:在插入方法中对空值使用空检查运算符
- jestjs - 3000 次测试 - 主要性能问题。可以做什么?