I am doing a GUI interface. When i am creating an object i am getting an error message can anyone see what i have forgotten to do ? The error message is in the MainApp under the comment Building an object for subClass. Thanks in advance.
I have made a mistake of putting class(class is a keyword in java) in the constructor:
public class subClass()
{
class was then removed to prevent the error occurring.
//Imports.
//MainApp.
import javax.swing.JFrame;
public class MainApp
{
public static void main(String[] args)
{
//Building an object for subClass.
subClass class = new subClass();
class.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
class.setSize(275,275);
class.setVisible(true);
}
}
//Imports.
//subclass.
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
//
public class subClass extends JFrame
{
private JLabel item1;
//
public subClass()
{
// Sets the Title of the window.
super("Title");
// Sets the layout of the window. FlowLayout is the default layout.
setLayout(new FlowLayout());
item1 = new JLabel("This is a sentence.");
item1.setToolTipText("This is going to show up on hover.");
add(item1);
}
classis a Java keyword. You can’t use it as an identifier.