Hi all! I've come very close to finishing this applet of mine but I'm stuck on one last part.
The main purpose of this applet is just to fetch some data from a URL (read in 1 line, parse it, and display the data.) After starting this project, I found that applets couldn't access URLs unless they were signed applets. So after completing the applet the way it's meant to function, I signed the applet and it's still giving me errors. When I try loading the applet on a basic HTML page, it gives the Java symbol with the circling loading symbol around it but then it freezes.
I assume it has something to do with my URL function. Any help would be much appreciated, it's been giving me a huge headache ><
The problem lies within the Start() function. So you can skip down right to the problem. I figured I'd paste the whole program if anyone wanted to read through all the code. I know this function works outside of an applet so is there a way to fix this?
import java.util.*;
import javax.swing.JApplet;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.Desktop;
import java.awt.event.*;
import javax.swing.ImageIcon;
import javax.swing.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class Ranks extends JApplet{
//Declare varibles
private String worldRank, realmRank;
private JLabel worldRankLabel, realmRankLabel,tierNormalLabel, tierHeroicLabel, guildLogo;
private JComboBox tierNormal, tierHeroic;
private BufferedImage logo;
public void init(){
Container contents = getContentPane();
contents.setLayout(new FlowLayout());
String[] bossesNormal = {"Morchok", "Yor'sahj", "Zon'ozz", "Hagara", "Ultraxion", "Blackhorn", "Spine", "Madness"};
String[] bossesHeroic = {"Morchok", "Yor'sahj"};
realmRank = new String();
worldRank = new String();
tierNormal = new JComboBox(bossesNormal);
tierHeroic = new JComboBox(bossesHeroic);
//Set logo to guild image
try{
logo = ImageIO.read(this.getClass().getResource("FD_Logo.png"));
guildLogo = new JLabel(new ImageIcon(logo));
}
catch(IOException io){
guildLogo = new JLabel("Error Loading Image");
}
realmRankLabel = new JLabel("Realm Rank: " + realmRank);
worldRankLabel = new JLabel("World Rank: " + worldRank);
tierNormalLabel = new JLabel("Normal kills");
tierHeroicLabel = new JLabel("Heroic kills");
contents.add(guildLogo);
contents.add(realmRankLabel);
contents.add(worldRankLabel);
contents.add(tierNormalLabel);
contents.add(tierNormal);
contents.add(tierHeroicLabel);
contents.add(tierHeroic);
getContentPane().setBackground(Color.white);
setSize(185, 200);
Start();
}
public void Start(){
try{
System.out.println(worldRank);
URL url = new URL("http://www.wowprogress.com/guild/us/elune/From+Dust/json_rank");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String inputLine;
String data = null;
// Set data = to the only line in the input stream from the URL
data = (inputLine = in.readLine());
worldRank = data.substring(28,32);
realmRank = data.substring(62,63);
}
catch(IOException io){}
}
}
Thanks in advance!