LOGIN_GUI
unknown
java
5 months ago
4.9 kB
4
Indexable
import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; public class LoginPage { public static void main(String[] args) { JFrame frame = new JFrame("Hardware POS Management System"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 300); frame.setLocationRelativeTo(null); frame.setLayout(new BorderLayout()); // <NAV> JPanel nav = new JPanel(); nav.setPreferredSize(new Dimension(0,40)); nav.setBackground(new Color(44, 62, 80)); nav.setLayout(new BorderLayout()); nav.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0,Color.white)); JLabel titleLabel = new JLabel("Account Login", SwingConstants.CENTER); titleLabel.setForeground(new Color(236, 240, 241)); titleLabel.setFont(new Font("Verdana", Font.BOLD, 20)); titleLabel.setHorizontalAlignment(SwingConstants.CENTER); nav.add(titleLabel, BorderLayout.CENTER); // </NAV> // <CENTERPAGE> JPanel centerPanel = new JPanel(); centerPanel.setLayout(new GridLayout(5,1,0,5)); centerPanel.setBorder(new EmptyBorder(0,80,0,80)); centerPanel.setBackground(new Color(149, 165, 166)); JLabel username = new JLabel("Username:"); username.setHorizontalAlignment(SwingConstants.CENTER); username.setFont(new Font("Verdana",Font.BOLD,15)); JTextField usernameTextField = new JTextField(); usernameTextField.setHorizontalAlignment(SwingConstants.CENTER); usernameTextField.setBorder(new RoundedBorder(10)); JLabel password = new JLabel("Password:"); password.setHorizontalAlignment(SwingConstants.CENTER); password.setFont(new Font("Verdana",Font.BOLD,15)); JPasswordField passwordField = new JPasswordField(); passwordField.setHorizontalAlignment(SwingConstants.CENTER); passwordField.setBorder(new RoundedBorder(10)); JButton login = new JButton("Login"); login.setBorder(new RoundedBorder(5)); login.setFont(new Font("Verdana",Font.BOLD,14)); login.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String username = usernameTextField.getText(); char[] password = passwordField.getPassword(); if (username.equals("admin") && String.valueOf(password).equals("password")) { JOptionPane.showMessageDialog(frame, "Login Successful!"); Dashboard.showNextFrame(); } else { JOptionPane.showMessageDialog(frame, "Incorrect Username or Password"); } } }); JPanel loginButton = new JPanel(new FlowLayout(FlowLayout.CENTER)); loginButton.add(login); loginButton.setBackground(new Color(149, 165, 166)); centerPanel.add(username); centerPanel.add(usernameTextField); centerPanel.add(password); centerPanel.add(passwordField); centerPanel.add(loginButton); // </CENTERPAGE> // <bottom> JPanel bottomPanel = new JPanel(); bottomPanel.setBackground(new Color(44, 62, 80)); bottomPanel.setPreferredSize(new Dimension(0,30)); bottomPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0,Color.white)); JLabel bottomTitle = new JLabel("Point of Sale System Management @2024", SwingConstants.CENTER); bottomTitle.setForeground(new Color(255, 255, 255)); bottomPanel.add(bottomTitle); // </bottom> frame.add(nav,BorderLayout.NORTH); frame.add(centerPanel,BorderLayout.CENTER); frame.add(bottomPanel,BorderLayout.SOUTH); frame.setVisible(true); } } class RoundedBorder implements Border { private int radius; public RoundedBorder(int radius) { this.radius = radius; } @Override public Insets getBorderInsets(Component c) { return new Insets(5, 5, 5, 5); // Define padding inside the border } @Override public boolean isBorderOpaque() { return true; // Border will be opaque } @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Set border color g2d.setColor(Color.BLACK); // Draw the rounded rectangle border g2d.drawRoundRect(x, y, width - 1, height - 1, radius, radius); } }
Editor is loading...
Leave a Comment