简体   繁体   中英

WindowBuilder Eclipse doesnt respond to actionlistener

I have a question. Im using WindowBuilder in Eclipse and when i type in the code,my action listener doesnt work. I tried everything.

Also,another question,when using WindowBuilder,what is the name of my frame object? I see there thtat it is made in my class,but it doesnt have name.

    public OrdinacijaGui()
{



    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    setBounds(600 , 300 , 450 , 300);
    setTitle("Dr Idrizovic");

    getContentPane().setLayout(null);

    JButton regUslugaButt = new JButton("Registar usluga");
    regUslugaButt.setBounds(10, 11, 150, 30);
    getContentPane().add(regUslugaButt);


    JButton regMaterijalaButt = new JButton("Registar materijala");
    regMaterijalaButt.setBounds(10, 71, 150, 30);
    getContentPane().add(regMaterijalaButt);


    JButton regIntervencijaButt = new JButton("Registar intervencija");
    regIntervencijaButt.setBounds(10, 131, 150, 30);
    getContentPane().add(regIntervencijaButt);


    JButton regDijagnozaButt = new JButton("Registar dijagnoza");
    regDijagnozaButt.setBounds(10, 191, 150, 30);
    getContentPane().add(regDijagnozaButt);


    JButton exitButt = new JButton("Zavrsetak rada");
    exitButt.setBounds(143, 232, 150, 30);
    getContentPane().add(exitButt);


    JButton evidencijaPacButt = new JButton("Evidencija pacijenata");
    evidencijaPacButt.setBounds(230, 11, 200, 30);
    getContentPane().add(evidencijaPacButt);


    JButton zakazivanjePacButt = new JButton("Zakazivanje pacijenata");
    zakazivanjePacButt.setBounds(230, 71, 200, 30);
    getContentPane().add(zakazivanjePacButt);


    JButton evidencijaStomatologaButt = new JButton("Evidencija stomatologa");
    evidencijaStomatologaButt.setBounds(230, 131, 200, 30);
    getContentPane().add(evidencijaStomatologaButt);


    JButton izvrseneUslugeButt = new JButton("Izvrsene usluge");
    izvrseneUslugeButt.setBounds(230, 191, 200, 30);
    getContentPane().add(izvrseneUslugeButt);


    thehandler handler = new thehandler();

    regUslugaButt.addActionListener(handler);
    regMaterijalaButt.addActionListener(handler);
    regIntervencijaButt.addActionListener(handler);
    regDijagnozaButt.addActionListener(handler);
    exitButt.addActionListener(handler);
    evidencijaPacButt.addActionListener(handler);
    zakazivanjePacButt.addActionListener(handler);
    evidencijaStomatologaButt.addActionListener(handler);
    izvrseneUslugeButt.addActionListener(handler);

}



public class thehandler implements ActionListener
{
    public void actionPerformed(ActionEvent event)
    {

        if(event.getSource() == regMaterijalaButt )
        {
            RegistarMaterijala regMat = new RegistarMaterijala();
        }

        if (event.getSource() == exitButt)
        {
            System.exit(0);

        }

    }
}

You button is defined twice, once as a local variable and once as an instance variable

JButton regMaterijalaButt = new JButton("Registar materijala");

Above is where you are defining the button as a local variable

if(event.getSource() == regMaterijalaButt )

Your ActionListener is referencing the instance variable.

Your code should be:

//JButton regMaterijalaButt = new JButton("Registar materijala");
regMaterijalaButt = new JButton("Registar materijala");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM