aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprithugoswami <prithugoswami524@gmail.com>2019-05-03 22:59:03 +0530
committerprithugoswami <prithugoswami524@gmail.com>2019-05-03 22:59:03 +0530
commit3d046dd068049fef8a48f920a11b09b21473e7eb (patch)
treeff7f969f3abca95d0549f6ae9f8273a8a9ae59b3
parentb1a383bc959a9950a0630b1ec953717495199664 (diff)
downloadtmdb-desktop-client-3d046dd068049fef8a48f920a11b09b21473e7eb.tar.gz
tmdb-desktop-client-3d046dd068049fef8a48f920a11b09b21473e7eb.zip
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
-rw-r--r--src/com/oocpro/tmdbdesktop/Constants.java2
-rw-r--r--src/com/oocpro/tmdbdesktop/ImagePanel.java27
-rw-r--r--src/com/oocpro/tmdbdesktop/Main.java17
-rw-r--r--src/com/oocpro/tmdbdesktop/tmdb/Movie.java12
4 files changed, 55 insertions, 3 deletions
diff --git a/src/com/oocpro/tmdbdesktop/Constants.java b/src/com/oocpro/tmdbdesktop/Constants.java
index 03719ee..245c36e 100644
--- a/src/com/oocpro/tmdbdesktop/Constants.java
+++ b/src/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";
}
diff --git a/src/com/oocpro/tmdbdesktop/ImagePanel.java b/src/com/oocpro/tmdbdesktop/ImagePanel.java
new file mode 100644
index 0000000..5d7819d
--- /dev/null
+++ b/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);
+ }
+}
diff --git a/src/com/oocpro/tmdbdesktop/Main.java b/src/com/oocpro/tmdbdesktop/Main.java
index 3b31e12..bbeb1e1 100644
--- a/src/com/oocpro/tmdbdesktop/Main.java
+++ b/src/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 @@ public class Main{
(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);
+
}
}
diff --git a/src/com/oocpro/tmdbdesktop/tmdb/Movie.java b/src/com/oocpro/tmdbdesktop/tmdb/Movie.java
index 22923c0..26d2028 100644
--- a/src/com/oocpro/tmdbdesktop/tmdb/Movie.java
+++ b/src/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 @@ public class Movie{
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");
+
+
}
}