My components are not showing up. How do I fix this?
Code:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener
window.setVisible(true); should be invoked only after all the components have been added to the frame.
void logini() throws IOException {
JFrame window = new JFrame("Login");
JPanel mainp = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
window.add(mainp);
BufferedImage myPicture = ImageIO.read(new File("c:\\bgd.png"));
JLabel picLabel = new JLabel(new ImageIcon( myPicture ));
mainp.add(picLabel, c);
c.gridx = 0;
c.gridy = 1;
gusername = new JTextField();
gusername.setText("Username");
mainp.add(gusername, c);
c.gridx = 0;
c.gridy = 2;
gpassword = new JTextField();
gpassword.setText(" password ");
mainp.add(gpassword, c);
c.gridx = 0;
c.gridy = 3;
JButton login = new JButton("Login");
mainp.add(login, c);
login.addActionListener(this);
login.setActionCommand("ok");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(500, 250);
window.setResizable(false);
window.setVisible(true);
}