Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.BoxLayout;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JPasswordField;
- import javax.swing.JRootPane;
- import javax.swing.JTextField;
- import javax.swing.SwingConstants;
- public class Interface extends JFrame implements ActionListener {
- private Container contentPane;
- private JPanel buttonPanel, userPanel;
- private JButton loginButton, createUserButton, logoutButton, withdrawButton, depositButton, switchToRegisterButton, switchToLoginButton;
- private JLabel headerLabel, inputTopJTFLabel, inputPW1JPFLabel, toastLabel, inputPW2JPFLabel;
- public JTextField inputTopJTF;
- public JPasswordField inputPW1JPF, inputPW2JPF;
- JRootPane rootPane;
- public Interface(int width, int height, String title) {
- //Setting up Interface
- setTitle(title);
- setSize(width, height);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLocation(100,100);
- Font header = new Font("TimesRoman", Font.PLAIN, 50);
- ///////////////////////BUTTON PANEL///////////////////////
- //Button Panel
- buttonPanel = new JPanel();
- //Buttons
- //loginButton
- loginButton = new JButton("Login");
- loginButton.addActionListener(this);
- loginButton.setAlignmentX(Component.CENTER_ALIGNMENT);
- //switchToRegisterButton
- switchToRegisterButton = new JButton("New User?");
- switchToRegisterButton.addActionListener(this);
- switchToRegisterButton.setAlignmentX(Component.CENTER_ALIGNMENT);
- //switchToLoginButton
- switchToLoginButton = new JButton("Switch to Login");
- switchToLoginButton.addActionListener(this);
- switchToLoginButton.setAlignmentX(Component.CENTER_ALIGNMENT);
- switchToLoginButton.setVisible(false);
- //createUserButton
- createUserButton = new JButton("Register");
- createUserButton.addActionListener(this);
- createUserButton.setAlignmentX(Component.CENTER_ALIGNMENT);
- createUserButton.setVisible(false);
- //logoutButton
- logoutButton = new JButton("Logout");
- logoutButton.addActionListener(this);
- logoutButton.setAlignmentX(Component.CENTER_ALIGNMENT);
- logoutButton.setVisible(false);
- //withdrawButton
- withdrawButton = new JButton("Withdraw");
- withdrawButton.addActionListener(this);
- withdrawButton.setAlignmentX(Component.CENTER_ALIGNMENT);
- withdrawButton.setVisible(false);
- //depositButton
- depositButton = new JButton("Deposit");
- depositButton.addActionListener(this);
- depositButton.setAlignmentX(Component.CENTER_ALIGNMENT);
- depositButton.setVisible(false);
- //Adding items to buttonPanel
- buttonPanel.add(loginButton);
- buttonPanel.add(switchToRegisterButton);
- buttonPanel.add(switchToLoginButton);
- buttonPanel.add(createUserButton);
- buttonPanel.add(logoutButton);
- buttonPanel.add(withdrawButton);
- buttonPanel.add(depositButton);
- ///////////////BODY PANEL//////////////////////
- //Body Panel
- userPanel = new JPanel();
- userPanel.setLayout(new BoxLayout(userPanel, BoxLayout.PAGE_AXIS));
- //JTextFields
- //inputTopJTF
- Dimension inputTopJTFDimension = new Dimension(100, 20);
- inputTopJTF = new JTextField();
- inputTopJTF.setMaximumSize(inputTopJTFDimension);
- //inputPW1JPF
- Dimension inputPW1JPFDimension = new Dimension(100, 20);
- inputPW1JPF = new JPasswordField();
- inputPW1JPF.setMaximumSize(inputPW1JPFDimension);
- //inputPW2JPF
- Dimension inputPW2JPFDimension = new Dimension(100, 20);
- inputPW2JPF = new JPasswordField();
- inputPW2JPF.setMaximumSize(inputPW2JPFDimension);
- inputPW2JPF.setVisible(false);
- //JLabels
- //toastLabel
- toastLabel = new JLabel("Please sign in or create new account.");
- toastLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
- //inputTopJTFLabel
- inputTopJTFLabel = new JLabel("Username:");
- inputTopJTFLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
- //inputPW1JPFLabel
- inputPW1JPFLabel = new JLabel("Password:");
- inputPW1JPFLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
- //inputPW2JPFLabel
- inputPW2JPFLabel = new JLabel("Confirm Password:");
- inputPW2JPFLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
- inputPW2JPFLabel.setVisible(false);
- //Adding items to userPanel
- userPanel.add(toastLabel);
- userPanel.add(inputTopJTFLabel);
- userPanel.add(inputTopJTF);
- userPanel.add(inputPW1JPFLabel);
- userPanel.add(inputPW1JPF);
- userPanel.add(inputPW2JPFLabel);
- userPanel.add(inputPW2JPF);
- ///////////////CONTENT PANE/////////////////////
- //Content Pane
- contentPane = getContentPane();
- //JLabels
- //headerLabel
- headerLabel = new JLabel("Bank", SwingConstants.CENTER);
- headerLabel.setFont(header);
- //PAGE_START
- contentPane.add(headerLabel, BorderLayout.PAGE_START);
- //LINE_START
- //CENTER
- contentPane.add(userPanel, BorderLayout.CENTER);
- //LINE_END
- //PAGE_END
- contentPane.add(buttonPanel, BorderLayout.PAGE_END);
- userPanel.setFocusable(true);
- userPanel.requestFocus();
- //Default Button
- rootPane = getRootPane();
- rootPane.setDefaultButton(loginButton);
- setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- System.out.println("hi");
- }
- public static void main(String[] args) {
- new Interface(500, 400, "hii");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement