-1

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);

        }

    }
}
vulovicv
  • 19
  • 4
  • I see that twice you have been advised NOT to use a null layout: http://stackoverflow.com/questions/26326496/what-is-wrong-with-my-layout-code and http://stackoverflow.com/questions/26784502/setbounds-not-working-properly. Why do you continue to ask questions when you don't listen to the advice given. Not only that but you haven't "accepted" any answers from your previous questions. So I'll skip this one. – camickr Nov 06 '14 at 18:51
  • its not about null layout,its about actionlistener here. – vulovicv Nov 06 '14 at 18:53
  • But your code still uses a null layout, which means you haven't listened to the advice in past questions or accepted answers in past questions, so why should we continue to help because if you don't like the answer you will probably just ask the question again? – camickr Nov 06 '14 at 19:00
  • because I will see your answer and see if thats the best fit for me. So, can you help me with this? – vulovicv Nov 06 '14 at 19:01

1 Answers1

2

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");
camickr
  • 321,443
  • 19
  • 166
  • 288