[英]JFrame/JLabel issues
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class gui extends JFrame{
private static final long serialVersionUID = 1L;
private JLabel item1;
public void createGUI(){
setTitle("Window Title");
setLayout(new FlowLayout());
item1 = new JLabel("This is a sentence.");
item1.setToolTipText("This is a tip...");
add(item1);
}
import javax.swing.JFrame;
public static void main(String[] args) throws Exception{
gui guiObj = new gui();
guiObj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
guiObj.setSize(300,300);
guiObj.setVisible(true);
}
The window's title isn't being applied and the label isn't showing up. 窗口的标题未应用,标签未显示。 I'm not sure why... Does anyone see something I might have overlooked? 我不确定为什么...有人看到我可能忽略了的东西吗?
You never call createGUI
您永远不会调用createGUI
gui guiObj = new gui();
guiObj.createGUI();
It would be better to use the gui
constructor 最好使用gui
构造函数
You need to call createGUI()
. 您需要调用createGUI()
。 That' where everything is initialized 那就是一切初始化的地方
gui guiObj = new gui();
guiObj.createGUI();
Also please follow Java naming convention. 另外,请遵循Java命名约定。 Class names should begin with capital letters ie 班级名称应以大写字母开头,即
gui
→ Gui
gui
→ Gui
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.