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!

I had a feeling it had to do with the applet.

Another question I need help with is getting my Run() method to actually run and update the labels each time the applet is run. I know I'm doing something wrong. Do I need to override Start() and then call Run() in Start()?

If you want your methods to be called (except for the 4 that the browser will call)
you will have to call them from some method.

I don't think I can do what I originally planned to do here.

My original plan was to take a string from website (read it, parse it, and assign labels to the parses to display information.) And then I wanted to have a drop down box (when clicked on a specific item) would direct the user to a certain website page.

Since applets can't seem to do any of these main functions, is there anything you would recommend? Can I do this with Java? Basically, my GUI for the applet is displayed information about game progress that I wanted to use on my website. If you have any ideas on how I could still do this, I would be much appreciative!

Have you tried the showDocument method?

No I haven't. The reason for it is because I can't get the information from the site server to update my current standings through the applet so it seems both things I'm trying to do are out of the question using an applet

In hindsight, would these methods work outside of an applet that the applet just calls from another class or would it still result in the same errors?

I can't get the information

Hard code a URL for a test to see if it would work. You do not need to get any data to test if the showDocument method will work.

would these methods work outside of an applet

No, the showDocument method is supported by the browser that the applet is running in.

Okay excellent I appreciate you're help. I'll give that a shot and let you know how it works out!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.