Results 1 to 6 of 6

Thread: Help!

  1. #1
    Join Date
    Dec 2011
    Posts
    212
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Help!

    Hello guys,what's up?
    I have been trying to draw something in java,but it says me that i dont have a main type or something like that ....
    Here is the code,what should i do?

    code:
    package asd;

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


    @SuppressWarnings("serial")
    public class Lama extends JFrame {
    public void run{




    public void paint( Graphics g )
    {


    Graphics2D to = ( Graphics2D ) g;


    to.setPaint( new GradientPaint( 5, 30, Color.BLUE, 35, 100,
    Color.YELLOW, true ) );
    to.fill( new Ellipse2D.Double( 5, 30, 65, 100 ) );
    to.getColor();


    }
    }
    }

  2. #2
    Join Date
    May 2008
    Location
    Mental Hospital
    Posts
    414
    Mentioned
    4 Post(s)
    Quoted
    42 Post(s)

    Default

    You need to have a main method.

    Code:
      public static void main(String[] args)  
        {
    Also, when asking for help it is always helpful to post a screenshot of the error, or copy the exact text of the error, not just "it was something or other."

    Cheers,
    Noob King
    Last edited by Noob King; 05-27-2012 at 08:30 AM.

  3. #3
    Join Date
    Dec 2011
    Posts
    212
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks!But i dont know how could i put that on the code as it show me the line in red.
    Here is the code:
    Code:




    package YO;

    import javax.swing.JFrame;
    import javax.swing.JLabel;

    import java.awt.*;
    import java.awt.geom.*;


    @SuppressWarnings("serial")
    public class Lama extends JFrame {







    public void paint( Graphics g )
    {



    JLabel gaston= new JLabel("gaston");

    add(gaston);
    }



    }

    Here is the error:


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

  4. #4
    Join Date
    Apr 2007
    Posts
    581
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    Try this

    Code:
    package asd;
    
    import javax.swing.JFrame;
    import java.awt.*;
    import java.awt.geom.*;
    
    
    @SuppressWarnings("serial")
    public class Lama extends JFrame {
    
    public Lama() {
    	super("My JFrame");
    	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	setSize(300, 300);
    	setVisible(true);
    }
    
    public static void main(String[] args) {
    	new Lama();
    }
    
    
    
    public void paint( Graphics g )
    {
    	super.paint(g);
    
    Graphics2D to = ( Graphics2D ) g;
    
    
    to.setPaint( new GradientPaint( 5, 30, Color.BLUE, 35, 100, 
    Color.YELLOW, true ) ); 
    to.fill( new Ellipse2D.Double( 5, 30, 65, 100 ) );
    to.getColor();
    
    
    }
    
    }

  5. #5
    Join Date
    Dec 2011
    Posts
    212
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by ShawnjohnSJ View Post
    Try this

    Code:
    package asd;
    
    import javax.swing.JFrame;
    import java.awt.*;
    import java.awt.geom.*;
    
    
    @SuppressWarnings("serial")
    public class Lama extends JFrame {
    
    public Lama() {
    	super("My JFrame");
    	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	setSize(300, 300);
    	setVisible(true);
    }
    
    public static void main(String[] args) {
    	new Lama();
    }
    
    
    
    public void paint( Graphics g )
    {
    	super.paint(g);
    
    Graphics2D to = ( Graphics2D ) g;
    
    
    to.setPaint( new GradientPaint( 5, 30, Color.BLUE, 35, 100, 
    Color.YELLOW, true ) ); 
    to.fill( new Ellipse2D.Double( 5, 30, 65, 100 ) );
    to.getColor();
    
    
    }
    
    }
    Thanks!!

  6. #6
    Join Date
    Apr 2007
    Posts
    581
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    No problem, just make sure you indent your code to make it more readable. If you don't mind downloading a program, I would suggest using the Eclipse IDE if you aren't already - it automatically indents code for you.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •