D
D
Domus2017-10-08 23:24:30
Java
Domus, 2017-10-08 23:24:30

How to properly add ActionListener to elements?

Good afternoon.

I've been suffering for 3 hours now - I don't know how to solve the problem.
The entire interface is described in one method . There are a lot of elements in the interface that need to be processed. As a result of clicking on some elements, changes should occur with other elements that are located in this method .
Where to place the listener so that you can handle clicks using switch-case?
So far, I see only this option: add all the elements to the external array, add the listener as a nested class. If the array elements are defined as JComponent, then some methods will be unavailable (for example, .setText() for a JMenu element). Please tell me how to be?

class MyWindow extends JFrame{
      super(){
            create();
      }
      create(){
            //Тут описывается весь интерфейс: панели, элементы.. 
      }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2017-10-08
@zagayevskiy

Think about the architecture, make the whole swing view, and move the switching logic to the controller / presenter. The whole interface in one method approach is bad.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question