package screens;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class LoginGUI extends JFrame implements ActionListener, ItemListener
{
//Global Variables
private JTextField uName, pWord;
private JButton enter, cancel;
private JRadioButton sale, admin;
private JLabel title;
private Font font = new Font("Trebuchet MS", Font.BOLD, 20);;
private ButtonGroup options;
private GridBagLayout layout;
private GridBagConstraints gbc;
public LoginGUI()
{
setSize(800,400);
setTitle("Login");
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//setBorder(BorderFactory.createTitledBorder("Header"));
layout = new GridBagLayout();
setLayout(layout);
gbc = new GridBagConstraints();
//GUI Components
// User Type Line
addComponent(new JLabel("User Type:"), 0,0,2,1);
sale = new JRadioButton("Sale Staff", true);
admin = new JRadioButton("Admin", false);
options = new ButtonGroup(); //Grouping Buttons
options.add(sale);
options.add(admin);
sale.addItemListener(this);
admin.addItemListener(this);
addComponent(sale,2,0,1,1);
addComponent(admin,3,0,1,1);
//Username Line
addComponent(new JLabel("Username:"),0,1,2,1);
uName = new JTextField();
addComponent(uName,2,1,2,1);
//Password Line
addComponent(new JLabel("Password:"),0,2,2,1);
pWord = new JTextField();
addComponent(pWord,2,2,2,1);
//Buttons
enter = new JButton("Enter");
enter.addActionListener(this);
cancel = new JButton("Cancel");
cancel.addActionListener(this);
addComponent(enter,2,3,1,1);
addComponent(cancel,3,3,1,1);
this.setVisible(true); //Sets visibility when object is created
}
//Method to add a component to GridBagLayout
public void addComponent(Component c, int gx, int gy, int gw, int gh)
{
c.setFont(font);
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.insets = new Insets(5,5,5,5);
gbc.fill = GridBagConstraints.HORIZONTAL;
add(c, gbc);
}
@Override
public void actionPerformed(ActionEvent arg0)
{
// TODO Auto-generated method stub
}
@Override
public void itemStateChanged(ItemEvent arg0)
{
// TODO Auto-generated method stub
}
public static void main(String[] args)
{
LoginGUI gui = new LoginGUI();
}
}