Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners problem with main

Have Programming Question? Ask it here!
 
 
 


brasidasaei
problem with main
1 Answer(s)      4 years and 5 months ago
Posted in : Java Beginners



import javax.swing.*;
import java.awt.*;

public class YellowFace extends JApplet
{
public static final int FACE_DIAMETER = 200;
public static final int X_FACE = 100;
public static final int Y_FACE = 50;

public static final int EYE_WIDTH = 10;
public static final int EYE_HEIGHT = 20;
public static final int X_RIGHT_EYE = 155;
public static final int Y_RIGHT_EYE = 95;
public static final int X_LEFT_EYE = 230;
public static final int Y_LEFT_EYE = Y_RIGHT_EYE;

public static final int NOSE_DIAMETER = 10;
public static final int X_NOSE = 195;//Center of nose will be at 200
public static final int Y_NOSE = 135;

public static final int MOUTH_WIDTH = 100;
public static final int MOUTH_HEIGHT = 50;
public static final int X_MOUTH = 150;
public static final int Y_MOUTH = 175;
public static final int MOUTH_START_ANGLE = 180;
public static final int MOUTH_DEGREES_SHOWN = 180;

public void paint(Graphics canvas)
{
//Draw face circle:
canvas.setColor(Color.YELLOW);
canvas.fillOval(X_FACE, Y_FACE, FACE_DIAMETER, FACE_DIAMETER);
canvas.setColor(Color.BLACK);
canvas.drawOval(X_FACE, Y_FACE, FACE_DIAMETER, FACE_DIAMETER);
//Draw eyes:
canvas.setColor(Color.BLUE);
canvas.fillOval(X_RIGHT_EYE, Y_RIGHT_EYE, EYE_WIDTH, EYE_HEIGHT);
canvas.fillOval(X_LEFT_EYE, Y_LEFT_EYE, EYE_WIDTH, EYE_HEIGHT);
//Draw nose:
canvas.setColor(Color.BLACK);
canvas.fillOval(X_NOSE, Y_NOSE, NOSE_DIAMETER, NOSE_DIAMETER);
//Draw mouth:
canvas.setColor(Color.RED);
canvas.drawArc(X_MOUTH, Y_MOUTH, MOUTH_WIDTH, MOUTH_HEIGHT,
MOUTH_START_ANGLE, MOUTH_DEGREES_SHOWN);
}
}

i have copied this code from a book and i have a problem. when i compile it appears this message:
java.lang.NoSuchMethodError: main
Exception in thread "main" .
Should i put a main in another file? And how can i call this class?Thx a lot










Advertisement
View Answers

March 3, 2010 at 10:42 AM


Hi Friend,

This is an applet code and applet doesn't have main method therefore compile it and run it with html file.

applet.html:

<html>
<body>
<h1>Java Applet Demo</h1>
<applet code=YellowFace.class width=500 height=400>
</applet>
</body>
</html>

Thanks


Related Tutorials/Questions & Answers:
problem with main - Java Beginners
a problem. when i compile it appears this message: java.lang.NoSuchMethodError: main Exception in thread "main" . Should i put a main in another file? And how can...problem with main   import javax.swing.*; import java.awt.
main method
main method  Why is the java main method static
Advertisements
main method
main method  What is the argument type of a program's main() method
main() method
main() method  Can we define two main() methods having same parameter but with different return type in a program
main function
main function  Give me the description of public static void main(Strings args
main method
main method  hello, Can I make multiple main methods in the same... can not make multiple main with in the same class program fails to compile. Compiler gives error that the main method is already defined in the class
MAin error
MAin error  Error while running hello program in another dir rather... but @ d tym of runnin error in main class is generated Exception in thread "main".java.lang.NoClassFoundDefLoader. : Hello caused
main method
main method  psvm(String args[]) what does this arguement in paranthesis denote?   Hi Friend, public-It indicates that the main() method can be called by any object. static-It indicates that the main() method
Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" java.lang.ClassCastException  I am trying...){e.printStackTrace();} } } public static void main(String[] argv) { try { Class driver..._jdbc.java:37:error:package org.postgresql doesnot exist can anyone solve this problem
Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" java.lang.ClassCastException  I am trying...){e.printStackTrace();} } } public static void main(String[] argv) { try { Class driver...:error:package org.postgresql doesnot exist can anyone solve this problem its
Main method overloading
Main method overloading  Can we overload main()method
why not float main?
why not float main?  why should the main be int or void?why cant it be float or char? why int main()?why not float main()?or char main
why not float main?
why not float main?  why should the main be int or void?why cant it be float or char? why int main()?why not float main()?or char main
Main memory is also known as
Main memory is also known as   Main memory of a computer is also known
JSON main question
JSON main question  What is the main purpose of JSON ,in which cases can i use
JSON main question
JSON main question  What is the main purpose of JSON ,in which cases can i use
Main job of cpu
Main job of cpu  What is the Main Job of CPU?   The CPU perform two main task .. 1. It carry out program instructions and also 2. Process the data and information
public static void main
public static void main  what is mean public static void main?   public-It indicates that the main() method can be called by any object. static-It indicates that the main() method is a class method. void- It indicates
What is the arguement of main method?
What is the arguement of main method?  hi, What is the arguement of main method? thanks,   Hi, For main() method accepts only an array of String object as arguement. For moe details on http://www.roseindia.net/java
Can a main method be overloaded?
Can a main method be overloaded?   Hi, Can a main method be overloaded? thanks,   Hi, Yes, In Java program we could having multiple number of main() methods with different Signature and implementation in the class
main func - Java Beginners
main func  why do we pass array of strings in main function of java?  Hi Friend, It is used to signify that the user may opt to enter parameters to the java program at command line. Thanks
main() syntax - Java Beginners
main() syntax  Hi, I would like to know the complete structure of the main() in jdk1.5 with sample program. Regards, UsmanAli Shaik,  ...] [import statements] [class declaration] [main() method] For Example: package
Problem
Problem  import java.io.*; import java.net.*; public class EchoClient { public static void main(String[] args) throws IOException { Socket echoSocket = null; PrintWriter out = null; BufferedReader
Main features of JSP technology
Main features of JSP technology  Main features of JSP technology ?    A language for developing JSP pages, which are text-based documents that describe how to process a request and construct a response. Constructs
problem
problem  import java.io.*; class ranveer { public static void main(String args[])throws IOException { BufferedReader in =new BufferedReader(new InputStreamReader(System.in)); int m=Integer.parseInt(in.readLine()); int n
Problem
Problem  import java.io.*; import java.net.*; public class EchoClient { public static void main(String[] args) throws IOException { Socket echoSocket = null; PrintWriter out = null; BufferedReader
Main function.. - Java Beginners
Main function..  Hi Friend.. public static void main(String args[]) What does it mean...public - static - void - main -(String args[]) Can u plz... return the value when it exits main(): This is the entry point for the application
What is the main feature of Hibernate3?
What is the main feature of Hibernate3?  What is the main feature of Hibernate3?   Hibernate 3.0, the latest Open Source persistence technology. Features of Hibernate Hibernate 3.0 provides three full-featured query
java main program
java main program  how to write a main program for the following code public class JaroWinkler { private String compOne; private String compTwo; private String theMatchA = ""; private String theMatchB
create main page
create main page  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="java.sql.*"%> <%@page import="java.util.*"%> <%@ page session="true
Main topics in java for IT corporate working?
Main topics in java for IT corporate working?  What are the main and most important topics in java should be mastered that are usually incorporated in IT corporate world
When is java main method called?
When is java main method called?  When is java main method called? Please explain the main method in Java with the help of code.   In a java class, main(..) method is the first method called by java environment when
What is the return type of the main method?
What is the return type of the main method?  hi, What is the return type of the main method? thanks   Hi, In the java programming the Main() method doesn't return anything hence declared void. In Java, you need
What if the main() method is declared as private?
What if the main() method is declared as private?  Hi, What if the main() method is declared as private? Thanks   Hi, I have found some reference site for java programming coding for Main() method is declared
Why is the main method declared static?
Why is the main method declared static?  Hi, Why is the main method declared static? thanks   Hi, When we declare main() method in any Java class always has the same signature, and we declare public static void main
Can a main method be declared final?
Can a main method be declared final?   Hi, Can a main method be declared final? Thanks   Hi, Yes we can. The final method can... be override in a subclass. for more about main method be declared final in Java
Main Thread and Child Thread
There are two types of threads in Java Progarm In Java there are Main and Child Threads used in Programming. Main thread is automatically created when program runs. Child Thread gets created by the main thread . Java Main
main function in java - Java Interview Questions
main function in java  1....why is function main() define as static in java? 2...drawbacks of using rmi
What are the main disadvantages of Java Server Faces 2.0?
What are the main disadvantages of Java Server Faces 2.0?  What are the main disadvantages of Java Server Faces 2.0
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... to be inputed as the rest is generated but the problem that i have found out that the program recquires a main() method in order to be runned - here is the following code
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... to be inputed as the rest is generated but the problem that i have found out that the program recquires a main() method in order to be runned - here is the following code
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... to be inputed as the rest is generated but the problem that i have found out that the program recquires a main() method in order to be runned - here is the following code
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... to be inputed as the rest is generated but the problem that i have found out that the program recquires a main() method in order to be runned - here is the following code
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... to be inputed as the rest is generated but the problem that i have found out that the program recquires a main() method in order to be runned - here is the following code
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... to be inputed as the rest is generated but the problem that i have found out that the program recquires a main() method in order to be runned - here is the following code
main function defnition in class - Java Beginners
main function defnition in class  why do we use public infront of a main function   Hi friend, The main method is similar to the main... and will subsequently invoke all the other methods required by your program. The main method
How to Differenciate Main Thread and Child Thread in Java
How to Differenciate Main Thread and Child Thread in Java  hi... Main Thread and Java Child Thread. Please Suggest any example or online link... in Java Programming Language. These are Java Main Thread and the Child Thread
Display Hello even before main get executed??
Display Hello even before main get executed??  I have a class (main method) as follow.....As I know this can be done using static method, but Q is how? **class Hello{ public static void main(String[] args
 

 

 

DMCA.com