Search code examples
javaswingjpaneljtextfield

Blank JPanel after adding a JTextField


Working on adding a GUI to my simple craps simulation program.

Made a new JPanel and added a few JTextFields to it with a default text value. I get no error, and the code runs, but all I get is a blank window with nothing in it.

Here is the code:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class CrapsGUI extends JFrame
{
   JPanel jp = new JPanel();
   JLabel jl = new JLabel();
   JTextField die1 = new JTextField("Die 1",30);
   JTextField die2 = new JTextField("Die 2",30);
   JTextField sum = new JTextField("Sum",30);
   JTextField point = new JTextField("Point",30);
   JTextField status = new JTextField("Status",30);

   public CrapsGUI()
   {
      setTitle("Craps Simulator 2013");
      setVisible(true);
      setSize(400, 200);
      setDefaultCloseOperation(EXIT_ON_CLOSE);

      jp.add(die1);
      jp.add(die2);
      jp.add(sum);
      jp.add(point);
      jp.add(status);
   }

   public static void main(String[] args)
   {
      Craps craps = new Craps();

      CrapsGUI crapsGUI = new CrapsGUI();
   }
}

Thanks in advance!


Solution

  • You haven't added the JPanel that contains the visible components.

    add(jp);