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 8690301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:52:25+00:00 2026-06-12T23:52:25+00:00

I have a dialog, which have four buttons say New, Save, Delete, Cancel. Now

  • 0

I have a dialog, which have four buttons say New, Save, Delete, Cancel. Now each of these need to perform their action. So I have defined a separate class which implements an ActionListener. I have used this class to perform each of the button action.

public class MyClass implements ActionListener {
  public void actionPerformed(ActionEvent e) { 
   if(e.getActionCommand().toString() == "OK") {
        // Code
   } else if( .. ){

   }
  }
}

What I have done is, I defined an inner class which I used to do the same functionality. But what I was not getting is, is it best practice to write a separate class or is it best to use inner class. I was suggested to write in a public class so tomorrow some one can use this class to perform their action. So I have the following questions,

  1. If the functionality is not called by any object (which I can’t say) then I can write it in inner class? OR

  2. Is it a good practice always to write inner class which performs the actions of that dialog?

  • 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-12T23:52:26+00:00Added an answer on June 12, 2026 at 11:52 pm

    There is no general answer to these questions. If the code in actionPerformed() is one line, writing a whole class file is usually overkill.

    If the code is more complex, it might be suitable to reuse but as the code grows, it also gets more specific (so you can’t reuse it anymore).

    Try to follow this approach:

    • Build your application from simple blocks that are independent of each other.
    • Configure the application by writing code that connects the blocks.

    So in your case, you could have helper methods which do the work. Wrap them in Swing Actions; this allows you to use them in all kinds of buttons and menus.

    Try to move as much work as possible into the helpers so that the actions become really simple. If in doubt, ask yourself: Is this code part of the work? Does everyone need to do this?

    If yes, then the code should go into a work/helper class.

    If it’s things like UI related checks (visible/enabled), conversion (string to number), validation, etc., it should go into the action.

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

Sidebar

Related Questions

I have an MFC dialog in which there are two radio buttons. I have
I have four Buttons that display the the date/time of calendars which are attributes
Say I have a WPF dialog in which I have async event handlers that
I have a modeless dialog which i need to show multiple instances of it
I have a custom dialog which has 3 buttons and sometimes it has one
I have a dialog which is used to create 2 sets of data which
I have a jQuery dialog which loads an external php page. All is working
hello all I have a small dialog which I created dynamically, which has a
Introduction I have been so annoyed by applications that have a startup dialog which
I have a modal settings dialog which is a JDialog. In this settings window

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.