Recently in a small system, want to achieve linkage menu, so tried several methods.
1, want to monitor the change of the drop-down menu through a thread, thus control from the menu.
Problems encountered:
①: At first, I'm using an external threading class, but I'm going to change the drop-down menu of the main window with an external thread class,
②: So, you need to pass a class parameter to reference,
③: I invoke the thread class in the main window.
④: Because I need to use the data from the data in the thread class, I need to use the database connection in the thread class
It is not used in the Run method, of course, but is initialized when the data is defined at the very beginning.
⑤: I thought, in the beginning to use the database connection, even once, should be OK.
⑥: Then, run the times wrong, should be the database connection too much, overflow bar.
⑦: On debug, we find a main thread of the IR = new Itemrun (); Here is the error, that is, the initialization of the object is a problem, that is, its construction is problematic.
⑧: Think for a long time, should have figured out: when the main thread calls the threading class, and the thread class has the main threads, and then the main process in the class
The constructor method (my thread class is initialized in the main thread constructor method), which produces an infinite loop, one layer off, a bit like recursion.
2, using events to monitor
①: So multithreading can not be used, suddenly thought of event monitoring
②: To change the items value from the menu by monitoring the JComboBox so that it gets the item selected.
③: it finally worked.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Problems encountered and resolved using the Linkage menu in the Java Desktop program