Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

imageobserver runtime error

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

// This applet displays a single image twice,
// once at its normal size and once much wider.

public class ImageDisplayer extends JApplet {

static String imageFile = "D:/vijay_dreams/JavaExamples/pegeon.gif";

public void init() {
Image image = getImage(getCodeBase(), imageFile);
ImagePanel imagePanel = new ImagePanel(image);
getContentPane().add(imagePanel, BorderLayout.CENTER);
}
}

class ImagePanel extends JPanel {


Image image;

public ImagePanel(Image image) {

this.image = image;
}

public void paintComponent(Graphics g) {
super.paintComponent(g); // Paint background

// Draw image at its natural size first.
g.drawImage(image, 0, 0, this); //85x62 image

// Now draw the image scaled.
g.drawImage(image, 90, 0, 300, 62, this);
}
}

**************************************
The above pgm gives me and runtime error as,

/* Exception in thread "main" java.lang.NoSuchMethodError: main */

can anyone explain why?


Thanks and Regards,
viji.
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you trying to run this? Applets are referenced in an applet tag inside of an HTML page. They can't be run from the command line via the "java" command.

Note that applets do not have access to the local file system, so you will have to sign it, or fiddle with the local security policy.

If you want to run this applet as an application, check out the MainFrame class.
[ December 28, 2006: Message edited by: Ulf Dittmer ]
 
Water! People swim in water! Even tiny ads swim in water:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic