This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Bank Simulation Program (Help appreciated )- Clear data from JLabel [NetBeans 8.1, JDK 8]  RSS feed

Brendan Rodgers
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all

I have completed my assignment which was a Bank Simulation program. The way the program is meant to function is stated below:

  • You select the type of account (Current or Savings)
    You enter an initial balance to create account
    You click the Create Account button
    This amount is now displayed as the total account balance
    Then you click the Start Simulation button
    This starts a timer, which counts a month every 5 seconds
    At each 5 second interval (month), a random transaction (deposit/withdrawal) occurs, and the amount is added or taken away from the total balance
    These transactions that occur are displayed in a JLabel, stating how much was deposited or withdrawn at each month.

  • This is working for me, except for the issue stated below:

  • Issue: When I select for example Current account, and run the simulation the transaction data/history is displayed, which is what should happen. But when I select a different type of account, such as Savings, and start Simulation, the new transaction data will continue to populate under the previous accounts transaction data.

  • I am looking for a solution, that when a different account is simulated, after a simulation has occured (e.g. after a Current account simulation has completed a Savings account simulation is started) that the previous transaction data will be cleared, and only the current simulation data is shown.

    I have tried to setText(null); and setText(""); in a button called "Clear Transaction Data", so the user can clear the data before they start the simulation of another account and the data does disappear. But when I start the new simulation, the old transaction data will be shown again, and the new transaction data will start to be populated under it.

    Thanks to anyone who can help me work towards a solution, provides information, or who views this post,

    Here is my code below

    Campbell Ritchie
    Posts: 55715
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Welcome to the Ranch

    My, isn't that NetBeans GUI Builder code illegible. It always is. That is why we advise people to avoid IDEs; you end up learning the IDE rather than Java®.
    Why have you got that many fields? Why have you not given them real names? jLabel2 is particularly bad. Most of them should probably be local variables, except the balance and similar. Those belong outwith that class; you should have a Bank class which is completely separate from the GUI. You should be able to run that Bank app with no GUI, before you even think of a frame to display it in.
    Why have you got those setVisible(false) calls?
    Why have you got those int fields? I am sure they ought not to be ints (well, most of them).
    Why are you using that Timer rather than a Swing timer? What is the timer for in the first place?

    It is quite easy to change the text in a component with text; you usually say
    I presume you have checked whether a JLabel actually has a setText() method. You can probably set the text to "".
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!