MaxxxxiorS

pierwszeokno.java

Jan 18th, 2019 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.09 KB | None | 0 0
  1. import java.io.BufferedWriter;
  2. import java.io.FileWriter;
  3. import java.io.IOException;
  4. import javax.swing.JTextField;
  5. import java.io.FileNotFoundException;
  6. import java.io.PrintWriter;
  7. import java.io.BufferedReader;
  8. import java.io.FileReader;
  9. /*
  10.  * To change this license header, choose License Headers in Project Properties.
  11.  * To change this template file, choose Tools | Templates
  12.  * and open the template in the editor.
  13.  */
  14.  
  15. /**
  16.  *
  17.  * @author TI
  18.  */
  19. public class telesw extends javax.swing.JFrame {
  20.  
  21.     /**
  22.      * Creates new form telesw
  23.      */
  24.     public telesw() {
  25.         initComponents();
  26.     }
  27.  
  28.     /**
  29.      * This method is called from within the constructor to initialize the form.
  30.      * WARNING: Do NOT modify this code. The content of this method is always
  31.      * regenerated by the Form Editor.
  32.      */
  33.     @SuppressWarnings("unchecked")
  34.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  35.     private void initComponents() {
  36.  
  37.         jLabel1 = new javax.swing.JLabel();
  38.         player = new javax.swing.JTextField();
  39.         jLabel2 = new javax.swing.JLabel();
  40.         plrok = new javax.swing.JButton();
  41.  
  42.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  43.  
  44.         jLabel1.setText("Teleturniej Świąteczny");
  45.  
  46.         jLabel2.setText("Nazwa gracza");
  47.  
  48.         plrok.setText("Ok");
  49.         plrok.addMouseListener(new java.awt.event.MouseAdapter() {
  50.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  51.                 plrokMouseClicked(evt);
  52.             }
  53.         });
  54.  
  55.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  56.         getContentPane().setLayout(layout);
  57.         layout.setHorizontalGroup(
  58.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  59.             .addGroup(layout.createSequentialGroup()
  60.                 .addGap(140, 140, 140)
  61.                 .addComponent(jLabel1)
  62.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  63.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  64.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  65.                 .addComponent(plrok)
  66.                 .addGap(52, 52, 52))
  67.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  68.                 .addGap(0, 108, Short.MAX_VALUE)
  69.                 .addComponent(jLabel2)
  70.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  71.                 .addComponent(player, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
  72.                 .addGap(138, 138, 138))
  73.         );
  74.         layout.setVerticalGroup(
  75.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  76.             .addGroup(layout.createSequentialGroup()
  77.                 .addGap(28, 28, 28)
  78.                 .addComponent(jLabel1)
  79.                 .addGap(59, 59, 59)
  80.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  81.                     .addComponent(player, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  82.                     .addComponent(jLabel2))
  83.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 116, Short.MAX_VALUE)
  84.                 .addComponent(plrok)
  85.                 .addGap(40, 40, 40))
  86.         );
  87.  
  88.         pack();
  89.     }// </editor-fold>                        
  90.  
  91.     private void plrokMouseClicked(java.awt.event.MouseEvent evt) {                                  
  92.         try {
  93.             String filename = "players.txt";
  94.             FileWriter fw = new FileWriter(filename,true);
  95.             fw.write(player.getText()+"\r\n");
  96.             fw.close();
  97.         } catch(IOException ioe) {
  98.             System.err.println("IOException: " + ioe.getMessage());
  99.         }
  100.        
  101.         String fileName = "player.txt";
  102.         try {
  103.             PrintWriter outputStream = new PrintWriter(fileName);
  104.            
  105.             outputStream.println(player.getText());
  106.             outputStream.close();
  107.             System.out.println("Gotowe.");
  108.            
  109.         } catch (FileNotFoundException e) {
  110.             e.printStackTrace();
  111.         }
  112.        
  113.         this.dispose();
  114.         opis jframe = new opis();
  115.         jframe.setVisible(true);
  116.        
  117.        
  118.        
  119.         //String name = "";
  120.        
  121.         //try {
  122.         //    BufferedReader br = new BufferedReader(new FileReader("Name.txt"));
  123.         //    String line = null;
  124.            
  125.         //    while ((line=br.readLine()) != null) {
  126.         //        String tmp[] = line.split("\t");
  127.         //        name = tmp[0];
  128.         //        System.out.println(name + "\t");
  129.         //    }
  130.            
  131.         //    br.close();
  132.         //} catch (IOException e) {
  133.         //    e.printStackTrace();
  134.         //}
  135.        
  136.        
  137. //String string = player.getText();
  138.        
  139.         //try {
  140.         //    BufferedWriter writer =
  141.         //            new BufferedWriter ( new FileWriter(".\\test.txt"));
  142.            
  143.         //    writer.write(string);
  144.            
  145.         //    writer.close();
  146.         //} catch (IOException e) {
  147.         //    e.printStackTrace();
  148.         //}
  149.        
  150.        
  151.        
  152.         //String fileName = "players.txt";
  153.         //try {
  154.         //    PrintWriter outputStream = new PrintWriter(fileName);
  155.            
  156.         //    outputStream.println("\n");
  157.         //    outputStream.println(player.getText());
  158.         //    outputStream.close();
  159.         //    System.out.println("Gotowe.");
  160.            
  161.         //} catch (FileNotFoundException e) {
  162.         //    e.printStackTrace();
  163.         //}
  164.        
  165.        
  166.  
  167.         //String playerName = player.getText();
  168.         //String playerName = "Gracz";
  169.        
  170.         //JTextField player = ...;
  171.         //String title = player.getText();
  172.         //FileWriter fw = new FileWriter(new File(title+".txt"));
  173.         //fw.write(title);
  174.         //fw.close();
  175.        
  176.        
  177.         //String file_name = "C:/Users/TI/Documents/NetBeansProjects/teleturniej/players/players.txt";
  178.        
  179.         //try {
  180.         //    ReadFile file = new ReadFile(file_name);
  181.         //    String[] aryLines = file.OpenFile();
  182.         //    int i;
  183.         //    for (i=0; i <aryLines.length; i++) {
  184.         //        System.out.printIn(aryLines[i]);
  185.         //    }
  186.         //}catch (IOException e) {
  187.         //    System.out.printIn( "Sorry, dude - no can do!" );
  188.         //}
  189. //        try {
  190. //        BufferedWriter writer =
  191. //                new BufferedWriter ( new FileWriter(".\\players.txt") );
  192.        
  193. //        writer.write(playerName);
  194.        
  195. //        writer.close();
  196. //    } catch (IOException e) {
  197. //        e.printStackTrace();
  198. //    }
  199.    
  200.         //plyr.setText(playerName);
  201.         //this.dispose();
  202.         //opis opistele = new opis();
  203.         //opistele.setVisible(true);
  204.     }                                  
  205.  
  206.     /**
  207.      * @param args the command line arguments
  208.      */
  209.     public static void main(String args[]) {
  210.         /* Set the Nimbus look and feel */
  211.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  212.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  213.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  214.          */
  215.         try {
  216.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  217.                 if ("Nimbus".equals(info.getName())) {
  218.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  219.                     break;
  220.                 }
  221.             }
  222.         } catch (ClassNotFoundException ex) {
  223.             java.util.logging.Logger.getLogger(telesw.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  224.         } catch (InstantiationException ex) {
  225.             java.util.logging.Logger.getLogger(telesw.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  226.         } catch (IllegalAccessException ex) {
  227.             java.util.logging.Logger.getLogger(telesw.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  228.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  229.             java.util.logging.Logger.getLogger(telesw.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  230.         }
  231.         //</editor-fold>
  232.  
  233.         /* Create and display the form */
  234.         java.awt.EventQueue.invokeLater(new Runnable() {
  235.             public void run() {
  236.                 new telesw().setVisible(true);
  237.             }
  238.         });
  239.     }
  240.  
  241.     // Variables declaration - do not modify                    
  242.     private javax.swing.JLabel jLabel1;
  243.     private javax.swing.JLabel jLabel2;
  244.     private javax.swing.JTextField player;
  245.     private javax.swing.JButton plrok;
  246.     // End of variables declaration                  
  247. }
Add Comment
Please, Sign In to add comment