Advertisement
Guest User

Interface Issue

a guest
Dec 17th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.81 KB | None | 0 0
  1. public class Interface extends JFrame implements ActionListener {
  2.    
  3.     private Container contentPane;
  4.    
  5.     private JPanel buttonPanel, userPanel;
  6.    
  7.     private JButton loginButton, createUserButton, logoutButton, withdrawButton, depositButton, switchToRegisterButton, switchToLoginButton;
  8.    
  9.     private JLabel headerLabel, inputTopJTFLabel, inputPW1JPFLabel, toastLabel, inputPW2JPFLabel;
  10.    
  11.     public JTextField inputTopJTF;
  12.     public JPasswordField inputPW1JPF, inputPW2JPF;
  13.    
  14.     JRootPane rootPane;
  15.  
  16.     public Interface(int width, int height, String title) {
  17.        
  18.         //Setting up Interface
  19.         setTitle(title);
  20.         setSize(width, height);
  21.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  22.         setLocation(100,100);
  23.         setVisible(true);
  24.            
  25.         Font header = new Font("TimesRoman", Font.PLAIN, 50);
  26.        
  27.         ///////////////////////BUTTON PANEL///////////////////////
  28.        
  29.         //Button Panel
  30.         buttonPanel = new JPanel();
  31.        
  32.         //Buttons
  33.         //loginButton
  34.         loginButton = new JButton("Login");
  35.         loginButton.addActionListener(this);
  36.         loginButton.setAlignmentX(Component.CENTER_ALIGNMENT);
  37.        
  38.         //switchToRegisterButton
  39.         switchToRegisterButton = new JButton("New User?");
  40.         switchToRegisterButton.addActionListener(this);
  41.         switchToRegisterButton.setAlignmentX(Component.CENTER_ALIGNMENT);
  42.        
  43.         //switchToLoginButton
  44.         switchToLoginButton = new JButton("Switch to Login");
  45.         switchToLoginButton.addActionListener(this);
  46.         switchToLoginButton.setAlignmentX(Component.CENTER_ALIGNMENT);
  47.         switchToLoginButton.setVisible(false);
  48.        
  49.         //createUserButton
  50.         createUserButton = new JButton("Register");
  51.         createUserButton.addActionListener(this);
  52.         createUserButton.setAlignmentX(Component.CENTER_ALIGNMENT);
  53.         createUserButton.setVisible(false);
  54.  
  55.         //logoutButton
  56.         logoutButton = new JButton("Logout");
  57.         logoutButton.addActionListener(this);
  58.         logoutButton.setAlignmentX(Component.CENTER_ALIGNMENT);
  59.         logoutButton.setVisible(false);
  60.        
  61.         //withdrawButton
  62.         withdrawButton = new JButton("Withdraw");
  63.         withdrawButton.addActionListener(this);
  64.         withdrawButton.setAlignmentX(Component.CENTER_ALIGNMENT);
  65.         withdrawButton.setVisible(false);
  66.        
  67.         //depositButton
  68.         depositButton = new JButton("Deposit");
  69.         depositButton.addActionListener(this);
  70.         depositButton.setAlignmentX(Component.CENTER_ALIGNMENT);
  71.         depositButton.setVisible(false);
  72.        
  73.         //Adding items to buttonPanel
  74.         buttonPanel.add(loginButton);
  75.         buttonPanel.add(switchToRegisterButton);
  76.         buttonPanel.add(switchToLoginButton);
  77.         buttonPanel.add(createUserButton);
  78.         buttonPanel.add(logoutButton);
  79.         buttonPanel.add(withdrawButton);
  80.         buttonPanel.add(depositButton);
  81.        
  82.         ///////////////BODY PANEL//////////////////////
  83.        
  84.         //Body Panel
  85.         userPanel = new JPanel();
  86.         userPanel.setLayout(new BoxLayout(userPanel, BoxLayout.PAGE_AXIS));
  87.        
  88.         //JTextFields
  89.         //inputTopJTF
  90.         Dimension inputTopJTFDimension = new Dimension(100, 20);
  91.         inputTopJTF = new JTextField();
  92.         inputTopJTF.setMaximumSize(inputTopJTFDimension);
  93.        
  94.         //inputPW1JPF
  95.         Dimension inputPW1JPFDimension = new Dimension(100, 20);
  96.         inputPW1JPF = new JPasswordField();
  97.         inputPW1JPF.setMaximumSize(inputPW1JPFDimension);
  98.        
  99.         //inputPW2JPF
  100.         Dimension inputPW2JPFDimension = new Dimension(100, 20);
  101.         inputPW2JPF = new JPasswordField();
  102.         inputPW2JPF.setMaximumSize(inputPW2JPFDimension);
  103.         inputPW2JPF.setVisible(false);
  104.        
  105.         //JLabels
  106.         //toastLabel
  107.         toastLabel = new JLabel("Please sign in or create new account.");
  108.         toastLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
  109.        
  110.         //inputTopJTFLabel
  111.         inputTopJTFLabel = new JLabel("Username:");
  112.         inputTopJTFLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
  113.        
  114.         //inputPW1JPFLabel
  115.         inputPW1JPFLabel = new JLabel("Password:");
  116.         inputPW1JPFLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
  117.        
  118.         //inputPW2JPFLabel
  119.         inputPW2JPFLabel = new JLabel("Confirm Password:");
  120.         inputPW2JPFLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
  121.         inputPW2JPFLabel.setVisible(false);
  122.        
  123.         //Adding items to userPanel
  124.         userPanel.add(toastLabel);
  125.         userPanel.add(inputTopJTFLabel);
  126.         userPanel.add(inputTopJTF);
  127.         userPanel.add(inputPW1JPFLabel);
  128.         userPanel.add(inputPW1JPF);
  129.         userPanel.add(inputPW2JPFLabel);
  130.         userPanel.add(inputPW2JPF);
  131.        
  132. ///////////////CONTENT PANE/////////////////////
  133.        
  134.     //Content Pane
  135.     contentPane = getContentPane();
  136.    
  137.     //JLabels
  138.     //headerLabel
  139.     headerLabel = new JLabel("Bank", SwingConstants.CENTER);
  140.     headerLabel.setFont(header);
  141.    
  142.     //PAGE_START
  143.     contentPane.add(headerLabel, BorderLayout.PAGE_START);
  144.    
  145.     //LINE_START
  146.    
  147.     //CENTER
  148.     contentPane.add(userPanel, BorderLayout.CENTER);
  149.    
  150.     //LINE_END
  151.    
  152.     //PAGE_END
  153.     contentPane.add(buttonPanel, BorderLayout.PAGE_END);
  154.    
  155.     userPanel.setFocusable(true);
  156.     userPanel.requestFocus();
  157.    
  158.     //Default Button
  159.     rootPane = getRootPane();
  160.     rootPane.setDefaultButton(loginButton);
  161.        
  162.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement