1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
|
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
/**
*
* @author abysr
*/
class FactoryPlayer extends javax.swing.JFrame {
private static int nbOfPlayer;
private static List<String> nameList = new ArrayList<String>();
private List<Player> playersList = new ArrayList<Player>();
/**
* Creates new form FactoryPlayer
*/
public FactoryPlayer() {
initComponents();
}
/**
* 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() {
btnGroupNbPlayers = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
pnlNbPlayers = new javax.swing.JPanel();
btnOkNbPlayers = new javax.swing.JButton();
btnBackNbPlayers = new javax.swing.JButton();
rdBtn2Players = new javax.swing.JRadioButton();
rdBtn3Players = new javax.swing.JRadioButton();
rdBtn4Players = new javax.swing.JRadioButton();
pnlPlayerNames = new javax.swing.JPanel();
lblPlayer4 = new javax.swing.JLabel();
btnOkPlayerNames = new javax.swing.JButton();
lblPlayer1 = new javax.swing.JLabel();
lblPlayer2 = new javax.swing.JLabel();
lblPlayer3 = new javax.swing.JLabel();
txtPlayer4 = new javax.swing.JTextField();
txtPlayer3 = new javax.swing.JTextField();
txtPlayer2 = new javax.swing.JTextField();
txtPlayer1 = new javax.swing.JTextField();
btnBackNbPlayers1 = new javax.swing.JButton();
pnlRules = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
btnBackRules = new javax.swing.JButton();
jLabel5 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new java.awt.CardLayout());
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jButton1.setText("Rules");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 130, -1, 40));
jButton3.setText("Game");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jPanel1.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 127, -1, 40));
getContentPane().add(jPanel1, "card2");
btnOkNbPlayers.setText("Ok");
btnOkNbPlayers.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOkNbPlayersActionPerformed(evt);
}
});
btnBackNbPlayers.setText("Back");
btnBackNbPlayers.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBackNbPlayersActionPerformed(evt);
}
});
btnGroupNbPlayers.add(rdBtn2Players);
rdBtn2Players.setSelected(true);
rdBtn2Players.setText("2 players");
btnGroupNbPlayers.add(rdBtn3Players);
rdBtn3Players.setText("3 players");
btnGroupNbPlayers.add(rdBtn4Players);
rdBtn4Players.setText("4 players");
javax.swing.GroupLayout pnlNbPlayersLayout = new javax.swing.GroupLayout(pnlNbPlayers);
pnlNbPlayers.setLayout(pnlNbPlayersLayout);
pnlNbPlayersLayout.setHorizontalGroup(
pnlNbPlayersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlNbPlayersLayout.createSequentialGroup()
.addGap(140, 140, 140)
.addGroup(pnlNbPlayersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlNbPlayersLayout.createSequentialGroup()
.addComponent(btnOkNbPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 91, Short.MAX_VALUE)
.addComponent(btnBackNbPlayers)
.addGap(24, 24, 24))
.addGroup(pnlNbPlayersLayout.createSequentialGroup()
.addGroup(pnlNbPlayersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(rdBtn4Players)
.addComponent(rdBtn3Players)
.addComponent(rdBtn2Players))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
);
pnlNbPlayersLayout.setVerticalGroup(
pnlNbPlayersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlNbPlayersLayout.createSequentialGroup()
.addGap(57, 57, 57)
.addComponent(rdBtn2Players)
.addGap(18, 18, 18)
.addComponent(rdBtn3Players)
.addGap(18, 18, 18)
.addComponent(rdBtn4Players)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
.addGroup(pnlNbPlayersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnOkNbPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnBackNbPlayers))
.addGap(56, 56, 56))
);
getContentPane().add(pnlNbPlayers, "card3");
pnlPlayerNames.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
lblPlayer4.setText("player 4");
pnlPlayerNames.add(lblPlayer4, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 150, -1, 26));
btnOkPlayerNames.setText("Ok");
btnOkPlayerNames.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOkPlayerNamesActionPerformed(evt);
}
});
pnlPlayerNames.add(btnOkPlayerNames, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 210, -1, -1));
lblPlayer1.setText("player 1");
pnlPlayerNames.add(lblPlayer1, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 30, -1, 26));
lblPlayer2.setText("player 2");
pnlPlayerNames.add(lblPlayer2, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 70, -1, 26));
lblPlayer3.setText("player 3");
pnlPlayerNames.add(lblPlayer3, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 110, -1, 26));
txtPlayer4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtPlayer4ActionPerformed(evt);
}
});
pnlPlayerNames.add(txtPlayer4, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 150, 170, -1));
pnlPlayerNames.add(txtPlayer3, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 110, 170, -1));
pnlPlayerNames.add(txtPlayer2, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 70, 170, -1));
pnlPlayerNames.add(txtPlayer1, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 30, 170, -1));
btnBackNbPlayers1.setText("Back");
btnBackNbPlayers1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBackNbPlayers1ActionPerformed(evt);
}
});
pnlPlayerNames.add(btnBackNbPlayers1, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 250, -1, -1));
getContentPane().add(pnlPlayerNames, "card4");
pnlRules.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
pnlRules.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(28, 63, 340, 180));
btnBackRules.setText("Back");
btnBackRules.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBackRulesActionPerformed(evt);
}
});
pnlRules.add(btnBackRules, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 250, -1, -1));
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel5.setText("rules");
pnlRules.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 20, 170, -1));
getContentPane().add(pnlRules, "card5");
pack();
}// </editor-fold>
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
jPanel1.setVisible(false);
pnlNbPlayers.setVisible(true);
}
private void btnOkNbPlayersActionPerformed(java.awt.event.ActionEvent evt) {
pnlNbPlayers.setVisible(false);
pnlPlayerNames.setVisible(true);
if (rdBtn2Players.isSelected())
{
nbOfPlayer = 2;
txtPlayer3.setVisible(false);
lblPlayer3.setVisible(false);
txtPlayer4.setVisible(false);
lblPlayer4.setVisible(false);
}
else if ( rdBtn3Players.isSelected())
{
nbOfPlayer = 3;
txtPlayer4.setVisible(false);
lblPlayer4.setVisible(false);
}
else nbOfPlayer = 4;
}
private void btnBackNbPlayersActionPerformed(java.awt.event.ActionEvent evt) {
pnlNbPlayers.setVisible(false);
jPanel1.setVisible(true);
}
private void txtPlayer4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
pnlRules.setVisible(true);
jPanel1.setVisible(false);
}
private void btnBackRulesActionPerformed(java.awt.event.ActionEvent evt) {
pnlRules.setVisible(false);
jPanel1.setVisible(true);
}
private void btnBackNbPlayers1ActionPerformed(java.awt.event.ActionEvent evt) {
pnlPlayerNames.setVisible(false);
pnlNbPlayers.setVisible(true);
txtPlayer3.setVisible(true);
txtPlayer4.setVisible(true);
lblPlayer3.setVisible(true);
lblPlayer4.setVisible(true);
}
private void btnOkPlayerNamesActionPerformed(java.awt.event.ActionEvent evt) {
nameList.add("txtPlayer1");
nameList.add("txtPlayer2");
nameList.add("txtPlayer3");
nameList.add("txtPlayer4");
for ( int i = 0; i < nbOfPlayer; i++)
{
Player p = new Player(nameList.get(i));
playersList.add(p);
}
}
/**
* @param args the command line arguments
*/
public List createPlayers () {
/* 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(FactoryPlayer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FactoryPlayer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FactoryPlayer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FactoryPlayer.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 FactoryPlayer().setVisible(true);
}
});
return playersList;
}
// Variables declaration - do not modify
private javax.swing.JButton btnBackNbPlayers;
private javax.swing.JButton btnBackNbPlayers1;
private javax.swing.JButton btnBackRules;
private javax.swing.ButtonGroup btnGroupNbPlayers;
private javax.swing.JButton btnOkNbPlayers;
private javax.swing.JButton btnOkPlayerNames;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JLabel lblPlayer1;
private javax.swing.JLabel lblPlayer2;
private javax.swing.JLabel lblPlayer3;
private javax.swing.JLabel lblPlayer4;
private javax.swing.JPanel pnlNbPlayers;
private javax.swing.JPanel pnlPlayerNames;
private javax.swing.JPanel pnlRules;
private javax.swing.JRadioButton rdBtn2Players;
private javax.swing.JRadioButton rdBtn3Players;
private javax.swing.JRadioButton rdBtn4Players;
private javax.swing.JTextField txtPlayer1;
private javax.swing.JTextField txtPlayer2;
private javax.swing.JTextField txtPlayer3;
private javax.swing.JTextField txtPlayer4;
// End of variables declaration
} |
Partager