Can anybody figure out what is wrong with the following code. I don't see the labels and textfields I expected to see. Thank you.
import java.awt.*;
import javax.swing.*;
public class PracticeApp {
public static void main(String[] args)
{
JFrame SalesF = new JFrame(); //SalesFrame();
SalesF.setVisible(true);
}
}
class SalesFrame extends JFrame
{
public SalesFrame()
{
setTitle("Sales");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(new SalesPanel());
this.pack();
centerWindow(this);
}
private void centerWindow(Window w)
{
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
setLocation((d.width-w.getWidth())/2, (d.height-w.getHeight())/2);
}
}
class SalesPanel extends JPanel
{
JPanel sPanel = new JPanel();
private JLabel prompt1Label, prompt2Label; //prompt3Label, prompt4Label;
public JTextField prompt1TextField, prompt2TextField, prompt3TextField;
public SalesPanel()
{
// add panels
setLayout(new GridBagLayout());
prompt1Label = new JLabel("Enter ISBN");
add(prompt1Label, getConstraints(0,0,1,1, GridBagConstraints.EAST));
prompt1TextField = new JTextField(10);
prompt1TextField.setEditable(true);
prompt1TextField.setFocusable(false);
add(prompt1TextField, getConstraints(1,0,1,1, GridBagConstraints.WEST));
prompt2Label = new JLabel("Enter Title");
add(prompt2Label, getConstraints(0,1,1,1, GridBagConstraints.EAST));
prompt1TextField = new JTextField(10);
prompt1TextField.setEditable(false);
prompt1TextField.setFocusable(false);
add(prompt2TextField, getConstraints(1,1,1,1, GridBagConstraints.WEST));
prompt3TextField = new JTextField(10);
prompt3TextField.setEditable(false);
prompt3TextField.setFocusable(false);
add(prompt3TextField, getConstraints(1,2,2,4, GridBagConstraints.WEST));
}
private GridBagConstraints getConstraints(int gridx, int gridy,
int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5, 5, 5, 5);
c.ipadx = 0;
c.ipady = 0;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.anchor = anchor;
return c;
}
}

