Netbeans没有显示UI

时间:2014-02-27 06:50:28

标签: user-interface

我在netbeans中运行它并且它没有显示任何内容。有谁知道为什么netbeans没有显示用户界面?是因为我使用的是空的java文件吗?我的代码如下。我是netbeans和java的新手,所以任何帮助都将不胜感激。

import java.awt.*;
import javax.swing.*;

class UserInterface extends javax.swing.JFrame {
    public UserInterface() {
    setTitle("My First UI");
    setLayout(null);
    setBounds(10,10,400,600);
    Container con = getContentPane();

    JLabel lblCustomerName = new JLabel("Customer Name");
    JTextField txtCustomerName = new JTextField();
    JButton btnOkay =  new JButton("Okay");

    lblCustomerName.setBounds(20,20,100,20);
    txtCustomerName.setBounds(125,20,100,20);
    btnOkay.setBounds(20,300,80,60);

    con.add(lblCustomerName);
    con.add(txtCustomerName);
    con.add(btnOkay);
    con.setVisible(true);
    }
}

class Tester {
public static void main(String[] args) {
    new UserInterface();
    }
}

1 个答案:

答案 0 :(得分:0)

您的java代码无法显示您的框架。

请在Tester.class中设置:

class Tester {
  public static void main(String[] args) {
      UserInterface ui = new UserInterface();
      ui.setVisible(true);
  }
}

您可以从UserInterface.class中删除con.setVisible(true);