i think theres something wrong with my computer, im trying to create a GUI for my program but it wont display my JLabels (which contain images)
i downloaded a program with a GUI i made at the computer lab in my university which works there, but on my laptop it doesnt display any JLabels either. Can someone run these codes for me to check if the error is in my code or with my computer?
Heres the code with the main method and JFrame:
import java.awt.*;
import javax.swing.*;
class TestHomeController
{
public static void main(String[] args)
{
// Creates the JFrame
JFrame myWindow = new JFrame("Home Controller");
// Set the default close operation of the JFrame object to dispose
myWindow.setDefaultCloseOperation(3);
// Instance the standalone class containing the components
HomeController Remote1 = new HomeController();
// Add intermediate level container to top level container
myWindow.add(Remote1,BorderLayout.CENTER);
// Displays the window.
myWindow.pack();
myWindow.setVisible(true);
}// end of main method
}// end of class
and heres the code with the GUI components:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class HomeController extends JPanel
{
ImageIcon blank = new ImageIcon("blank.jpg");
JLabel Appliance1 = new JLabel(blank);
JLabel Appliance2 = new JLabel(blank);
JLabel Appliance3 = new JLabel(blank);
JLabel Appliance4 = new JLabel(blank);
JLabel Appliance5 = new JLabel(blank);
JLabel Appliance6 = new JLabel(blank);
JLabel Appliance7 = new JLabel(blank);
JLabel Appliance8 = new JLabel(blank);
JLabel Appliance9 = new JLabel(blank);
HomeController()
{
this.setLayout(new BorderLayout());
JPanel Panel1 = new JPanel();
JPanel Panel2 = new JPanel();
JPanel Panel3 = new JPanel();
Appliance1.setOpaque(true);
Panel1.add(Appliance1,BorderLayout.WEST);
Appliance2.setOpaque(true);
Panel1.add(Appliance2,BorderLayout.CENTER);
Appliance3.setOpaque(true);
Panel1.add(Appliance3,BorderLayout.EAST);
Appliance4.setOpaque(true);
Panel2.add(Appliance4,BorderLayout.WEST);
Appliance5.setOpaque(true);
Panel2.add(Appliance5,BorderLayout.CENTER);
Appliance6.setOpaque(true);
Panel2.add(Appliance6,BorderLayout.EAST);
Appliance7.setOpaque(true);
Panel3.add(Appliance7,BorderLayout.WEST);
Appliance8.setOpaque(true);
Panel3.add(Appliance8,BorderLayout.CENTER);
Appliance9.setOpaque(true);
Panel3.add(Appliance9,BorderLayout.EAST);
}
}
NOTE: when run it should display a three by three grid containing blank images.(you will need to create an image called blank for it to work)