Add files via upload
This commit is contained in:
parent
3b647d3dde
commit
41b196cb46
20
apiTMDB.iml
Normal file
20
apiTMDB.iml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="module-library">
|
||||||
|
<library>
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://H:/json-simple-1.1.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</orderEntry>
|
||||||
|
</component>
|
||||||
|
</module>
|
BIN
out/production/apiTMDB/apiTMDB.class
Normal file
BIN
out/production/apiTMDB/apiTMDB.class
Normal file
Binary file not shown.
BIN
out/production/apiTMDB/gui$1.class
Normal file
BIN
out/production/apiTMDB/gui$1.class
Normal file
Binary file not shown.
BIN
out/production/apiTMDB/gui.class
Normal file
BIN
out/production/apiTMDB/gui.class
Normal file
Binary file not shown.
BIN
out/production/apiTMDB/main.class
Normal file
BIN
out/production/apiTMDB/main.class
Normal file
Binary file not shown.
52
src/apiTMDB.java
Normal file
52
src/apiTMDB.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
public class apiTMDB {
|
||||||
|
private static final String apikey = "9fd90530b11447f5646f8e6fb4733fb4";
|
||||||
|
|
||||||
|
public apiTMDB(){
|
||||||
|
String json="";
|
||||||
|
try {
|
||||||
|
URL apiurl = new URL("https://api.themoviedb.org/3/movie/550?api_key=9fd90530b11447f5646f8e6fb4733fb4");
|
||||||
|
BufferedReader myreader = new BufferedReader(new InputStreamReader(apiurl.openStream(), Charset.forName("UTF-8")));
|
||||||
|
json = readAll(myreader);
|
||||||
|
|
||||||
|
JSONParser pars = new JSONParser();
|
||||||
|
|
||||||
|
JSONObject jsonobj = (JSONObject) pars.parse(json);
|
||||||
|
System.out.println(jsonobj.get("id"));
|
||||||
|
|
||||||
|
System.out.println(json);
|
||||||
|
} catch (MalformedURLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readAll(Reader rd) throws IOException {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
int cp;
|
||||||
|
while ((cp = rd.read()) != -1) {
|
||||||
|
sb.append((char) cp);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
98
src/gui.java
Normal file
98
src/gui.java
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import com.sun.jndi.toolkit.url.UrlUtil;
|
||||||
|
import com.sun.webkit.network.Util;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.net.Authenticator;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.PasswordAuthentication;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
public class gui extends JFrame {
|
||||||
|
|
||||||
|
JPasswordField passfield;
|
||||||
|
JTextField userfield;
|
||||||
|
|
||||||
|
JLabel logininfo;
|
||||||
|
|
||||||
|
public gui(){
|
||||||
|
this.setTitle("TMDB api");
|
||||||
|
this.setSize(500,500);
|
||||||
|
|
||||||
|
addelements();
|
||||||
|
addlisteners();
|
||||||
|
|
||||||
|
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
this.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setProxy(String authUser, String authPassword) {
|
||||||
|
Authenticator.setDefault(
|
||||||
|
new Authenticator() {
|
||||||
|
@Override
|
||||||
|
public PasswordAuthentication getPasswordAuthentication() {
|
||||||
|
return new PasswordAuthentication(
|
||||||
|
authUser, authPassword.toCharArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
//set https proxy
|
||||||
|
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
|
||||||
|
System.setProperty("https.proxyUser", authUser);
|
||||||
|
System.setProperty("https.proxyPassword", authPassword);
|
||||||
|
System.setProperty("https.proxyHost", "proxy.htl-steyr.ac.at");
|
||||||
|
System.setProperty("https.proxyPort", "8082");
|
||||||
|
|
||||||
|
//set http proxy
|
||||||
|
System.setProperty("http.proxyUser", authUser);
|
||||||
|
System.setProperty("http.proxyPassword", authPassword);
|
||||||
|
System.setProperty("http.proxyHost", "proxy.htl-steyr.ac.at");
|
||||||
|
System.setProperty("http.proxyPort", "8082");
|
||||||
|
|
||||||
|
try {
|
||||||
|
new URL("http://google.com").openStream();
|
||||||
|
new URL("https://google.com").openStream();
|
||||||
|
return true;
|
||||||
|
} catch (IOException e1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addlisteners(){
|
||||||
|
passfield.addActionListener(e -> {
|
||||||
|
if(setProxy(userfield.getText(),String.copyValueOf(passfield.getPassword()))){
|
||||||
|
logininfo.setText("logged in successfully");
|
||||||
|
}else{
|
||||||
|
logininfo.setText("loggin error!");
|
||||||
|
}
|
||||||
|
new apiTMDB();
|
||||||
|
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addelements(){
|
||||||
|
this.setLayout(new BorderLayout());
|
||||||
|
userfield = new JTextField();
|
||||||
|
passfield = new JPasswordField();
|
||||||
|
|
||||||
|
logininfo = new JLabel("Not logged in yet");
|
||||||
|
|
||||||
|
JPanel authpanel = new JPanel(new GridLayout(2,2));
|
||||||
|
authpanel.add(new JLabel("User:"));
|
||||||
|
authpanel.add(userfield);
|
||||||
|
authpanel.add(new JLabel("Password:"));
|
||||||
|
authpanel.add(passfield);
|
||||||
|
|
||||||
|
this.add(logininfo,BorderLayout.SOUTH);
|
||||||
|
this.add(authpanel,BorderLayout.NORTH);
|
||||||
|
}
|
||||||
|
}
|
5
src/main.java
Normal file
5
src/main.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
public class main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new gui();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user