为什么没有显示在我的Java GUI? [英] Why is nothing showing up in my Java GUI?
问题描述
我目前工作的一个计算器。现在,我试图获得与编码的Java GUI,通过一个简单的程序,使一个窗口的文本字段的经验。在code可以编译没有错误,但是当我执行程序时,出现的窗口中,但没有文本字段。怎样使文本字段可见?在code如下所示:
进口的javax.swing *。
进口java.awt中的*。
公共类窗口{
公共静态无效的主要(字串[] args){
JFrame的窗口=新的JFrame(窗口);
Window.setSize(400550);
Window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
的JPanel面板=新JPanel(新的FlowLayout());
JTextField的文本字段=新的JTextField(在此处键入的东西);
Window.setVisible(真);
}
}
您还没有添加任何部件到你的JFrame。您可以添加他们像这样:
Panel.add(文本字段);
Window.add(面板);
Window.setVisible(真);
边注:您应该坚持的 Java的命名约定的。使用变量名骆驼。
I am currently working on a calculator. Right now, I am trying to gain experience with coding Java GUI, by making a simple program that makes a window with a text field. The code can compile without errors, but when I execute the program, the window appears, but without the text field. How do I make the text field visible? The code is shown as follows:
import javax.swing.*;
import java.awt.*;
public class Window {
public static void main(String[] args) {
JFrame Window = new JFrame("Window");
Window.setSize(400,550);
Window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel Panel = new JPanel (new FlowLayout());
JTextField TextField = new JTextField("Type something here");
Window.setVisible(true);
}
}
You haven't added any of the components to your JFrame. You can add them like so:
Panel.add(TextField);
Window.add(Panel);
Window.setVisible(true);
Side note: You should stick to the Java naming conventions. Use camel case for variable names.
这篇关于为什么没有显示在我的Java GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!