aspose file tools*
The moose likes Beginning Java and the fly likes ColorText Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ColorText" Watch "ColorText" New topic


DB Ekanayake

Joined: Apr 07, 2008
Posts: 8

I got Following codes form a Java Tut.
They compiled without any errors.But when I try to run the program it Produced the following error.

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

Can any one spend your valuable time to solve this matter



import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;

public class ColorText extends Canvas{

public void paint(Graphics g){
Font font;

font=new Font("Arial",Font.ITALIC | Font.BOLD,18);
g.drawString("Arial 18 point bold italic red",10,20);

Color mycolor =new Color(0,255,0);
font=new Font("Times new Roman",Font.BOLD,22);
g.drawString("Times new Roman 22 point plain green",10,40);

g.setColor(new Color(0,0,255));
font=new Font("Monospaced",Font.BOLD,20);
g.drawString("Monospaced 20 point plain blue",10,60);
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39576
This code is not a standalone program - it's an AWT component. It can be used by embedding it in a Frame or some other kind of AWT container. To run it, the class would also need a main method, as the error message mentions.

Ping & DNS - updated with new look and Ping home screen widget
It is sorta covered in the JavaRanch Style Guide.
subject: ColorText
Similar Threads
java database applet with Internet Explorer
java database applet with Internet Explorer
How do i apply font styles and sizes to a string ?
java database applet with Internet Explorer
Create Bar Chart