到目前为止,我编写了一个应用程序,因此它只显示了小部件,因此在添加Action Listener等之前,我可以看到是否一切正常。
问题是当我运行它时,根本没有任何显示,只是一个空白屏幕。
我附上了布局应该是什么样子的图片。我是这个网站的新手所以显然我不能发布任何图像,直到10个代表。这是PhotoBucket的链接。
http://i930.photobucket.com/albums/ad149/Wolverino5/pic_zpsa4599592.png
到目前为止,这是我的代码。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Project9 extends JFrame
{
private JTextField idLabel;
private JTextField idField;
private JTextField priceLabel;
private JTextField priceField;
private JTextField numInStockLabel;
private JTextField numInStockField;
private JTextField codeLabel;
private JTextField codeField;
private JTextField transaction;
private JButton insert;
private JButton delete;
private JButton display;
private JButton displayOne;
private JButton hide;
private JButton clear;
private Container c = getContentPane();
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(650,700);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public Project9()
{
setTitle("BOOK DataBase Application");
c.setLayout(new FlowLayout());
Label main = new Label("Data Entry: Best Bargian Book Store");
c.add(main);
idLabel = new JTextField("Enter ID",15);
idLabel.setEditable(false);
c.add(idLabel);
idField = new JTextField();
c.add(idField);
priceLabel = new JTextField("Enter Price:",15);
priceLabel.setEditable(false);
c.add(priceLabel);
priceField = new JTextField();
c.add(priceField);
numInStockLabel = new JTextField("Enter Number In Stock:",15);
numInStockLabel.setEditable(false);
c.add(numInStockLabel);
numInStockField = new JTextField();
c.add(numInStockField);
codeLabel = new JTextField("Enter Code: 1,2,3 or 4:",15);
codeLabel.setEditable(false);
c.add(codeLabel);
codeField = new JTextField();
c.add(codeField);
insert = new JButton("Insert");
c.add(insert);
delete = new JButton("Delete");
c.add(delete);
display = new JButton("Display");
c.add(display);
displayOne = new JButton("displayOne");
c.add(displayOne);
hide = new JButton("Hide");
c.add(hide);
clear = new JButton("Clear");
c.add(clear);
Label messages = new Label ("Messages");
c.add(messages);
transaction = new JTextField();
c.add(transaction);
}
}
答案 0 :(得分:0)
您永远不会创建Project9类的实例,因此只运行的四行是main中创建空JFrame的行。
变化:
JFrame frame = new JFrame();
要:
JFrame frame = new Project9();