...
Clase SignIn, para el registro de jugadores:
package starwarsbattleship;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
/**
*
* @author r2montero
*/
public class SignIn extends javax.swing.JFrame {
//private boolean addToExisting = true;
/**
* Creates new form SignIn
*/
public SignIn() {
initComponents();
setTitle("Registro de Jugadores");
setIconImage(new ImageIcon(getClass().getResource("/images/deathstarico.png")).getImage());
((JPanel) getContentPane()).setOpaque(false);
ImageIcon milleniumwindow = new ImageIcon(this.getClass().getResource("/images/falconwindow.jpg"));
JLabel background = new JLabel();
background.setIcon(milleniumwindow);
getLayeredPane().add(background, JLayeredPane.FRAME_CONTENT_LAYER);
background.setBounds(0, 0, milleniumwindow.getIconWidth(), milleniumwindow.getIconHeight());
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frame = getSize();
setLocation((screen.width - frame.width) / 2,(screen.height - frame.height) / 2);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
namelbl = new javax.swing.JLabel();
nicknamelbl = new javax.swing.JLabel();
passwordlbl = new javax.swing.JLabel();
nametxt = new javax.swing.JTextField();
nicknametxt = new javax.swing.JTextField();
passwordtxt = new javax.swing.JPasswordField();
passrptlbl = new javax.swing.JLabel();
passtxt = new javax.swing.JPasswordField();
accept = new javax.swing.JButton();
cancel = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
namelbl.setFont(new java.awt.Font("Star Jedi Logo DoubleLine2", 0, 14)); // NOI18N
namelbl.setForeground(java.awt.Color.yellow);
namelbl.setText("Nombre del Piloto");
nicknamelbl.setFont(new java.awt.Font("Star Jedi Logo DoubleLine2", 0, 14)); // NOI18N
nicknamelbl.setForeground(java.awt.Color.yellow);
nicknamelbl.setText("Nickname");
passwordlbl.setFont(new java.awt.Font("Star Jedi Logo DoubleLine2", 0, 14)); // NOI18N
passwordlbl.setForeground(java.awt.Color.yellow);
passwordlbl.setText("Contraseña");
passrptlbl.setFont(new java.awt.Font("Star Jedi Logo DoubleLine2", 0, 13)); // NOI18N
passrptlbl.setForeground(java.awt.Color.yellow);
passrptlbl.setText("Repita la Contraseña");
accept.setText("Aceptar");
accept.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acceptActionPerformed(evt);
}
});
cancel.setText("Cancelar");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(84, 84, 84)
.addComponent(accept, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(passrptlbl)
.addComponent(passwordlbl)
.addComponent(nicknamelbl)
.addComponent(namelbl))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(nametxt, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(nicknametxt, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(passwordtxt, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(passtxt, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))))))
.addContainerGap(22, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(namelbl)
.addComponent(nametxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(13, 13, 13)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(nicknamelbl)
.addComponent(nicknametxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(passwordlbl)
.addComponent(passwordtxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(passrptlbl)
.addComponent(passtxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(61, 61, 61)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(accept)
.addComponent(cancel))
.addContainerGap(30, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void acceptActionPerformed(java.awt.event.ActionEvent evt) {
String pName = nametxt.getText();
String pNick = nicknametxt.getText();
String pPassword = new String(passwordtxt.getPassword());
String pPass = new String(passtxt.getPassword());
Player player;
if (pPassword.equals(pPass)) {
player = new Player(pName, pNick, pPass);
Array saveToArrayList = Array.getInstance();
saveToArrayList.addPlayer(player);
/*FilesManager save = FilesManager.getInstance();
boolean newFile = true;
if(addToExisting){
addToExisting = false;
newFile = false;
}
save.SavePlayer(player, "players.csv", newFile);*/
} else {
BadPass msg = new BadPass();
msg.setVisible(true);
dispose();
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(SignIn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(SignIn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(SignIn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(SignIn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SignIn().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton accept;
private javax.swing.JButton cancel;
private javax.swing.JLabel namelbl;
private javax.swing.JTextField nametxt;
private javax.swing.JLabel nicknamelbl;
private javax.swing.JTextField nicknametxt;
private javax.swing.JLabel passrptlbl;
private javax.swing.JPasswordField passtxt;
private javax.swing.JLabel passwordlbl;
private javax.swing.JPasswordField passwordtxt;
// End of variables declaration
}
Clase BadPass, que indica un mensaje en caso de que las contraseñas no coincidan:
package starwarsbattleship;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
/**
*
* @author r2montero
*/
public class BadPass extends javax.swing.JFrame {
/**
* Creates new form BadPass
*/
public BadPass() {
initComponents();
setTitle("Contraseñas no coinciden");
setIconImage(new ImageIcon(getClass().getResource("/images/deathstarico.png")).getImage());
((JPanel)getContentPane()).setOpaque(false);
ImageIcon vader = new ImageIcon(this.getClass().getResource("/images/vadermsg.jpg"));
JLabel background = new JLabel();
background.setIcon(vader);
getLayeredPane().add(background,JLayeredPane.FRAME_CONTENT_LAYER);
background.setBounds(0, 0, vader.getIconWidth(), vader.getIconHeight());
setLocationRelativeTo(null);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
accept = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
setType(java.awt.Window.Type.POPUP);
jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 16)); // NOI18N
jLabel1.setForeground(new java.awt.Color(164, 21, 19));
jLabel1.setText("¡Las contraseñas digitadas");
jLabel2.setFont(new java.awt.Font("Ubuntu", 1, 16)); // NOI18N
jLabel2.setForeground(new java.awt.Color(164, 21, 19));
jLabel2.setText("deben ser iguales!");
jLabel3.setFont(new java.awt.Font("Ubuntu", 1, 16)); // NOI18N
jLabel3.setForeground(new java.awt.Color(164, 21, 19));
jLabel3.setText("Intentelo otra vez");
accept.setText("Aceptar");
accept.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
acceptMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(accept, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)))
.addContainerGap(186, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
.addComponent(accept)
.addGap(25, 25, 25))
);
pack();
}// </editor-fold>
private void acceptMouseClicked(java.awt.event.MouseEvent evt) {
SignIn back = new SignIn();
back.setVisible(true);
dispose();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(BadPass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(BadPass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(BadPass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(BadPass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new BadPass().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton accept;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
// End of variables declaration
}
Cont...