My main problem:
In my JApplet, my actionPerformed method should open a website when a certain item is selected in a JComboBox. The problem, is that the desktop.browse(uri); statement will not work.
I've tried this outside of an applet in just a small program and it ran fine. So there's something here that I must be missing.
Below is my code:
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 javax.swing.BoxLayout;
public class Ranks extends JApplet implements ActionListener{
//Declare varibles
private String address, worldRank, realmRank;
private JLabel guildLogo, worldRankLabel, realmRankLabel,tierNormalLabel, tierHeroicLabel;
private JComboBox tierNormal, tierHeroic;
public void init(){
setLayout(new FlowLayout());
String[] bossesNormal = {"Morchok", "Yor'sahj", "Zon'ozz", "Hagara", "Ultraxion", "Blackhorn", "Spine", "Madness"};
String[] bossesHeroic = {"Morchok"};
realmRank = new String();
worldRank = new String();
tierNormal = new JComboBox(bossesNormal);
tierHeroic = new JComboBox(bossesHeroic);
JLabel blank1 = new JLabel(" ");
guildLogo = new JLabel(new ImageIcon("FD_logo.png"));
JLabel blank2 = new JLabel(" ");
realmRankLabel = new JLabel("Realm Rank: " + realmRank);
JLabel blank3 = new JLabel(" ");
worldRankLabel = new JLabel("World Rank: " + worldRank);
JLabel blank4 = new JLabel(" ");
//worldRankPos = new JLabel(worldRank);
tierNormalLabel = new JLabel("Normal kills");
JLabel blank5 = new JLabel(" ");
tierHeroicLabel = new JLabel("Heroic kills");
JLabel blank6 = new JLabel(" ");
JLabel blank7 = new JLabel(" ");
//Set label fonts and text positions
add(blank1);
add(guildLogo);
add(blank2);
add(realmRankLabel);
add(blank3);
add(worldRankLabel);
add(blank4);
add(blank5);
add(tierNormalLabel);
add(tierNormal);
add(blank6);
//add(blank6);
add(tierHeroicLabel);
add(tierHeroic);
//Set drop boxes actionlisteners
tierNormal.addActionListener(this);
tierHeroic.addActionListener(this);
setSize(new Dimension(185, 200));
getContentPane().setBackground(Color.white);
}
public void actionPerformed(ActionEvent ae){
JComboBox cb = (JComboBox)ae.getSource();
if(ae.getSource() == tierNormal){
//if(tierNormal.getSelectedItem() == "Morchok"){
URI uri = null;
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
try{
uri = new URI("http://www.fromdustelune.com");
desktop.browse(uri);
}
catch(IOException io){
//Do nothing
}
catch(URISyntaxException e){
//Do nothing
}
}
}
public void Run() throws IOException{
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,31);
}
}
Any hints or tips will help greatly. Thanks in advance!