ContentPanel issue, The content panel is not showing up on the second window when I enter the information

19 Views Asked by At

This program takes user input for courses and outputs the best possible course that they should research for their post-secondary options. The issue is basically when I Fill in this information in the surveyFrame which is functional I know that, Program name: Actuarial Science Institution: University of Waterloo Faculty: Faculty of Math Program Duration (years): 4 Guidline: 88 Tuition Fee ($): 123456

Then a new frame should open with three panels that show each course that is related to their input.

All I need help with is that the panels don't show up and the contentPanel Panel objects are all throwing errors.

/* Note: https://stackoverflow.com/questions/27209669/getting-paintcomponent-
 * elements-of-a-jpanel-to-work-with-another-jpanel-inside-o: used from line 48 to 50
 */

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.ImageIcon;

public class ResultJFrame extends JFrame implements ActionListener {
    JButton backButton;
    JPanel buttonPanel;
    JLabel header;
    JPanel headerPanel;
    JPanel tempPanel;
    JLabel options;
    JPanel optionsPanel;
    Box optionsBox1;
    JPanel contentPanel;
    BufferedImage img;
    
    ResultJFrame() {
        setTitle("Results");
        setSize(1000, 625);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setResizable(false);
        
        try {
            img = ImageIO.read(new File("images/background.png"));

            contentPanel = new JPanel(new BorderLayout()) {
                public void paintComponent(Graphics g) {
                    super.paintComponent(g);
                    g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
                }
            };
            
            header = new JLabel("Recommended Programs");
            header.setFont(new Font("Canva Sans", Font.BOLD, 30));
            header.setForeground(Color.WHITE);

            headerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
            headerPanel.setOpaque(false);
            headerPanel.add(header);
            contentPanel.add(headerPanel, BorderLayout.NORTH);

            tempPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
            options = new JLabel("Option 1                        Option 2" +
                    "                        Option 3");
            options.setFont(new Font("Canva Sans", Font.BOLD, 30));
            options.setForeground(Color.WHITE);
            tempPanel.add(options);
            tempPanel.setOpaque(false);
            tempPanel.setBounds(-15, 60, 1000, 200);
            contentPanel.add(tempPanel);
            
            optionsBox1 = Box.createVerticalBox();
            optionsBox1.add(Box.createVerticalStrut(10));

            optionsPanel = new JPanel();
            optionsPanel.setOpaque(false);
            optionsPanel.add(optionsBox1);
            contentPanel.add(optionsPanel, BorderLayout.CENTER);

            backButton = new JButton("Go Back");
            backButton.setForeground(Color.WHITE);
            backButton.setBackground(new Color(0, 21, 79));
            backButton.setFocusable(false);
            backButton.addActionListener(this);
            backButton.setFont(new Font("Canva Sans", Font.BOLD, 30));

            buttonPanel = new JPanel();
            buttonPanel.setLayout(null);
            backButton.setBounds(397, 460, 180, 60);
            backButton.setBackground(new Color(0, 21, 79));
            buttonPanel.setOpaque(false);
            buttonPanel.add(backButton);
            contentPanel.add(buttonPanel);

            setContentPane(contentPanel);
            
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public static void Actuarial(int option) {
        JPanel options = new JPanel();
        options.setBounds(10, 10, 100, 100);
        options.setBackground(Color.RED);
        add(options);
        
        JPanel backPlate1 = new JPanel();
        backPlate1.setLayout(null);
        backPlate1.setBounds(74, 120, 200, 370);
        backPlate1.setBackground(new Color(1, 28, 102));
        backPlate1.setPreferredSize(new Dimension(200, 350));
        contentPanel.add(backPlate1);
        backPlate1.setVisible(true);
                        
        JPanel backPlate2 = new JPanel();
        backPlate2.setLayout(null);
        backPlate2.setBounds(387, 120, 200, 370);
        backPlate2.setBackground(new Color(1, 28, 102));
        backPlate2.setPreferredSize(new Dimension(200, 350));
        contentPanel.add(backPlate2);
        backPlate2.setVisible(true);
              
        JPanel backPlate3 = new JPanel();
        backPlate3.setLayout(null);
        backPlate3.setBounds(697, 120, 200, 370);
        backPlate3.setBackground(new Color(1, 28, 102));
        backPlate3.setPreferredSize(new Dimension(200, 350));
        contentPanel.add(backPlate3);
        backPlate3.setVisible(true);
            
        contentPanel.add(backPlate1);
        contentPanel.add(backPlate2);
        contentPanel.add(backPlate3);
    }
    
    public void actionPerformed(ActionEvent event) {
        if (event.getSource() == backButton) {
            this.dispose();
            TitleFrame titleFrame = new TitleFrame();
            titleFrame.getClass();
            //go back to title frame
        }
    }

    public static void ComputationalMathematics(int i) {
        
    }
}

Expecting 3 panels with the courses.

0

There are 0 best solutions below