Problems encountered and resolved using the Linkage menu in the Java Desktop program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.