java - 我正在尝试让 JButton Age 计算,但我有错误
问题描述
package project;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class agecal {
JButton MyButton = new JButton("This is my button.");
JTextField textField = new JTextField();
MyButton.addActionListener (new ActionListener () {
public void buttonFunction (Action Event e){
int age;
age = currentYear - birthYear;
textField.setText(age);
}}
当有人键入出生年份时,如何使这个 JButton 显示在下面,它在JButton图像下方显示年龄图像
解决方案
这是因为你试图在setText()
方法上打印一个 int,这个方法接受一个字符串作为参数使用
textField.setText(String.valueOf(age));
推荐阅读
- php - How to dynamically update my drivers/etc/hosts file using PHP script for windows?
- jenkins - Raise Abort in Jenkins Job from Batch script
- android - Android System log when cellular data is on and off
- ios - ObjectMapper:在映射函数中使用反射
- java - create windows service from executable JAR file
- javascript - 类型错误:未定义不是对象(评估“this.setState”)
- apache-spark - 如何将相同的rdd保存到多个cassandra表?
- key - GPSShell 无法将 RSA 公钥放在智能卡上
- javascript - 在反应路由器配置中编写异步组件以进行延迟加载
- javascript - 通过控制台在现有图表js上触发axispointer函数