Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Creating a Movie Trailer Watcher in Java

In this article you will see a simple desktop app which lets you checkout latest movie trailers and even search movies with your favorite actor/actress.

An application which allows you to search all your favorite movie trailers. It also helps you out watch latest ongoing movie trailer or to search movie trailer by your favorite actor/actress.

Here I will give you a brief idea on important aspects of Virtual Screenshot Manager.

Movie Trailer Watcher

Figure 1: Movie Trailer Watcher

We make a simple swing application. We are dependent on usage of Trailer Addict api.

What the app does is when user request to search a movie or a person then it calls this api with correct values.

This api will return a xml result which can be easily parsed. For example in php pages we can make use of simplexml_load_file method.

After you obtain the result you can simply show it on your page.

Let's start with coding stuff :

The interface has been made in Java which is used to make call to functionality running on website. Now when website receives the request it would do below :

Listing 1: Capture Screenshot

 $newTr=simplexml_load_file("http://api.traileraddict.com/?featured=yes&count=8");

This will return an xml with all latest trailers. We store the results in a variable named $newTr. We now obtain the links from the returned xml and echo that to website.

Listing 2: Search Movie Trailer by Actor/Actress Name

simplexml_load_file("http://api.traileraddict.com/?actor=" . $act . "&count=8");

Here $act store the name of actor or actress for which you require to search trailers. We store the results in a variable named $newTr. This will again return an xml with required trailers.We now obtain the links from the returned xml and echo that to website like below :

Listing 3: Retreive outcome

foreach ($newTr->trailer as $x => $updates) {

    echo $updates->embed;
}

This display the trailers.

Listing 4: Search Movie Trailer by Movie Name

simplexml_load_file("http://api.traileraddict.com/?film=" . $film . "&count=8");

Here $film store the name of movie for which you require to search trailers. We store the results in a variable named $newTr. This will again return an xml with required trailers.We now obtain the links from the returned xml and echo that to website.

This explains the major functionality. Now we explain the functionality of GUI.

GUI code would be like :

Listing 5: GUI


    public MovieTrailer() {
        initComponents();
        if (SystemTray.isSupported()) {
            tray = SystemTray.getSystemTray();
            Image image = getResImg("tray.png");
            ActionListener exitListener = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Exiting....");
                    System.exit(0);
                }
            };

            PopupMenu popup = new PopupMenu();
            MenuItem defaultItem = new MenuItem("Watch latest trailers.");
            defaultItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
String link="http://www.martcode.com/softwareGallery/MovieTrailer.php";
        JTextArea a = new JTextArea("In case browser dont open please move to link " + link);
                    JOptionPane.showMessageDialog(null, a);
                    Constant.openURL(link);

                }
            });
            popup.add(defaultItem);
            defaultItem = new MenuItem("Search Trailer by moviename");
            defaultItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    new SearchMovieByN().setVisible(true);
                    
                }
            });
            popup.add(defaultItem);
            defaultItem = new MenuItem("Search Movie by Actor/Actress name");
            defaultItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    new SearchMovieByA().setVisible(true);
                }
            });
            popup.add(defaultItem);
            defaultItem = new MenuItem("About");
            defaultItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    setVisible(true);
                    try {
                        tray.remove(trayIcon);

                    } catch (Exception ex) {
                    }
                }
            });
            popup.add(defaultItem);
            defaultItem = new MenuItem("Exit");
            defaultItem.addActionListener(exitListener);
            popup.add(defaultItem);
            trayIcon = new TrayIcon(image, "Movie Trailer Watcher", popup);
            trayIcon.setImageAutoSize(true);
        } else {
            System.out.println("system tray not supported");
        }
        addWindowStateListener(new WindowStateListener() {
            public void windowStateChanged(WindowEvent e) {

                if (e.getNewState() == ICONIFIED) {
                    try {
                        tray.add(trayIcon);
                        setVisible(false);
                        System.out.println("added to SystemTray");
                    } catch (AWTException ex) {
                        System.out.println("unable to add to tray");
                    }
                }
                if (e.getNewState() == 7) {
                    try {
                        tray.add(trayIcon);
                        setVisible(false);
                        System.out.println("added to SystemTray");
                    } catch (AWTException ex) {
                        System.out.println("unable to add to system tray");
                    }
                }
                if (e.getNewState() == MAXIMIZED_BOTH) {
                    tray.remove(trayIcon);
                    setVisible(true);
                    System.out.println("Tray icon removed");
                }
                if (e.getNewState() == NORMAL) {
                    tray.remove(trayIcon);
                    setVisible(true);
                    System.out.println("Tray icon removed");
                }
            }
        });
        setIconImage(getResImg("tray.png"));
        setTitle("Movie Trailer Watcher");
        setVisible(true);
    }

Here:

  • We make the application move to tray automatically while minimizing
  • When we click on check Movie Trailer then it calls the Website martcode.com and the website display the relevant trailers using the logic we discussed.
  • When he clicks on Search option then another GUI opens depending he/she want to search by movie name or actor/actress name. The PHP coding has been done at website ie martcode.com

Listing 6: GUI for search by actor/actress

String link="http://www.martcode.com/softwareGallery/MovieTrailer.php?act="+jTextField1.getText()+"&case=2";
        JTextArea a = new JTextArea("In case browser dont open please move to link " + link);
                    JOptionPane.showMessageDialog(null, a);
                    Constant.openURL(link);

When person search by actor/actress we show a message box telling which website we are opening and opens it. We have defined the class Constant having method to open any url.We used Textarea so that we could be able to select the link when the dialog box appears. If we placed jlabel instead we wont be able to select the text and user would have to type the link manually in case the browser don’t open.

Listing 7: GUI for search by Movie name

  String link="http://www.martcode.com/softwareGallery/MovieTrailer.php?mname="+jTextField1.getText()+"&case=3";
        JTextArea a = new JTextArea("In case browser dont open please move to link " + link);
                    JOptionPane.showMessageDialog(null, a);
                    Constant.openURL(link);

When person search by movie we show a message box telling which website we are opening and opens it. We have defined the class Constant having method to open any url. We used Textarea so that we could be able to select the link when the dialog box appears. If we placed jlabel instead we won’t be able to select the text and user would have to type the link manually in case the browser doesn’t open.

An online service for same is at : http://www.martcode.com/softwareGallery/MovieTrailer.php

You can even download the softcopy of this software and use it. Please let me know if you like it.

This is all for this article. See you next time.



My main area of specialization is Java and J2EE. I have worked on many international projects like Recorders,Websites,Crawlers etc.Also i am an Oracle Certified java professional as well as DB2 certified

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login