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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:47:02+00:00 2026-06-17T19:47:02+00:00

public class EventController extends MouseAdapter implements ActionListener { private EventModel model; private EventView view;

  • 0
public class EventController extends MouseAdapter implements ActionListener {

    private EventModel model;
    private EventView  view;
    String tableClick;
    Events events;    

    /** Constructor */
   public EventController(EventModel myModel, EventView myView){
       model = myModel;
       view = myView;     
   }

   public void setUpListeners() {
       this.view.addEventButton.addActionListener(this); 
       this.view.addEventMenuItem.addActionListener(this);
       this.view.editEventMenuItem.addActionListener(this);
       this.view.tableEvent.addMouseListener(this);                
   }

   @Override
   public void actionPerformed(ActionEvent e){
       Object button = e.getSource();
       if(button==this.view.addEventButton) {
           setEventDetails();          
       }                
   }

   @Override
   public void mouseClicked(java.awt.event.MouseEvent event) {
      int rowSelected = view.tableEvent.getSelectedRow();
       //blahblahblah
      view.changeDisplay(events);
    }

How do I Override the method keyPressed of the KeyListener class just like I have done with the mouseClicked, and ActionPerformed I really don’t want to override keyTyped and keyReleased, just the keyPressed on its own. The interaction takes place in another class called VIEW

  • 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-17T19:47:03+00:00Added an answer on June 17, 2026 at 7:47 pm

    Java does not support multiple inheritance, so you can’t extend multiple classes, you can’t have something like:

    class EventController extends MouseAdapter, KeyAdapter
    

    You can implement multiple interfaces however, but it seems that you want to avoid that.

    Now, the solution to this kind of problem is always the same, use composition over inheritance. You could easily have two inner-classes: one that extends KeyAdapter and the other MouseAdapter. Then later on, when you need to add listeners, you uses fields of your class instead of this.

    Something like this:

    import java.awt.event.ActionListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.MouseAdapter;
    
    public class EventController {
        private EventModel model;
        private EventView  view;
        String tableClick;
        Events events;
    
        private MouseAdapter mouseListener = new MouseAdapter() {
    
            @Override
            public void mouseClicked(java.awt.event.MouseEvent event) {
              int rowSelected = view.tableEvent.getSelectedRow();
               //blahblahblah
              view.changeDisplay(events);
            }
        };
    
        private KeyAdapter keyAdapter = new KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent e) {
                // Perform here whatever is needed
                // You also have access to your enclosing instance EventController.this and its methods
            }
        };
    
        private ActionListener actionListener = new ActionListener() {@Override
                   public void actionPerformed(ActionEvent e){
               Object button = e.getSource();
               if(button==this.view.addEventButton) {
                   setEventDetails();          
               }
    
           }
    
    
    
        /** Constructor */
       public EventController(EventModel myModel, EventView myView){
           model = myModel;
           view = myView;     
        }
    
       public void setUpListeners() {
           this.view.addEventButton.addActionListener(actionListener); 
           this.view.addEventMenuItem.addActionListener(actionListener);
           this.view.editEventMenuItem.addActionListener(actionListener);
           this.view.tableEvent.addMouseListener(mouseListener);
           // Here you can also add the keyadapter to your views
       }
    
    
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Prerequisites { private class Course implements Comparator<Course> { public String name; public
public class FBPost extends Service{ private Bundle params = new Bundle(); private String userID=;
public class SuperUser extends User implements Serializable{ private static final long serialVersionUID = 1L;
public class AycanClass extends AsyncTask<String, Void, String> implements IAppointments { Activity activity; public AycanClass(Activity
public class A { private A(int param1, String param2) {} public static A createFromCursor(Cursor
public class TwitterActivity extends Activity { private Twitter twitter; private OAuthProvider provider; private CommonsHttpOAuthConsumer
public class Challenge implements Comparable<Challenge>, Serializable { private static final long serialVersionUID = 6970603871560357536L;
public class CheckBoxDemo extends Activity implements CompoundButton.OnCheckedChangeListener { CheckBox cb; @Override public void onCreate(Bundle
public class BaseFoo { private string param; public BaseFoo(string param) { this.param = param;
public class StatisticsViewPresenter { private IStatisticsView view; private Statistics statsModel; public StatisticsViewPresenter(IStatisticsView view, Statistics

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.