Hello everyone, Ive been trying to add an image into a program ive been working on.
Im new to working with GUIs so this is all a bit confusing. When i run it all i see is the black box i created. Any advice? Also i have the image saved in the same location as the .java and .class file because i wasnt sure which it had to be with.
Im new to working with GUIs so this is all a bit confusing. When i run it all i see is the black box i created. Any advice? Also i have the image saved in the same location as the .java and .class file because i wasnt sure which it had to be with.
import java.awt.*; import javax.swing.*; public class SplashScreen { public static void main(String[]args){ JFrame frame = new JFrame ("DNA Trait Predictions"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); JPanel primary = new JPanel(); primary.setBackground(Color.black); primary.setPreferredSize(new Dimension(1000,500)); ImageIcon icon = new ImageIcon("DNA.jpg"); JLabel dna = new JLabel("True Source Code",icon,SwingConstants.CENTER); JPanel panel = new JPanel(); panel.setBackground(Color.black); panel.setPreferredSize(new Dimension(200,200)); frame.add(dna); frame.getContentPane().add(primary); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } }