• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ColorText

 
DB Ekanayake
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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

Thanks

DB



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

public class ColorText extends Canvas{
ColorText(){
setSize(400,120);
setBackground(Color.pink);
}

public void paint(Graphics g){
Font font;

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

Color mycolor =new Color(0,255,0);
g.setColor(mycolor);
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic