Solved

Displaying an image from a url

Posted on 1998-07-28
2
203 Views
Last Modified: 2010-03-30
Can you tell me  how to get an image to appear when a user clicks on a button.
On the button click the program reads in a url from a textfield and then should display the appropriate image within the applet - how do I get this to work:

Here is the code, repaint does not repaint the applet and the image does not appear:

import java.awt.*;
import java.applet.*;
import java.net.*;


public class urlimageviewer extends Applet
{
 private Image image;
 private URL urladd;
 private Button loadImage;
 private TextField urlText;
 private String urlTextString;
 
    public void init()
    {
        loadImage = new Button("Get Image");
        urlText = new TextField(30);
        setLayout(new FlowLayout());
        add(urlText);
        add(loadImage);
    }//end of init method

    public void paint(Graphics g)
    {
    boolean b = g.drawImage(image, 20,20,100,100, this);
    }//end of method paint


    public boolean action(Event event, Object arg)
    {
    if (event.target == loadImage)
        {
        try
            {
            urlTextString = urlText.getText();
            urladd = new URL(urlTextString);
            image = getImage(urladd);
            repaint();
            }
            catch(java.lang.Exception ex)
            {
            ex.printStackTrace();
            }
        }//end of if statement
    return true;
    }//end of method action
}//end of class urlImageViewer

Please give me concrete code examples explained in detail, so I don't have to write back for more explanation

Thanks very much for your help

Mel
0
Comment
Question by:help_me
2 Comments
 

Accepted Solution

by:
usk earned 50 total points
ID: 1228614
I have uploaded an applet with the source code to my homepage

http://www.cybersite.dk/examples/

In my example you can only loade one picture, but you just have to add the URL and TextField code from your own code.

Hope this is what you need.

PS. I used JDK 1.2 beta 3
0
 
LVL 2

Expert Comment

by:vendrig
ID: 1228615
First of all, your applet works fine in my appletviewer 1.1.5
and MSIE3 browser. But not in NSNav 4.05...
Two caveats: painting the image, while it could still be
undefined, especially since you don't use the mediatracker.
More important: security. In usk's example, you can see that he
loads images that have the same codebase.
But it seems like your applet doesn't even load applets from the
same codebase. I have some ideas, but it really is beyond my
short-term expertise:(
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
more than one jdk and one jre 1 41
HashTable highest marks enumeration alternative 9 39
hibernate jars 4 32
CSV file parsing thru Java 13 31
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question