Results 1 to 3 of 3
  1. #1
    fanjavaid is offline Member
    Join Date
    Dec 2012
    Location
    Jakarta, Indonesia
    Posts
    23
    Rep Power
    0

    Question How to auto call Listener when Program start?

    Hello, i have class Combobox Listener which implements ActionListener interface like this :
    Java Code:
    public class DoctorComboBoxListener implements ActionListener{
    
        @Override
        public void actionPerformed(ActionEvent e) {
            Doctor doctor = (Doctor) MainFrame.cmbDoctor.getSelectedItem();
            System.out.println(doctor.getId());
        }
        
    }
    I have method to retrieve Data from Database an collect them in JComboBox :
    Java Code:
    public void getDoctorData() {
            DoctorService doctorService = new DoctorService();
            List<Doctor> list = doctorService.selectAll();        
            
            cmbDoctor.removeAllItems();
            for (Doctor doctor : list) {
                cmbDoctor.addItem(doctor);
            }
    }
    I try to call that method in my Constructor and call Listener like this :
    Java Code:
    public MainFrame() {
            initComponents();
            
            // Make fullscren startup
            setExtendedState(MainFrame.MAXIMIZED_BOTH);
            
            getDoctorData();    
            cmbDoctor.addActionListener(new DoctorComboBoxListener());
    }
    But, if i start the Application the Listener not automaticaly call.
    It called after i selected the ComboBox.
    Any idea?
    Please, help me. Thank you :)

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: How to auto call Listener when Program start?

    Write a method that you can call both from the ActionListener's actionPerformed and from the constructor

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    fanjavaid is offline Member
    Join Date
    Dec 2012
    Location
    Jakarta, Indonesia
    Posts
    23
    Rep Power
    0

    Default Re: How to auto call Listener when Program start?

    Hello, thanks for your help. It works now :)

Similar Threads

  1. How to auto start Java application form browser
    By marcinz in forum New To Java
    Replies: 5
    Last Post: 04-03-2011, 05:30 PM
  2. java Code to start MDB Listener
    By ganeshkumarm in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 01-20-2011, 12:45 AM
  3. Replies: 1
    Last Post: 01-18-2011, 06:27 PM
  4. Auto Start
    By Blackberrylerner in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 04:49 PM
  5. Replies: 5
    Last Post: 03-20-2009, 10:04 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •