Help with simple applet code

i wanted to write a applet that would display a image,(this is my first program) i wrote the code shown below,but image space is emptly when i load it up with any browser.....i ran the code in netbeans,,, i am a novice, any piece of advice also wud be helpful.........
<applet code="imagereadingapplet" width=500 height=500>
<param name="img" value="kollam.gif">
</applet>
import java.applet.*;
import java.awt.*;
* @author raman
public class imagereadingapplet extends Applet {
* Initialization method that will be called after the applet is loaded
* into the browser.
Image img;
@Override
public void init() {
img = getImage(getDocumentBase(),"kollam.gif");
@Override
public void paint(Graphics g){
g.drawImage(img,0,0,this);
// TODO overwrite start(), stop() and destroy() methods
}

Hi,
First advice imagereadingapplet -> ImageReadingApplet (Java name convention).
Second image file name is hard coded so you don't have to set param for the applet (Best would be not to hard code this name).
Finally maybe the most interesting, It seems that image kollam.gif is not at root folder.
I don't really know netbeans but your image must be in bin folder, the same as imagereadingapplet.class.

Similar Messages

  • Help with simple applet - dragging box

    Hi I need help with a simple applet concept.
    I have a picture drawn in the background, but I need to draw a square and resize it when I drag.
    So with the picture in the background I click, drag the mouse, and it draws a rectangle from the starting point to where the mouse is while the mouse is clicked.
    The only problem is I can't figure out how to do this without redrawing the whole picture. If I don't repaint, it just keeps stretching around rectangles and leaving them there.
    I don't really need exact code, just an idea on how to do this without repainting the background every time the mouse is moved (because the picture in the background is complicated to draw and takes like a second).
    Thanks
    [nvm, found out about xormode]
    Edited by: BugMenOTdhzj on Nov 30, 2009 4:47 PM

    BugMenOTdhzj wrote:
    ..the picture in the background is complicated to draw and takes like a second).Paint the 'picture in the background' to a BufferedImage, then when it comes to paint()/paintComponent(), draw the BI to the Graphics object (clipped, if necessary (1)), then draw the rectangle to the Graphics object. This would be further optimised at time of rendering, by drawing both the 'picture in the background' BI and rectangle to a second BI, and finally writing that 2nd BI to the Graphics object.
    1) There are potentially other improvements that can be made, particularly with clipping, but I suspect if you try as I suggested, the rendering will be very quick and responsive. I have 40 FPS sound trace animations that do a great deal more on each call to paintComponent(), before bursting the final BI to screen.

  • Need Help With Simple ABAP Code

    Hello,
    I'm loading data from a DSO (ZDTBMAJ) to an Infocube (ZCBRAD06). I need help with ABAP code to some of the logic in Start Routine. DSO has 2 fields: ZOCTDLINX & ZOCBRDMAJ.
    1. Need to populate ZOCPRODCD & ZOCREFNUM fields in Infocube:
        Logic:-
        Lookup /BI0/PMATERIAL, if /BIC/ZOCBRDMAJ = /BIC/OIZOCBRDMAJ
        then /BIC/ZOCPRODCD = ZOCPRODCD in Infocube
               /BIC/ZOCREFNUM = ZOCREFNUM in Infocube         
    2. Need to populate 0G_CWWTER field in Infocube:
        Logic:
        Lookup /BIC/PZOCTDLINX, if /BIC/ZOCTDLINX = BIC/OIZOCTDLINX
        then G_CWWTER = 0G_CWWTER in Infocube.
    I would need to read single row at a time.
    Thanks!

    I resolved it.

  • Please help with simple esle code

    Hi all
    Please can someone tell what I am doing Wrong with tis code.
    I just can not see it
    Please Help Me
    Craig
    void ShippAddressjCheckBox_actionPerformed(ActionEvent e) {
    if (ShippAddressjCheckBox.setSelected(true ));
    CopyAddress1();
    else (ShippAddressjCheckBox.setSelected(false ));
    ClearShippingAddress();
    }

    Thanks for that
    this is what I have done
    void ShippAddressjCheckBox_actionPerformed(ActionEvent e) {
    if (ShippAddressjCheckBox.setSelected(true ))
    CopyAddress1();
    else if (ShippAddressjCheckBox.setSelected(false)) {
    ClearShippingAddress();
    I can seam to get it to work
    Thanks

  • Help with graph applet code

    I cant figure out how to finsih this... I am creating an applet that draws a quadratic equation according to the parameters in the html file...
    Here is the first class... I think its ok:
    import java.awt.*;
    import java.applet.*;
    public class Graph extends Applet
         public void init()
             int in1 = Integer.parseInt(getParameter("a"));
             int in2 = Integer.parseInt(getParameter("b"));
             int in3 = Integer.parseInt(getParameter("c"));
              int a=1;
              int b=1;
              int c=1;
              if( in1!=0)
                                                 a=in1;
              if( in2!=0)
                 b=in2;
              if( in3!=0)
                 c=in3;
              Dimension size = getSize();
              int width = size.width;
              String msg = "Quadratic Equation: y = ax^2 + bx + c";
              Label bottom = new Label(msg);
              Label header = new Label("Quadratic Equation");
              setLayout(new BorderLayout());
              GraphCanvas canvas = new GraphCanvas(width,a,b,c);
              add(header,BorderLayout.NORTH);
              add(canvas,BorderLayout.CENTER);
              add(bottom,BorderLayout.SOUTH);
    }and here is the GraphCanvas class... which I can't figure out how to finish. hints and help would be appriciated:
    import java.awt.*;
    import java.applet.*;
    public class GraphCanvas extends Canvas
         private double density;
         private final int XMAX = 10;
         private final int XMIN = -10;
        private final int YMAX = 10;
         private final int YMIN = -10;
         private double x;
         private double y;
         public GraphCanvas(int dimension, double a, double b, double c)
             dimension = 20;
              density=dimension/(XMAX-XMIN)
              y=a*x^2+b*x+c;
         public void paint(Graphics g)
              drawGrid(g);
              graphQuadratic(g);
         public void drawGrid(Graphics g)
         public void graphQuadratic(Graphics g)
              for (x=-10;x<=10;x+=0.02)
                   y=x^2+x+1;
                   moveTo(x,y);
                   drawTo(g,x,y);
         public void moveto(double x, double y)
         public void drawto(double x, double y, Graphics g)
    }it;s mainly the drawTo and moveTo methods that i am haveing trouble getting my tired mind wrapped around.

    You may want to test the equation first, then save a "y-offset" value. Otherwise the images you draw may be off the canvas. Do this before drawing the scales (which I presume would appear in your drawGrid method), I'd suggest. Also use the offset when drawing the curve itself.
    it;s mainly the drawTo and moveTo methods that i am haveing trouble getting my tired mind
    wrapped around.Well, you're the one that wants to use them. What do you expect them to do?

  • Help With Simple Encryption Code

    I'm making a Cipher for personal use and possible publish as freeware. Can someone help me figure out what I'm missing in my code and/or post possible fixes? Thanks!
    P.S. If this code looks ametuer, it's because it is. I'm just a freshman in college :)
    Encryption Class:
    import java.util.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import java.security.*;
    public class EncryptionModule {
    static final int keylength = 42;
    private SecretKeySpec skeySpec;
    public EncryptionModule(String key)
    skeySpec = makeKey(key);
    public SecretKeySpec makeKey(String keys)
    SecretKeySpec skeySpec = null;
    try {
    byte [] keys_raw = keys.getBytes();
    skeySpec = new SecretKeySpec(keys_raw, "Blowfish");
    } catch(Exception e) {
    e.printStackTrace();
    return skeySpec;
    public String EncryptionModule(String line)
    byte[] encrypted = new byte[0];
    try {
    Cipher cipher = Cipher.getInstance("Blowfish");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
    encrypted = cipher.doFinal(line.getBytes());
    } catch(Exception e) {
    e.printStackTrace();
    return new String(encrypted);
    public String Decrypt(String line)
    byte[] decrypted = new byte[0];
    try {
    Cipher cipher = Cipher.getInstance("Blowfish");
    cipher.init(Cipher.DECRYPT_MODE,skeySpec);
    decrypted = cipher.doFinal(line.getBytes());
    } catch(Exception e) {
    e.printStackTrace();
    return new String(decrypted);
    File IO Class:
    import java.io.*;
    import java.awt.*;
    import java.util.*;
    public class FileIO
    BufferedReader inputFile;
    String inputFileName;
    BufferedWriter outputFile;
    String outputFileName;
    ArrayList dataList;
    ArrayList breakLine;
    EncryptionModule EncryptionModuleor;
    * Constructor for objects of class IO.
    public FileIO(String key)
    dataList = new ArrayList();
    breakLine = new ArrayList();
    EncryptionModuleor = new EncryptionModule(key);
    public void main(String[] args) throws IOException
    dataList = new ArrayList();
    breakLine = new ArrayList();
    setInputFile();
    * setInputFile - Displays a dialog box to select and open a file for input
    * @return true if success, false otherwise
    public boolean setInputFile() throws IOException
    boolean fileOpened = true;
    FileDialog myDB = new FileDialog(new Frame(),"Select a log file for INPUT");
    myDB.setDirectory(".");
    myDB.show();
    inputFileName = myDB.getFile();
    if (inputFileName==null){
    fileOpened = false;
    else {
    try {
    inputFile = new BufferedReader(new FileReader(myDB.getDirectory()+"\\"+inputFileName));
    catch(FileNotFoundException e) {
    fileOpened = false;
    return fileOpened;
    * setOutputFile - Displays a dialog box to select and open or create a file for output
    * @return true if success, false otherwise
    public boolean setOutputFile() throws IOException
    boolean fileOpened = true;
    FileDialog myDB = new FileDialog(new Frame(),"Select or create a file for OUTPUT");
    myDB.setDirectory(".");
    myDB.setMode(FileDialog.SAVE);
    myDB.show();
    outputFileName = myDB.getFile();
    if (outputFileName==null){
    fileOpened = false;
    else{
    try {
    outputFile = new BufferedWriter(new FileWriter(myDB.getDirectory()+"\\"+outputFileName));
    catch(FileNotFoundException e) {
    fileOpened = false;
    return fileOpened;
    public void processData()throws IOException
    dataList = new ArrayList();
    if (!setInputFile()){
    System.out.println("Cannot open selected input file: "+inputFileName);
    return;
    String line;
    line = inputFile.readLine(); //Read a new line from the input file
    EncryptionModuleor = new EncryptionModule(line);
    line = inputFile.readLine();
    while(line != null)
    dataList.add(EncryptionModuleor.EncryptionModule(line));
    line = inputFile.readLine(); //Read a new line from the input file
    copyFile();
    public void copyFile() throws IOException
    if (!setOutputFile()){
    System.out.println("Cannot open selected output file: "+outputFileName);
    return;
    for (int i=0; i<dataList.size(); i++){
    outputFile.write((String)dataList.get(i));
    if (i<dataList.size()-1){
    outputFile.newLine();
    outputFile.close();
    }

    You dont say what the problem is so one has to guess!
    1) " return new String(encrypted);"
    It is not realy safe to convert bytes to String this way. This must be close to the number 1 problem seen in this forum. Use something like Base64 or HEX encoding.
    2) Don't just catch exceptions and print out stack traces!
    If you intend to publish the encrytpion class then define an exception class specific to this problem (maybe more than one) and convert internal exceptions that you can't handle to this exception.
    3) You ave not defined a mode or padding and are relying on the default. Make it explicit so there is no argument as to what mode and padding is being used.
    4) For some reason you are breaking a file into lines and then encrypting each line. Why not just encrypt the whole file as bytes. Much easier, quicker, less code.
    5) Rather than use a GUI to select the file why not make them command line parameters using the standard UNIX/DOS approach.

  • Help with simple applet.

    Was given this applet by Cisco Tac,  waiting to hear from them as well;
    event manager applet capture_cpu_spike
    event snmp oid 1.3.6.1.4.1.9.2.1.56 get-type next entry-op ge entry-val 85 exit-time 600 poll-interval 1
    action 1.0 cli command "enable"
    action 1.1 syslog msg "CPU Utilization is high"   
    action 1.2 cli command "term exec prompt timestamp"
    action 1.3 cli command "sh proc cpu sorted | redirect flash:cpu_info.txt"
    action 1.4 cli command "show interface | redirect flash:interface_info.txt"
    action 1.5 cli command "term no exec prompt timestamp"
    action 1.6 syslog msg "CPU Utilization is Low"
    Probelm is that it creates the files on the flash;
    Directory of flash:/
        1  -rw-    55809628  Feb 22 2011 15:06:38 +00:00  c2800nm-advipservicesk9-mz.124-20.T.bin
        4  -rw-          31   May 8 2012 06:42:34 +00:00  cpu_info.txt
        3  -rw-          31   May 8 2012 06:42:36 +00:00  interface_info.txt
        2  -rw-         736  Feb 26 2010 10:11:24 +00:00  vlan.dat
    but when you check the contents of the files,  both say;
    JNJSILJ1RR2203#more cpu_info.txt
    Command authorization failed.
    What's up????
    Thanks

    Ok,  tried this butr am still getting same;
    username EEM privilege 15
    event manager session cli username EEM
    event manager applet capture_cpu_spike
    event snmp oid 1.3.6.1.4.1.9.2.1.56 get-type next entry-op ge entry-val 85 exit-time 600 poll-interval 1
    action 1.0 cli command "enable"
    action 1.1 syslog msg "CPU Utilization is high"   
    action 1.2 cli command "term exec prompt timestamp"
    action 1.3 cli command "sh proc cpu sorted | redirect flash:cpu_info.txt"
    action 1.4 cli command "show interface | redirect flash:interface_info.txt"
    action 1.5 cli command "term no exec prompt timestamp"
    action 1.6 syslog msg "CPU Utilization is Low"
    Just to be sure tried this also;
    username USER privilege 15
    event manager session cli username USER

  • Need help with a activation code for Adobe Acrobat X Standard for my PC,, Don't have older version serial numbers,  threw programs away,  only have Adobe Acrobat X Standard,  need a code to unlock program?

    Need help with a activation code for Adobe Acrobat X Standard for my PC, Don't have older Version of Adobe Acrobat 9, 8 or 7. 

    You don't need to install the older version, you only need the serial number from your original purchase. If you don't have them to hand, did you register? If so, they should be in your Adobe account. If not you really need to contact Adobe, though it isn't clear they will be able to do anything without some proof of purchase etc.

  • HT3209 Purchased DVD in US for Cdn viewing. Digital download will not work in Cda or US? please help with new Digital code that will work

    Purchased DVD in US for Cdn viewing. Digital download will not work in Cda or US? please help with new Digital code that will work

    You will need to contact the movie studio that produced the DVD and ask if they can issue you a new code valid for Canada. Apple cannot help you, and everyone here in these forums is just a fellow user.
    Regards.

  • Beginner needs help with simple code.

    I just statrted learnind java, and I need some help with this simple program. For some reason everytime I enter my Farenheit value, the Celsius conversion returns as 0.0. Would really appreciate the help. Thanks.
    Here's the code:
    public class TempConverter
    public static void main(String[] args)
    double F = Double.parseDouble(args[0]);
    System.out.println("Temperature in Farenheit is: " + F);
    double C = 5 / 9;
    C *= (F - 32);
    System.out.println("Temperature in Celsius is: " + C);
    }

    double C = 5 / 9This considers "5" and "9" to be integers and does an integer division, discarding the remainder. The result of that division is 0. Trydouble C = 5.0/9.0;

  • Need help with adjusting Javascript code to work in Adobe Edge (Countdown)

    Hello
    Im a newbie when it comes to working with Javascript and Adobe Edge and need a bit of help with adjusting some javascript code to work with Adobe Edge. A friend of mine helped me with making this javascript code: Edit fiddle - JSFiddle
    Its a simple countdown which counts down to a certain time at a certain date. What I aim to do is to add this code as a trigger on a text-element called "countdown" (within a symbol called "count").
    I have tried to do this as the code is, but it does not work. Anyone have any suggestions?
    Thanks!
    Mvh,
    Øyvind Hermans

    Hello again
    I have stumbled upon a problem with these animations; They crash the browser after viewing them a little while, usually less than 30 seconds in.
    Is this problem also occuring when you watch the animations?
    Is the countdown-code to much for the browsers to handle?
    Thanks in advance for your answers.
    Sincerely,
    Øyvind Hermans

  • Need help with advanced applet

    I need help with designing an applet as follows. Can someone give me a basic layout of code and material so i can fill in the rest or at leats give me some hints so i can get started since i am like no good at applets.
    Design and implement an applet that graphically displays the processing
    of a selection sort. Use bars of various heights to represent
    the values being sorted. Display the set of bars after each swap. Put
    a delay in the processing of the sort to give the human observer a
    chance to see how the order of the values changes.
    heres a website that does something similar
    http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html

    elasolova wrote:
    i will not help you this time. but if you buy me a candy maybe i can reconsider the issue. :PI suggest an all-day sucker.

  • Need help coding simple applet program

    Hello I'm attempting to learn applet programming in either swing or awt. Whichever is best for current applications. I want to begin by creating my first hello world application. I want to create a simple applet that has two buttons, press button number one and the text "hello world 1" comes up somewhere on the applet, press two and "hello world 2" comes up. can anyone help me with this simple applet? Thnx in advance

    http://java.sun.com/docs/books/tutorial/applet/

  • Help with simple script

    I was wondering if someone could help me with a simple bit of action script 3. I need to make a movie clip (single_mc) disappear when the user clicks on the mouse (stop_btn). Here’s what I have so far.
    function setProperty(event:MouseEvent):void
    single_mc.alpha=0;
    stop_btn.addEventListener(MouseEvent.CLICK, setProperty);
    Also I was wonder if you could recommend an Action script 3 book for me. I would like one that is not a training book, but has situations and then the script written out. For example: I click a button and a movie symbol disappears from the stage. I am a graphic artist, that from time to time, needs simple interaction in flash, but cant justify the time to learn the script.
    Thanks for your time

    use the snippets panel to help with you with sample code for basic tasks.
    function setProperty(event:MouseEvent):void
    single_mc.visible=false;
    stop_btn.addEventListener(MouseEvent.CLICK, setProperty);

  • Please help with simple Drag N Drop

    I’m desperate and need some help with this simple drag
    and drop. Here is the scenario…this animation is for a
    kindergarten course. I have 6 different colored teddy bears on the
    floor and the bears are to be placed on the middle shelf in the
    room, in no particular order. I have the code in place to drag the
    bears, and they return to their original location if dropped in the
    wrong area. Everything works, except I can’t make the bears
    stick to the target area. The target area has to be the same for
    all 6 bears. Can someone help me out with this?
    I have a feeling that the problem has something to do with my
    instance names, but I have tried everything I can think of and
    cannot get it to work. Is there some way I can post, send, or
    attach my .fla file for someone to look at? I’m desperate.
    PLEASE HELP!

    var startX3:Number;
    var startY3:Number;
    var counter3:Number=0;
    vf_A.addEventListener(MouseEvent.MOUSE_DOWN, pickUp3);
    vf_A.addEventListener(MouseEvent.MOUSE_UP, dropIt3);
    vf_E.addEventListener(MouseEvent.MOUSE_DOWN, pickUp3);
    vf_E.addEventListener(MouseEvent.MOUSE_UP, dropIt3);
    vf_I.addEventListener(MouseEvent.MOUSE_DOWN, pickUp3);
    vf_I.addEventListener(MouseEvent.MOUSE_UP, dropIt3);
    vf_O.addEventListener(MouseEvent.MOUSE_DOWN, pickUp3);
    vf_O.addEventListener(MouseEvent.MOUSE_UP, dropIt3);
    vf_U.addEventListener(MouseEvent.MOUSE_DOWN, pickUp3);
    vf_U.addEventListener(MouseEvent.MOUSE_UP, dropIt3);
    function pickUp3(event:MouseEvent):void {
    event.target.startDrag(true);
    reply2_txt.text="";
    event.target.parent.addChild(event.target);
    startX2=event.target.x;
    startY2=event.target.y;
    function dropIt3(event:MouseEvent):void {
    event.target.stopDrag();
    var myTargetName:String="target"+event.target.name;
    var myTarget:DisplayObject=getChildByName(myTargetName);
    if (event.target.dropTarget != null &&
    event.target.dropTarget.name == "instance112") {
    reply2_txt.text="Good Job!";
    event.target.removeEventListener(MouseEvent.MOUSE_DOWN,
    pickUp3);
    event.target.removeEventListener(MouseEvent.MOUSE_UP,
    dropIt3);
    event.target.buttonMode=false;
    event.target.x=myTarget.x;
    event.target.y=myTarget.y;
    var mySound:Sound = new vowels_NAR_goodjob();
    mySound.play();
    counter3++;
    } else {
    reply2_txt.text="Try Again!";
    event.target.x=startX2;
    event.target.y=startY2;
    var mySound2:Sound = new vowel_NAR_nopetryagain();
    mySound2.play();
    if (counter2==5) {
    reply2_txt.text="Great Job! You did it!";
    gotoAndPlay(3300);
    vf_A.buttonMode=true;
    vf_E.buttonMode=true;
    vf_I.buttonMode=true;
    vf_O.buttonMode=true;
    vf_U.buttonMode=true;

Maybe you are looking for