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
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.
Comments