StartPanel.java (2131B)
1 /* 2 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 */ 5 package com.groupproject.tictactoeclient.ContentPanes; 6 7 import com.groupproject.tictactoeclient.TicTacToeClient; 8 import java.awt.event.ActionEvent; 9 import java.awt.event.ActionListener; 10 import javax.swing.JButton; 11 import javax.swing.JPanel; 12 import javax.swing.SpringLayout; 13 14 /** 15 * 16 * @author Adam 17 */ 18 public class StartPanel extends CustomPanel { 19 20 public StartPanel(TicTacToeClient client) { 21 22 // Set panel layout to spring layout 23 SpringLayout layout = new SpringLayout(); 24 setLayout(layout); 25 26 //Create the 2 buttons login and register 27 JButton loginButton = new JButton("Login"); 28 JButton registerButton = new JButton("Register"); 29 30 //Add the Buttons to the panel 31 add(loginButton); 32 add(registerButton); 33 34 //Login Button constraints 35 layout.putConstraint(SpringLayout.HORIZONTAL_CENTER, loginButton, -60, SpringLayout.HORIZONTAL_CENTER, this); 36 layout.putConstraint(SpringLayout.VERTICAL_CENTER, loginButton, 0, SpringLayout.VERTICAL_CENTER, this); 37 38 //Register Button constraints 39 layout.putConstraint(SpringLayout.WEST, registerButton, 10, SpringLayout.EAST, loginButton); 40 layout.putConstraint(SpringLayout.VERTICAL_CENTER, registerButton, 0, SpringLayout.VERTICAL_CENTER, this); 41 42 //Login Button Action - go to login page 43 loginButton.addActionListener(new ActionListener() { 44 @Override 45 public void actionPerformed(ActionEvent e) { 46 client.showPanel(new login(client)); 47 } 48 }); 49 50 //Register Button Action - go to the register page 51 registerButton.addActionListener(new ActionListener() { 52 @Override 53 public void actionPerformed(ActionEvent e) { 54 client.showPanel(new register(client)); 55 } 56 }); 57 } 58 59 @Override 60 public void refresh() { 61 // not needed. 62 } 63 }