[英]How can i change the JTextArea string to something else
在我的代碼中,我已將我的JtextArea公開,並在我的代碼中,我將其稱為jtextare和setTextArea,但是當我按下該按鈕時,因為它是一個線程,它不允許我在掃描儀工作時更改JTextArea
public void scan() throws InterruptedException {
try {
//This is the part i called it but doesnt change the jtextfield into getUid
Login login = new Login();
login.jTextField_username.setText(getUid);
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
CardTerminal terminal = terminals.get(0);
System.out.println("Waiting for a card..");
if (terminal == null) {
return;
}
terminal.waitForCardPresent(0);
Card card = terminal.connect("T=1");
System.out.println("Card: " + card);
System.out.println("Protocol: " + card.getProtocol());
CardChannel channel = card.getBasicChannel();
ResponseAPDU response = channel.transmit(new CommandAPDU(new byte[]{(byte) 0xFF, (byte) 0xCA, (byte) 0x00, (byte) 0x00, (byte) 0x00}));
System.out.println("Response: " + response.toString());
if (response.getSW1() == 0x63 && response.getSW2() == 0x00) {
System.out.println("Failed");
}
System.out.println("UID: " + bin2hex(response.getData()));
getUid = bin2hex(response.getData());
} catch (CardException ex) {
Logger.getLogger(CardId.class.getName()).log(Level.SEVERE, null, ex);
}
}
請注意,我們無法編譯或運行代碼段,因此給出的任何答案都必須包含猜測,但是,話雖如此,我認為問題在於您在這里的假設是錯誤的:
//This is the part i called it but doesnt change the jtextfield into getUid
Login login = new Login(); // **** A ****
login.jTextField_username.setText(getUid); // **** B ****
在A行,您創建一個新的Login對象,但這是實際顯示的對象嗎? 我感覺不是,您已經創建並顯示了“登錄”窗口,現在正在創建一個新的,從未顯示過,並且B行正在更改其狀態(保存在其文本組件之一中的文本) )。 如果我的猜測是正確的,那么更好的解決方案是更改實際顯示的Login對象的狀態,而不是使用此方法創建的新的獨特對象。 這個怎么做? 無法陳述您到目前為止所提供的信息。
如果您想得到更可靠的答案,則可以在問題中創建並發布有效的[最小,完整和可驗證的示例](最小,完整和可驗證的示例)-請檢查鏈接,因為它會全部說明。
其他不相關的問題:
JTextArea
,但是代碼表明我們正在處理JTextField
-是嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.