Error in calling JFrame's super.
Hi, I'm new here, and I'm trying to learn how to properly use JFrame and some other graphical coding using Java. My problem right now is that my book suggested a code that keep giving me an error when compiling. The error I get from the code below says "call to super must be first statement in constructor.", yet I don't see what I did wrong. Would you all be kind enough to help me solve this please?
Code Java:
import javax.swing.*;
import java.awt.*;
public class ProjectOneJFrame extends JFrame
{
public void JFrameDemo()
{
super("JFrameDemo");
setSize(400,400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, 400, 400);
g.setColor(Color.orange);
g.setFont(new Font("Arial", Font.BOLD, 18));
g.drawString("Doing graphics with a JFrame!", 60, 200);
}
public static void main (String[] args)
{
new JFrameDemo();
}
}
Also, I would appriciate it if anyone notes any other errors in my coding.(Just so you know, I use BlueJ and NetBeans to code my programs.)
Re: Error in calling JFrame's super.
The message "call to super must be first statement in constructor" means what it says: you can only call super() as the first line of a constructor. But you have "super("JFrameDemo");" as the first line of a method. I know it's a method (and so does the compiler) because it returns void, and has a name that is not the same as that of the class.
Re: Error in calling JFrame's super.
-_- Thank you very much. I feel stupid now, lol. I fixed my coding so that it was the same name as the class, and changed the line in the main method and it worked. Thank you for helping me solve that, I don't think I'll forget about this now.
Re: Error in calling JFrame's super.