0

I'm coding a Java program that provides the user with some info on a given element. For example, the user chooses "Hydrogen," and the program gives some info about Hydrogen. I'd like to take the "thumbnail" image from the Wikipedia article associated with the element. Here's an example of the thumbnail image. I know it's asking for a lot, but I'd like to take a String ("Helium," for example) and convert it into ImageIcon that I can put into a JPanel. I've looked at the WikiData API, but I just don't know how to read that in Java. Here's a little sample of what I'm talking about:

import javax.swing.*;
class ImageTest{
    public static void main(String args[]){
        String elementName = "Hydrogen";
        findImage(elementName);
        JFrame frame = new JFrame("Frame");
        ImageIcon source = new ImageIcon(//blah blah);
        JLabel image = new JLabel(source);
        frame.add(image);
        frame.pack();
        frame.setVisible(true);
    }
}

Thanks in advance for the input! :)

  • Just to clarify, I'm not worried about converting the Image URL in the JFrame. I'm trying to find the Image URL in the first place. – Will Heitman Nov 26 '16 at 17:51
  • 2
    You can refer to the linked question to do that. For example, the image for Helium wiki page is retrieved with `https://en.wikipedia.org/w/api.php?action=query&titles=Helium&prop=pageimages&format=json`. The link is in the `"thumbnail" > "source"` element. – Tunaki Nov 26 '16 at 17:56

0 Answers0