第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

why cannot read int value from JTextField

why cannot read int value from JTextField

尚方寶劍之說 2019-03-01 11:10:12
JTextField t1 = new JTextField(" "); String a = t1.getText(); int intA = Integer.parseInt(a); System.out.println(intA); Error java.lang.NumberFormatException: For input string: "1 " 附上我的代碼 public class Testing extends JPanel { public int s; public Testing() { JPanel p = new JPanel(); JTextField t1 = new JTextField(" "); JTextField t2 = new JTextField(" "); JTextField t3 = new JTextField(" "); JButton b3 = new JButton("result"); p.add(t1); p.add(t2); p.add(t3); p.add(b3); add(p); b3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { String a = t1.getText(); int intA = Integer.parseInt(a); System.out.println(intA); // String b = t2.getText(); //t3.setText(a+""); } catch (NumberFormatException ignored) { System.out.println(ignored); } } }); } public static void main(String... arg) { Testing p = new Testing(); JFrame frame = new JFrame(); frame.add(p); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); } }
查看完整描述

2 回答

?
神不在的星期二

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊

謝謝@Sjs_k 的答案

JTextField t1 = new JTextField(""); 改去 JTextField t1 = new JTextField(5); 就行了

查看完整回答
反對(duì) 回復(fù) 2019-03-01
  • 2 回答
  • 0 關(guān)注
  • 388 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)