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

  • Home
  • SEARCH
  • 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 8883733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:53:13+00:00 2026-06-14T20:53:13+00:00

I have a little application that opens a fileChooser when clicking a button and,

  • 0

I have a little application that opens a fileChooser when clicking a button and, after choosing a file, works with the contents of it. So, let’s say we have this pseudo-code:

    File file = new File();
    JFileChooser fileChooser = new JFileChooser();

    [...]

    actionPerformed() {
      file = fileChooser.getSelectedFile();
      doStuffWithFile(file);
    }

At this point, it seems the code is taking on a procedural style, because everything that happens with file now actually happens while still inside that actionPerformed()-method. I’m not sure if this ok.

Is this okay coding style? Intuitively, I would want to end actionPerformed() and have the methods to work on my file called from somewhere else. But how would I do that?

An idea would be to just set the new value of file inside actionPerformed(). Then I could get that value with a getter. But how so? It should be the next thing that happens.

I’ve seen a propertyChangeListener here at stackoverflow, but I’m not sure if that’s the right thing, too.

  • 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-14T20:53:15+00:00Added an answer on June 14, 2026 at 8:53 pm

    One option is multithreading. It would still do everything, but not in the event thread. for example:

    actionPerformed(){
        new Thread(){
            public void run(){
                file = fileChooser.getSelectedFile();
                doStuffWithFile(file);
            }
         }.start()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little php, application or whatever that opens a zip and reads
I have been writing a little application where Form1 opens, checks that a config
I have written a little console application that uses s#arp. I can create an
I have an application that captures keystrokes. But i have read a little bit
In our application we have a little query that looks like this: var selectedAgents
I have a little application which uses regular expressions under VB6. It works perfectly
I have a little application that creates alerts whenever a change to a database
I've created a Windows Mobile application that opens, edits and closes a data file
A little back story : I have small application that will use Word to
I've got yet another deployment problem. What I have: little Windows Forms application that

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.