Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Problem with an array in a timer

  1. #1
    Junior Member
    Join Date
    Oct 2023
    Thanked 0 Times in 0 Posts

    Unhappy Problem with an array in a timer

    Hi, I have a code, which includes arrays. I i'm not an expert but as far as I know, it's supposed to work. The code is supposed to delete any non-integer characters from the textfields in the array. Unfortunately it doesn't, but i can't figure out why.
    This is the array:

    private JTextField[] textFields = {
    txtv1, txtv2, txtv3, txtv4, txtv5, txtv6, txtv7, txtv8, txtv9, txtv10,
    txtv11, txtv12, txtv13, txtv14, txtv15, txtv16, txtv17, txtv18, txtv19,
    txtv20, txtv21, txtv22, txtv23, txtv24, txtv25, txtv26, txtv27, txtv28,
    txtv29, txtv30, txtv31, txtv32, txtv33, txtv34, txtv35, txtv36,
    txtv1to12, txtv13to24, txtv25to36, txtv3to36, txtv2to35, txtv1to34,
    txtv00, txtv0, txtv1to18, txtveven, txtvzwart, txtvodd, txtv19to36, txtvrood

    This is the timer:

    final Timer t3 = new Timer(5000, new ActionListener() {
    public void actionPerformed(ActionEvent e) {

    for (int t = 0; t < 51; t++) {
    if (!(textFields[t]==null)) {
    try {
    int x = Integer.parseInt(textFields[t].getText());
    } catch (Exception ex) {
    textFields[t].setText(textFields[t].getText().substring(0, textFields[t].getText().length() - 1));

    Can someone please tell me what's wrong with this timer?
    Last edited by Tobatobatoba; October 19th, 2023 at 04:24 AM.

Similar Threads

  1. First timer here! Help with very very basic problem
    By brobertson300 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 31st, 2014, 01:44 PM
  2. Problem with timer
    By Hikaros in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 17th, 2013, 12:30 AM
  3. Replies: 2
    Last Post: May 13th, 2011, 03:08 AM
  4. Thread/timer problem
    By korbal in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 18th, 2010, 05:59 PM
  5. bubble sort timer problem
    By JavaNoob82 in forum Algorithms & Recursion
    Replies: 1
    Last Post: March 12th, 2010, 09:22 AM

Tags for this Thread