How to complie

Discussion in 'Java' started by Odinn, Dec 4, 2006.

  1. Odinn

    Odinn Guest

    Greetings , I am a newbie java learner , stepped from basic C knowlage
    to java at my universty and sadly due to I was sick I missed the latest
    course . I am seeking explaining about what this small program do and
    how to complie it. When I try to complie it at terminal i am getting
    "no suitable method `main' in class
    " error. As far as I understood it looks like it will show some
    graphics and it is some kind of javaapplet.

    Here is the code:
    import java.awt.*;
    import javax.swing.*;

    public class PointArrayApplet extends JApplet
    {
    public void paint(Graphics g)
    {
    Point [] triangle;
    triangle=new Point[3];
    triangle[0]=new Point(10,20);
    triangle[1]=new Point(35,90);
    triangle[2]=new Point(75,105);
    g.drawString(triangle[0].toString(),10,20);
    g.drawString(triangle[1].toString(),35,90);
    g.drawString(triangle[2].toString(),75,105);
    translate(triangle,100,200);
    g.drawString(triangle[0].toString(),110,220);
    g.drawString(triangle[1].toString(),135,290);
    g.drawString(triangle[2].toString(),175,305);
    }
    public static void translate(Point []points,int deltaX,int deltaY)
    {
    for(int i=0;i<points.length;i++)
    points.translate(deltaX,deltaY);
    }
    }

    Thanks in advance.
    Odinn, Dec 4, 2006
    #1
    1. Advertising

  2. Odinn

    Oliver Wong Guest

    "Odinn" <> wrote in message
    news:...
    > Greetings , I am a newbie java learner , stepped from basic C knowlage
    > to java at my universty and sadly due to I was sick I missed the latest
    > course . I am seeking explaining about what this small program do and
    > how to complie it. When I try to complie it at terminal i am getting
    > "no suitable method `main' in class
    > " error.


    You compile a java program using "javac", and one of the ways to run the
    program is using "java". If you get the error message "no suitable method
    'main' in class", it means you've already compiled the program and are now
    trying to run it.

    > As far as I understood it looks like it will show some
    > graphics and it is some kind of javaapplet.
    >
    > Here is the code:
    > import java.awt.*;
    > import javax.swing.*;
    >
    > public class PointArrayApplet extends JApplet
    > {
    > public void paint(Graphics g)
    > {
    > Point [] triangle;
    > triangle=new Point[3];
    > triangle[0]=new Point(10,20);
    > triangle[1]=new Point(35,90);
    > triangle[2]=new Point(75,105);
    > g.drawString(triangle[0].toString(),10,20);
    > g.drawString(triangle[1].toString(),35,90);
    > g.drawString(triangle[2].toString(),75,105);
    > translate(triangle,100,200);
    > g.drawString(triangle[0].toString(),110,220);
    > g.drawString(triangle[1].toString(),135,290);
    > g.drawString(triangle[2].toString(),175,305);
    > }
    > public static void translate(Point []points,int deltaX,int deltaY)
    > {
    > for(int i=0;i<points.length;i++)
    > points.translate(deltaX,deltaY);
    > }
    > }
    >
    > Thanks in advance.


    The program you have here is an applet, as you've noted. The "java"
    command can be used to run stand-alone java programs, but not applets. To
    run the applet, you either need to embed it in an HTML page and view it
    using your webbrowser, or use the "appletviewer" program.

    - Oliver
    Oliver Wong, Dec 4, 2006
    #2
    1. Advertising

  3. "Odinn" <> wrote in message
    news:...
    > Greetings , I am a newbie java learner , stepped from basic C knowlage
    > to java at my universty and sadly due to I was sick I missed the latest
    > course . I am seeking explaining about what this small program do and
    > how to complie it. When I try to complie it at terminal i am getting
    > "no suitable method `main' in class


    the compiler should never make such a complaint.
    Perhaps you mean that the error occurs when you try
    to execute it?

    > " error. As far as I understood it looks like it will show some
    > graphics and it is some kind of javaapplet.
    >
    > Here is the code:
    > import java.awt.*;
    > import javax.swing.*;
    >
    > public class PointArrayApplet extends JApplet
    > {
    > public void paint(Graphics g)
    > {
    > Point [] triangle;
    > triangle=new Point[3];
    > triangle[0]=new Point(10,20);
    > triangle[1]=new Point(35,90);
    > triangle[2]=new Point(75,105);
    > g.drawString(triangle[0].toString(),10,20);
    > g.drawString(triangle[1].toString(),35,90);
    > g.drawString(triangle[2].toString(),75,105);
    > translate(triangle,100,200);
    > g.drawString(triangle[0].toString(),110,220);
    > g.drawString(triangle[1].toString(),135,290);
    > g.drawString(triangle[2].toString(),175,305);
    > }
    > public static void translate(Point []points,int deltaX,int deltaY)
    > {
    > for(int i=0;i<points.length;i++)
    > points.translate(deltaX,deltaY);
    > }
    > }
    >
    > Thanks in advance.
    >

    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Technical Architect, Software Reuse Project
    Fred Kleinschmidt, Dec 4, 2006
    #3
  4. Odinn

    Odinn Guest

    Thanks alot for the answers. Now I got it :)
    Oliver Wong yazdi:
    > "Odinn" <> wrote in message
    > news:...
    > > Greetings , I am a newbie java learner , stepped from basic C knowlage
    > > to java at my universty and sadly due to I was sick I missed the latest
    > > course . I am seeking explaining about what this small program do and
    > > how to complie it. When I try to complie it at terminal i am getting
    > > "no suitable method `main' in class
    > > " error.

    >
    > You compile a java program using "javac", and one of the ways to run the
    > program is using "java". If you get the error message "no suitable method
    > 'main' in class", it means you've already compiled the program and are now
    > trying to run it.
    >
    > > As far as I understood it looks like it will show some
    > > graphics and it is some kind of javaapplet.
    > >
    > > Here is the code:
    > > import java.awt.*;
    > > import javax.swing.*;
    > >
    > > public class PointArrayApplet extends JApplet
    > > {
    > > public void paint(Graphics g)
    > > {
    > > Point [] triangle;
    > > triangle=new Point[3];
    > > triangle[0]=new Point(10,20);
    > > triangle[1]=new Point(35,90);
    > > triangle[2]=new Point(75,105);
    > > g.drawString(triangle[0].toString(),10,20);
    > > g.drawString(triangle[1].toString(),35,90);
    > > g.drawString(triangle[2].toString(),75,105);
    > > translate(triangle,100,200);
    > > g.drawString(triangle[0].toString(),110,220);
    > > g.drawString(triangle[1].toString(),135,290);
    > > g.drawString(triangle[2].toString(),175,305);
    > > }
    > > public static void translate(Point []points,int deltaX,int deltaY)
    > > {
    > > for(int i=0;i<points.length;i++)
    > > points.translate(deltaX,deltaY);
    > > }
    > > }
    > >
    > > Thanks in advance.

    >
    > The program you have here is an applet, as you've noted. The "java"
    > command can be used to run stand-alone java programs, but not applets. To
    > run the applet, you either need to embed it in an HTML page and view it
    > using your webbrowser, or use the "appletviewer" program.
    >
    > - Oliver
    Odinn, Dec 5, 2006
    #4
  5. Odinn wrote:

    Sorry - only just noticed this thread..

    > Greetings , I am a newbie java learner ,

    .....
    > public class PointArrayApplet extends JApplet


    Noobs and applets are a bad combination, as
    applets are much harder to debug and deploy than
    applications.

    I noted (trimmed) the part re C++ experience and
    am guessing you feel you are beyond the advice to
    'start with command line applications only', however I
    do recommend writing a few simple little CLI based
    apps. - even to check a new Java installation..

    I think you should put any GUI stuff aside for
    the moment. Especially when the information
    on which you are basing this code has not made
    clear that ..

    > {
    > public void paint(Graphics g)


    ...Swing (the 'J'Applet above) components should
    overide paintComponent(), rather than paint().

    Andrew T.
    Andrew Thompson, Dec 5, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. krigare
    Replies:
    0
    Views:
    838
    krigare
    Dec 27, 2003
  2. =?Utf-8?B?Sm9obiBCYW5raGVhZA==?=

    Failed Complie due to locked DLL

    =?Utf-8?B?Sm9obiBCYW5raGVhZA==?=, Dec 30, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,967
    =?Utf-8?B?Q2hpbm1heQ==?=
    Jan 4, 2005
  3. SAI

    complie cs file

    SAI, Jul 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    519
    =?Utf-8?B?Q2Ft?=
    Jul 10, 2005
  4. Yet another C# coder

    Complie ASP.NET 2.0 to Single DLL

    Yet another C# coder, Oct 12, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    521
    Juan T. Llibre
    Oct 12, 2005
  5. Benny Ng
    Replies:
    4
    Views:
    1,354
    Otis Mukinfus
    Feb 4, 2006
Loading...

Share This Page