Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import javax.swing.JTextField;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.io.BufferedReader;
- import java.io.FileReader;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author TI
- */
- public class telesw extends javax.swing.JFrame {
- /**
- * Creates new form telesw
- */
- public telesw() {
- 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() {
- jLabel1 = new javax.swing.JLabel();
- player = new javax.swing.JTextField();
- jLabel2 = new javax.swing.JLabel();
- plrok = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setText("Teleturniej Świąteczny");
- jLabel2.setText("Nazwa gracza");
- plrok.setText("Ok");
- plrok.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- plrokMouseClicked(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()
- .addGap(140, 140, 140)
- .addComponent(jLabel1)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(plrok)
- .addGap(52, 52, 52))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGap(0, 108, Short.MAX_VALUE)
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(player, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(138, 138, 138))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(28, 28, 28)
- .addComponent(jLabel1)
- .addGap(59, 59, 59)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(player, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 116, Short.MAX_VALUE)
- .addComponent(plrok)
- .addGap(40, 40, 40))
- );
- pack();
- }// </editor-fold>
- private void plrokMouseClicked(java.awt.event.MouseEvent evt) {
- try {
- String filename = "players.txt";
- FileWriter fw = new FileWriter(filename,true);
- fw.write(player.getText()+"\r\n");
- fw.close();
- } catch(IOException ioe) {
- System.err.println("IOException: " + ioe.getMessage());
- }
- String fileName = "player.txt";
- try {
- PrintWriter outputStream = new PrintWriter(fileName);
- outputStream.println(player.getText());
- outputStream.close();
- System.out.println("Gotowe.");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- this.dispose();
- opis jframe = new opis();
- jframe.setVisible(true);
- //String name = "";
- //try {
- // BufferedReader br = new BufferedReader(new FileReader("Name.txt"));
- // String line = null;
- // while ((line=br.readLine()) != null) {
- // String tmp[] = line.split("\t");
- // name = tmp[0];
- // System.out.println(name + "\t");
- // }
- // br.close();
- //} catch (IOException e) {
- // e.printStackTrace();
- //}
- //String string = player.getText();
- //try {
- // BufferedWriter writer =
- // new BufferedWriter ( new FileWriter(".\\test.txt"));
- // writer.write(string);
- // writer.close();
- //} catch (IOException e) {
- // e.printStackTrace();
- //}
- //String fileName = "players.txt";
- //try {
- // PrintWriter outputStream = new PrintWriter(fileName);
- // outputStream.println("\n");
- // outputStream.println(player.getText());
- // outputStream.close();
- // System.out.println("Gotowe.");
- //} catch (FileNotFoundException e) {
- // e.printStackTrace();
- //}
- //String playerName = player.getText();
- //String playerName = "Gracz";
- //JTextField player = ...;
- //String title = player.getText();
- //FileWriter fw = new FileWriter(new File(title+".txt"));
- //fw.write(title);
- //fw.close();
- //String file_name = "C:/Users/TI/Documents/NetBeansProjects/teleturniej/players/players.txt";
- //try {
- // ReadFile file = new ReadFile(file_name);
- // String[] aryLines = file.OpenFile();
- // int i;
- // for (i=0; i <aryLines.length; i++) {
- // System.out.printIn(aryLines[i]);
- // }
- //}catch (IOException e) {
- // System.out.printIn( "Sorry, dude - no can do!" );
- //}
- // try {
- // BufferedWriter writer =
- // new BufferedWriter ( new FileWriter(".\\players.txt") );
- // writer.write(playerName);
- // writer.close();
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
- //plyr.setText(playerName);
- //this.dispose();
- //opis opistele = new opis();
- //opistele.setVisible(true);
- }
- /**
- * @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(telesw.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(telesw.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(telesw.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(telesw.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 telesw().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JTextField player;
- private javax.swing.JButton plrok;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment