0

I'm making a Caesar Cipher program, and I'm trying to change the GUI. I've tried adding a background image (from the comments provided by the user(s) below), but now, nothing shows up (the background image, text boxes, and buttons don't display and I just get a blank window when I run the program). Any help is appreciated!

 public CaesarGUI() throws IOException {
    setTitle("Caesar Cipher");
    setVisible(true);
    setDefaultCloseOperation(3);
    pack();
    setSize(1400, 990);

    BufferedImage bg = ImageIO.read(Menu.class.getResource("beach.jpg"));
    JLabel label = new JLabel(new ImageIcon(bg));
    setContentPane(label);

    Container content = getContentPane();

    //Changed rows to 0 so it would be filled up before recalculating layout; achieves the horizontal layout
    GridLayout layout = new GridLayout(0, 2, 100, 5);
    content.setLayout(layout);

    inputTA = new JTextArea("Put the word you want to encrypt or decrypt and press the button", 12, 40);
    inputTA.setLineWrap(true);
    inputTA.setWrapStyleWord(true);
    inputTA.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    JScrollPane scroller = new JScrollPane(inputTA);
    scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    content.add(scroller);

    outputTA = new JTextArea(12, 40);
    outputTA.setLineWrap(true);
    outputTA.setWrapStyleWord(true);
    outputTA.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

    //Made output box uneditable so that it only displays output
    outputTA.setEditable(false);

    JScrollPane scroller2 = new JScrollPane(outputTA);
    scroller2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    content.add(scroller2);

    JPanel box1 = new JPanel();
    box1.setLayout(new FlowLayout());
    JButton decryptButton = new JButton("Decrypt");
    JButton encryptButton = new JButton("Encrypt");
    decryptButton.addActionListener(this);
    encryptButton.addActionListener(this);
    box1.add(decryptButton);
    box1.add(encryptButton);
    box1.add(new JLabel("Shift Factor"));
    box1.add(this.shiftFactor = new JTextField(20));
    content.add(box1);

    setResizable(false);
    //pack();
}
Artjom B.
  • 61,146
  • 24
  • 125
  • 222

0 Answers0