我剛開始爲一個任務開發一個小GUI,但啓動它時除了標題外沒有任何東西可見。JFrame中沒有顯示內容
我的代碼:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Property extends JFrame
{
/*private String propertyType;
private String propertyAddress;
private double propertyArea;
private int numOfBedrooms;
private int numOfGarages;
private int numOfToilets;
private String ownerGivenName;
private String ownerSurname;
private String ownerdateOfBirth;*/
JButton PropertySaleButton = new JButton("Add New Property");
JButton PurchaseOfferButton = new JButton("Submit Purchase Offer");
public Property()
{
setLayout (new FlowLayout());
add(PropertySaleButton);
add(PurchaseOfferButton);
}
public static void main(String[] args)
{
EventQueue.invokeLater(() ->
{
JFrame frame = new JFrame("CQ Real Estate");
/*Image img = new ImageIcon("icon.gif").getImage();
setIconImage(img);*/
frame.setSize(450, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
});
}
}
如果有人能告訴我什麼我缺少這將不勝感激。
你只創建一個空'JFrame',你不創建一個'Property'實例。至少使用'JFrame frame = new Property();'。 (已添加爲答案) – AxelH
您未調用'new Property()' –