I dont know what the problem...seems the button didnt work at all..~
help me find the problem plss...

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class listOfMovies extends JFrame implements ActionListener {

	private JLabel jlbWelcome, jlbPick;
	private JButton jbtBatman, jbtAngels, jbtDue, jbtFaster, jbtFour, jbtHuman, jbtWarrior, jbtWater, jbtHarry;

	public listOfMovies () {

		JPanel p1 = new JPanel ();
		p1.setLayout (new GridLayout (3,3,0,0));

		// image icon for buttons
		ImageIcon batman = new ImageIcon ("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\Batman.jpg");
		ImageIcon angels = new ImageIcon ("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\Angels.jpg");
		ImageIcon due = new ImageIcon ("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\DueDate.jpg");
		ImageIcon faster = new ImageIcon ("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\faster.jpg");
		ImageIcon four = new ImageIcon ("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\Four.jpg");
		ImageIcon human = new ImageIcon ("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\Human.jpg");
		ImageIcon warrior = new ImageIcon ("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\Warrior.jpg");
		ImageIcon water = new ImageIcon ("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\Water.jpg");
		ImageIcon harry = new ImageIcon ("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\harry.jpg");


		// initialize button
		jbtBatman = new JButton (batman);
		jbtAngels = new JButton (angels);
		jbtDue = new JButton (due);
		jbtFaster = new JButton (faster);
		jbtFour = new JButton (four);
		jbtHuman = new JButton (human);
		jbtWarrior = new JButton (warrior);
		jbtWater = new JButton (water);
		jbtHarry = new JButton (harry);



		// add button to the frame
		p1.add(new JButton(batman));
		p1.add(new JButton(angels));
		p1.add(new JButton(due));
		p1.add(new JButton(faster));
		p1.add(new JButton(four));
		p1.add(new JButton(human));
		p1.add(new JButton(warrior));
		p1.add(new JButton(water));
		p1.add(new JButton(harry));


		// p2 hold welcome label, north
		JPanel p2 = new JPanel ();
		p2.setLayout (new FlowLayout());
		p2.add (jlbWelcome = new JLabel("WELCOME TO MOVIE TICKETING SYSTEM"));
		getContentPane().add(p2, BorderLayout.NORTH);


		// p3 hold choose movie label, south
		JPanel p3 = new JPanel ();
		p3.setLayout (new FlowLayout());
		p3.add (jlbPick = new JLabel ("Choose Movie"));
		getContentPane().add(p3, BorderLayout.SOUTH);

		// create scroll bar using scrollpane
		JScrollPane scrollpane = new JScrollPane(p1);
    	getContentPane().add(scrollpane, BorderLayout.CENTER);


    	jbtBatman.addActionListener(this);
    	jbtAngels.addActionListener(this);
    	jbtDue.addActionListener(this);
    	jbtFaster.addActionListener(this);
    	jbtFour.addActionListener(this);
    	jbtHuman.addActionListener(this);
    	jbtWarrior.addActionListener(this);
    	jbtWater.addActionListener(this);
    	jbtHarry.addActionListener(this);


	}

	public void actionPerformed (ActionEvent e) {
       			 if ((e.getSource() == jbtBatman)) {

    				bookBatman frame = new bookBatman ();
   					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setTitle("Book Batman : The Dark Knight"); //set title of thewindow
					frame.setSize(800,600); //size of the window
					frame.setVisible(true); //visible the window
					frame.setLocationRelativeTo (null); //center the window

  					}

  				if((e.getSource() == jbtAngels))  {

  					bookAngels frame = new bookAngels ();
   					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setTitle("Booking Movie"); //set title of thewindow
					frame.setSize(800,600); //size of the window
					frame.setVisible(true); //visible the window
					frame.setLocationRelativeTo (null); //center the window

  					}

  				if((e.getSource() == jbtDue))  {

  					bookDueDate frame = new bookDueDate ();
   					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setTitle("Booking Movie"); //set title of thewindow
					frame.setSize(800,600); //size of the window
					frame.setVisible(true); //visible the window
					frame.setLocationRelativeTo (null); //center the window

					}

				if((e.getSource() == jbtFaster))  {

  					bookFaster frame = new bookFaster ();
   					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setTitle("Booking Movie"); //set title of thewindow
					frame.setSize(800,600); //size of the window
					frame.setVisible(true); //visible the window
					frame.setLocationRelativeTo (null); //center the window

					}

				if((e.getSource() == jbtFour))  {

  					bookFour frame = new bookFour ();
   					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setTitle("Booking Movie"); //set title of thewindow
					frame.setSize(800,600); //size of the window
					frame.setVisible(true); //visible the window
					frame.setLocationRelativeTo (null); //center the window

					}

				if((e.getSource() == jbtHuman))  {

  					bookHumanTarget frame = new bookHumanTarget ();
   					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setTitle("Booking Movie"); //set title of thewindow
					frame.setSize(800,600); //size of the window
					frame.setVisible(true); //visible the window
					frame.setLocationRelativeTo (null); //center the window

					}

				if((e.getSource() == jbtWarrior))  {

  					bookWarrior frame = new bookWarrior ();
   					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setTitle("Booking Movie"); //set title of thewindow
					frame.setSize(800,600); //size of the window
					frame.setVisible(true); //visible the window
					frame.setLocationRelativeTo (null); //center the window

					}

				if((e.getSource() == jbtWater))  {

  					bookWater frame = new bookWater ();
   					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setTitle("Booking Movie"); //set title of thewindow
					frame.setSize(800,600); //size of the window
					frame.setVisible(true); //visible the window
					frame.setLocationRelativeTo (null); //center the window

					}

				if((e.getSource() == jbtHarry))  {

  					bookHarry frame = new bookHarry ();
   					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setTitle("Booking Movie"); //set title of thewindow
					frame.setSize(800,600); //size of the window
					frame.setVisible(true); //visible the window
					frame.setLocationRelativeTo (null); //center the window

					}
	}
	public static void main (String [] args) {

	listOfMovies frame=new listOfMovies ();
 	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setTitle("List of Movies"); //set title of thewindow
	frame.setSize(800,600); //size of the window
	frame.setVisible(true); //visible the window
	frame.setLocationRelativeTo (null); //center the window

	}
}

P:ut a print statement at the start of the ActionPerformed to see if it's being called. If so, it's an error inside the logic of that method.

print statement? do u mean i should use S.O.P(" ")? teach me plss..im learning...~

Yes, System.out.println("Action handler called");
or something like that.
This is a very useful thing to do when debugging any program.
1. To see which code is/isn't being executed and
2. To display the values of variables to check that they are being set/updated as you expect.
Real programmers do it a lot, even before they hit bugs.

// initialize button
jbtBatman = new JButton (batman);

add the action listener to it

jbtBatman.addActionListener(this);

but do you add it to the window?

// add button to the frame
p1.add(new JButton(batman));

No - you create another new button and add that instead.

i still cant grab what r u saying...

did u mean i shouldnt put

p1.add(new JButton(batman));

im trying to combine ImageIcon+JPanel+JButton...

omg..now i see the problem is...~ im so dumb..Thx guys

Edited 5 Years Ago by TinyBelly: n/a

im so dumb

If you are, then so is everyone else who has ever posted or replied in this forum!
We've all done something like that, more than once.
You can often find that kind of "blind spot" error by explaining your code line-by-line to someone else - as soon as you have to read each line of code out loud you often realise that what you wrote wasn't exactly what you intended...

ps Thanks for letting us know how it turned out - it's surprising how often people disappear as soon as they get an answer and just leave the topic open.

This article has been dead for over six months. Start a new discussion instead.