Whats wrong with this java code

Graniti Bajraktari

main class

package other;

import javax.swing.JFrame;

public class Main {

    JFrameClass obj = new JFrameClass();
    obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    obj.setSize(275, 180);
    obj.setVisible(true);
}

my gui class

package other;

import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JFrame;

public class JFrameClass extends JFrame {

    // t1 -text 1 
    private JLabel t1;

    public JFrameClass(){

        super("Gui");
        setLayout(new FlowLayout());

        t1 = new JLabel("This is sentencw");
        t1.setToolTipText("HoverText");
        add(t1);

    }

}

i'm using eclipse and it si giving me a error for the setsize,setdefault...,setvisible methods i'm getting three or two errors in each one of them it says syntax error on token "," and like this

Daniel

You are writing statements directly into the class body. You should put your code in a method like this:

package other;

import javax.swing.JFrame;

public class Main {

  public static void main(String[] args){
    JFrameClass obj = new JFrameClass();
    obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    obj.setSize(275, 180);
    obj.setVisible(true);
 }
}

This should remove the errors. However, in my opinion you should put the commands within JFrameClass' constructor.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Whats wrong with the given Java Code

From Dev

javascript Whats wrong with this code

From Dev

Whats wrong in the following code?

From Dev

whats wrong with the android code ?

From Dev

Whats wrong with this glsl code?

From Dev

Whats wrong with this piece of code?

From Dev

Whats wrong with this JSP code

From Dev

Whats wrong with this C code lines

From Dev

Whats wrong with this code to read file?

From Dev

Whats wrong with this code? replace method

From Dev

Whats is wrong with this real mode code

From Dev

Whats wrong with this code to read file?

From Dev

Whats wrong with my jQuery code?

From Dev

Whats wrong with my php code?

From Dev

Whats wrong with this code? Objective C

From Dev

Whats wrong with this Jquery selector code?

From Dev

whats wrong with this code of reading with mmap?

From Dev

Whats wrong with my sql code

From Dev

whats is wrong in this basic method Java?

From Dev

Process finished with exit code 0 - whats wrong?

From Dev

whats wrong with my capitalize letters in words code?

From Dev

new to c, whats wrong with my code

From Dev

WHats wrong with this code for palindrome of a string array

From Dev

Whats wrong with this c code(linked list implementation)?

From Dev

Whats wrong with my jQuery Code for RadioButtonList

From Dev

Can someone look at my code and tell me whats wrong?

From Dev

Whats wrong in this code? im trying to make a login page

From Dev

Whats wrong with my code?(changing pictures using javascript)

From Dev

Can any body tell whats wrong with this code (New to python:()