Advertisement
FenrirsCode

Untitled

Mar 7th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. public class AddPlayer extends javax.swing.JFrame {
  2. StringBuffer display = new StringBuffer("");
  3.  
  4. /**
  5. * Creates new form AddPlayer
  6. */
  7. public AddPlayer() {
  8. initComponents();
  9.  
  10. this.setIconImage(Toolkit.getDefaultToolkit().
  11. getImage("src/CardImage/Joker_B.png"));
  12. this.setLocationRelativeTo(null);
  13. this.getRootPane().setDefaultButton(addJButton);
  14.  
  15. }
  16.  
  17. /**
  18. * This method is called from within the constructor to initialize the form.
  19. * WARNING: Do NOT modify this code. The content of this method is always
  20. * regenerated by the Form Editor.
  21. */
  22. @SuppressWarnings("unchecked")
  23. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  24. private void initComponents() {
  25.  
  26. addJButton = new javax.swing.JButton();
  27. newplayerJTextField = new javax.swing.JTextField();
  28. jLabel1 = new javax.swing.JLabel();
  29. closeJButton = new javax.swing.JButton();
  30.  
  31. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  32.  
  33. addJButton.setText("Add Player");
  34. addJButton.addActionListener(new java.awt.event.ActionListener() {
  35. public void actionPerformed(java.awt.event.ActionEvent evt) {
  36. addJButtonActionPerformed(evt);
  37. }
  38. });
  39.  
  40. jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  41. jLabel1.setText("Enter Name of New Player");
  42.  
  43. closeJButton.setText("Close");
  44. closeJButton.addActionListener(new java.awt.event.ActionListener() {
  45. public void actionPerformed(java.awt.event.ActionEvent evt) {
  46. closeJButtonActionPerformed(evt);
  47. }
  48. });
  49.  
  50. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  51. getContentPane().setLayout(layout);
  52. layout.setHorizontalGroup(
  53. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  54. .addGroup(layout.createSequentialGroup()
  55. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  56. .addGroup(layout.createSequentialGroup()
  57. .addGap(58, 58, 58)
  58. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE))
  59. .addGroup(layout.createSequentialGroup()
  60. .addGap(20, 20, 20)
  61. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  62. .addComponent(closeJButton)
  63. .addComponent(newplayerJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
  64. .addGap(31, 31, 31)
  65. .addComponent(addJButton)))
  66. .addContainerGap(19, Short.MAX_VALUE))
  67. );
  68. layout.setVerticalGroup(
  69. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  70. .addGroup(layout.createSequentialGroup()
  71. .addContainerGap()
  72. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
  73. .addGap(18, 18, 18)
  74. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  75. .addComponent(newplayerJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
  76. .addComponent(addJButton))
  77. .addGap(18, 18, 18)
  78. .addComponent(closeJButton)
  79. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  80. );
  81.  
  82. pack();
  83. }// </editor-fold>
  84.  
  85. private void closeJButtonActionPerformed(java.awt.event.ActionEvent evt) {
  86. // TODO add your handling code here:
  87.  
  88. dispose();
  89. }
  90.  
  91. private void addJButtonActionPerformed(java.awt.event.ActionEvent evt) {
  92. // TODO add your handling code here:
  93. //Variables:
  94. String FILEDIRECTORY = ("src//Players.txt");
  95. try{
  96. File file =new File(FILEDIRECTORY);
  97. FileWriter writer = new FileWriter(file,true);
  98. BufferedWriter buffered = new BufferedWriter(writer);
  99. try (PrintWriter pw = new PrintWriter(buffered))
  100. {
  101.  
  102. pw.println(newplayerJTextField.getText());
  103.  
  104. }
  105. }catch(IOException ioe){
  106. //this is in a different form then the cardGame
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement