SRL Archive - General

Help!


Gaston7eze

2012-05-26 08:49:07

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();


}
}
}

Noob King

2012-05-26 14:45:36

You need to have a main method.

  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

Gaston7eze

2012-05-26 15:14:30

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"

ShawnjohnSJ

2012-05-26 21:41:12

Try this


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();


}

}

Gaston7eze

2012-05-27 08:19:11

From: ShawnjohnSJ
Try this


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!!

ShawnjohnSJ

2012-05-27 16:23:11

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.