Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8249357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:30:55+00:00 2026-06-07T23:30:55+00:00

I’m implementing a javax.swing.timer to call a synchronous operation on a GUI. However, that

  • 0

I’m implementing a javax.swing.timer to call a synchronous operation on a GUI. However, that operation takes some time to finish and I’d like to provide an abort option to that timer call. Is that possible?

Thx!

import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FilenameFilter;
import java.util.Iterator;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import org.omg.CosNaming.IstringHelper;


public class vtm extends JPanel implements ActionListener{

    private JFrame frame;
    private String children[];
    private ConsoleApp hawk[];
    public static String data[][];
    public Timer timer;
    private int count1, count2;
    private int i;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    vtm window = new vtm();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public vtm() {
        timer = new Timer(25000, this);
        //timer.setInitialDelay(190);
        timer.start();
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {

        frame = new JFrame("VTM");
        frame.setSize(1024, 720);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);

        JLabel lblNewLabel_1 = new JLabel("");
        lblNewLabel_1.setIcon(new ImageIcon("config.png"));
        lblNewLabel_1.setBounds(970, 0, 51, 55);
        frame.getContentPane().add(lblNewLabel_1);
        lblNewLabel_1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                config x = new config();
                x.main(null);
                timer.stop();
                frame.dispose();
            }
            });

        JLabel lblNewLabel = new JLabel("");
        lblNewLabel.setIcon(new ImageIcon("bg.png"));
        lblNewLabel.setBounds(0, 0, 1024, 720);
        frame.getContentPane().add(lblNewLabel);


        String dir = System.getProperty("user.dir");

        File df = new File(dir);

        FilenameFilter fi = new FilenameFilter(){
            public boolean accept(File df, String name){
                return name.startsWith("D-");
            }
        };

        children = df.list(fi);
        hawk=new ConsoleApp[children.length];

        EventQueue.invokeLater(new Runnable(){
            public void run(){

                int count1 = 0; count2 = 0;

                for(i=0;i<children.length;i++)
                {


                hawk[i]=new ConsoleApp(children[i]);

                Iterator<String> it = hawk[i].p.iterator();

                System.out.println("Hi:"+hawk[i].p.size());

                while(it.hasNext())
                {
                    hawk[i].call(it.next());

                    if(count1 == 3)
                    {
                        count2++;
                        count1=0;
                    }

                    System.out.println("Look: " + hawk[i].l.getText().length());
                    hawk[i].l.setBounds((60 + 270*count1) + ((260-(hawk[i].l.getText().length()*7))/2), (70+(count2*60)), 260, 62);
                    hawk[i].c.setBounds(50 + 270*count1, (70+(count2*60)), 273, 62);
                    frame.getContentPane().add(hawk[i].c,0);
                    frame.getContentPane().add(hawk[i].l,0);

                    count1++;
                }
            }
            }
        });
    }

    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("lol");

        EventQueue.invokeLater(new Runnable(){
                public void run(){

                    int count1 = 0; count2 = 0;

                    for(i=0;i<children.length;i++)
                    {


                    hawk[i]=new ConsoleApp(children[i]);

                    Iterator<String> it = hawk[i].p.iterator();

                    System.out.println("Hi:"+hawk[i].p.size());

                    while(it.hasNext())
                    {
                        hawk[i].call(it.next());

                        if(count1 == 3)
                        {
                            count2++;
                            count1=0;
                        }

                        hawk[i].l.setBounds((60 + 270*count1) + ((260-(hawk[i].l.getText().length()*7))/2), (70+(count2*60)), 260, 62);
                        hawk[i].c.setBounds(50 + 270*count1, (70+(count2*60)), 273, 62);
                        frame.getContentPane().add(hawk[i].c,0);
                        frame.getContentPane().add(hawk[i].l,0);

                        count1++;
                    }
                }
                }
            });


    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:30:57+00:00Added an answer on June 7, 2026 at 11:30 pm

    You actionPerformed triggers a Runnable, which I assume is what takes a long time and what you would like to abort. Inside the Runnable’s run method you have two loops, for(i=0;i<children.length;i++) and while(it.hasNext()). If you add a stopping condition to these loops, you can make the Runnable finish early by controlling that condition from outside.

    For example, add a field abort to vtm and change the two loops to for(i=0;i<children.length && !abort;i++) and while(it.hasNext() && !abort) respectively. You can now set abort to true and the Runnable will stop the next time it tries to loop again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.