You never create an instance of the Project9 class, so the only four lines that run are those in main that create an empty JFrame.
Change:
JFrame frame = new JFrame();
To:
JFrame frame = new Project9();
题
I coded a application so far so it only shows the widgets so I can see if everything is in order before I add Action Listeners and such.
The problem is when I run it, nothing shows up at all, just a blank screen.
I attached a picture of what the layout should look like. I am new to this website so apparently I cannot post any images until 10 rep. Here is a link to PhotoBucket.
http://i930.photobucket.com/albums/ad149/Wolverino5/pic_zpsa4599592.png
Here is my code so far.
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);
}
}
解决方案
You never create an instance of the Project9 class, so the only four lines that run are those in main that create an empty JFrame.
Change:
JFrame frame = new JFrame();
To:
JFrame frame = new Project9();