将线程值输出到文本框中

时间:2013-04-09 16:42:18

标签: java multithreading user-interface

我正在尝试将银行帐户的值输出到文本框。该程序是银行账户模拟,线程随着模拟的进行而变化。目前,这些值将输出到控制台。

以下是目前输出的代码:

public BankAccount()
{
    accountBalance = 0 ;
}

public synchronized void deposit(int addAmount, String name)
{
    // the 'name' argument holds the name of the source of this credit 

    accountBalance+=addAmount ;
    System.out.println(name + " added " + addAmount) ;
    System.out.println("Account balance is now standing at " + accountBalance);
}

public synchronized void withdraw(int takeAmount, String name)
{
    // the 'name' argument holds the name of the bill being paid

    accountBalance-=takeAmount ;
    System.out.println(name + " took " + takeAmount) ;
    System.out.println("Account balance is now standing at " + accountBalance);
}

public int getBalance()
{
    return accountBalance ;
}

1 个答案:

答案 0 :(得分:0)

因为您将要生成多个线程,每个线程都能够更新单个JTextArea,所以您需要注意一个名为Event Queue的概念。 Here是一个解释您可以采取的方法的页面。