all repos — tmdb-desktop-client @ 3d046dd068049fef8a48f920a11b09b21473e7eb

A simple tmdb desktop client written in Java

Update Movie, Constants class

- Movie class now has a BufferedImage member with the poster of the
movie
- A ImagePanel class added
- Constants class was updated to include the Image url
prithugoswami prithugoswami524@gmail.com
Fri, 03 May 2019 22:59:03 +0530
commit

3d046dd068049fef8a48f920a11b09b21473e7eb

parent

b1a383bc959a9950a0630b1ec953717495199664

M src/com/oocpro/tmdbdesktop/Constants.javasrc/com/oocpro/tmdbdesktop/Constants.java

@@ -2,6 +2,6 @@ package com.oocpro.tmdbdesktop;

public class Constants{ public static final String BASEURL="https://api.themoviedb.org/3"; - public static final String IMG_URL="https://image.tmdb.org/t/p/w500"; public static final String API_KEY="b888b64c9155c26ade5659ea4dd60e64"; + public static final String IURL500="https://image.tmdb.org/t/p/w500"; }
A src/com/oocpro/tmdbdesktop/ImagePanel.java

@@ -0,0 +1,27 @@

+package com.oocpro.tmdbdesktop; + +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.imageio.ImageIO; +import javax.swing.JPanel; + +//Panel to display an Image + +public class ImagePanel extends JPanel{ + + private BufferedImage image; + + public ImagePanel(BufferedImage img) { + image = img; + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + g.drawImage(image, 0, 0, this); + } +}
M src/com/oocpro/tmdbdesktop/Main.javasrc/com/oocpro/tmdbdesktop/Main.java

@@ -2,10 +2,16 @@ package com.oocpro.tmdbdesktop;

import com.oocpro.tmdbdesktop.tmdb.Movie; import com.oocpro.tmdbdesktop.tmdb.Search; +import com.oocpro.tmdbdesktop.ImagePanel; +import java.awt.Dimension; import java.io.IOException; import java.io.InputStreamReader; import java.io.BufferedReader; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; public class Main{

@@ -15,11 +21,20 @@ BufferedReader mname = (new BufferedReader(new InputStreamReader

(System.in))); String Mov_name = mname.readLine(); Search mv = new Search(Mov_name); - Movie det = new Movie(mv.movieIds.get(1)); + Movie det = new Movie(mv.movieIds.get(0)); System.out.println(det.title + " ("+det.year+")"); System.out.println("Plotline: " + det.plotline); System.out.println("Genres: " + det.genres); System.out.println("Rating: " + det.rating); + + ImagePanel ip = new ImagePanel(det.poster); + + JFrame f = new JFrame(); + f.setSize(new Dimension(det.poster.getWidth(), + det.poster.getHeight())); + f.add(ip); + f.setVisible(true); + } }
M src/com/oocpro/tmdbdesktop/tmdb/Movie.javasrc/com/oocpro/tmdbdesktop/tmdb/Movie.java

@@ -2,6 +2,7 @@ package com.oocpro.tmdbdesktop.tmdb;

import com.oocpro.tmdbdesktop.Constants; +import java.awt.image.BufferedImage; import java.io.InputStream; import java.io.IOException; import java.net.MalformedURLException;

@@ -9,21 +10,26 @@ import java.net.URL;

import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import javax.imageio.ImageIO; import org.json.*; public class Movie{ + final String MOVIEBASEURL = Constants.BASEURL+"/movie/"; public String title; public String year; public String plotline; public List<String> genres; public float rating; + public BufferedImage poster; public Movie(int id)throws IOException, MalformedURLException{ String geturl = MOVIEBASEURL+id+"?api_key="+Constants.API_KEY; InputStream res = (InputStream)new URL(geturl).getContent(); JSONObject movie = new JSONObject(new JSONTokener(res)); - //System.out.println(movie.toString(1)); + + String poster_url = Constants.IURL500 + movie.getString("poster_path"); + poster = ImageIO.read(new URL(poster_url)); genres = new ArrayList<String>(); Iterator genres_itr = movie.getJSONArray("genres").iterator();

@@ -33,10 +39,14 @@ while(genres_itr.hasNext()){

JSONObject jo = (JSONObject)genres_itr.next(); genres.add(jo.getString("name")); } + + title = movie.getString("title"); year = movie.getString("release_date").substring(0,4); plotline = movie.getString("overview"); rating = (float)movie.getDouble("vote_average"); + + } }