Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Delimiters

Delimiters

Scheduled Pinned Locked Moved Java
questionjava
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10694570
    wrote on last edited by
    #1

    How do I separate my input with a tokenizer and delimiter?

    import java.io.BufferedWriter;
    import java.io.FileWriter;

    import javax.swing.JFrame;
    import javax.swing.JPanel;

    /*******************************************************************************************
    Program Name: ClientInformation.java
    Programmer's Name: Elizabeth Conklin
    Program Description: This program will accept user input and save the input to a file.
    *******************************************************************************************/
    public class WClientTest {

    public static void main(String\[\] args) {
    
    	WClient myWClient = new WClient();
    	myWClient.setDefaultCloseOperation(JFrame.EXIT\_ON\_CLOSE);
    	myWClient.setSize(650, 175);
    	myWClient.setTitle("Client Information");
    	myWClient.setVisible(true);	
    }
    

    }

    import java.awt.*;
    import java.awt.event.*;

    import javax.swing.*;

    import java.io.*;
    import java.util.ArrayList;
    import java.util.StringTokenizer;

    public class WClient extends JFrame {

    JLabel labelName;
    JLabel labelID;
    JLabel labelStartingBalance;
    JLabel labelClosingBalance;
    JTextField textName;
    JTextField textID;
    JTextField textStartingBalance;
    JTextField textClosingBalance;
    JButton buttonSave;
    
    public WClient() {
    	setLayout(new GridLayout(0,4));
    
    	labelName = new JLabel("Client Name: ");
    	add(labelName);
    	textName = new JTextField(10);
    	add(textName);
    	labelID = new JLabel("Client ID: ");
    	add(labelID);
    	textID = new JTextField(10);
    	add(textID);
    	labelStartingBalance = new JLabel("Starting Balance: ");
    	add(labelStartingBalance);
    	textStartingBalance = new JTextField(10);
    	add(textStartingBalance);
    	labelClosingBalance = new JLabel("Closing Balance: ");
    	add(labelClosingBalance);
    	textClosingBalance = new JTextField(10);
    	add(textClosingBalance);
    	buttonSave = new JButton("SAVE");
    	add(buttonSave);
    
    	event e = new event();
    	buttonSave.addActionListener(e);}
    
    public class event implements ActionListener{
    	public void actionPerformed(ActionEvent e) {
    			try {
    				String name = textName.getText();
    				String ID = textID.getText();
    				String startingBalance = textStartingBalance.getText();
    				String closingBalance = textClosingBalance.getText();
    				
    				textName.setText("");
    				textID.setText("");
    				textStartingBalance.setText("");
    				textClosingBalance.setText("");
    				
    				BufferedWriter outfile = new BufferedWriter(new FileWriter("client.txt", true));
    				
    				outfile
    
    L 1 Reply Last reply
    0
    • U User 10694570

      How do I separate my input with a tokenizer and delimiter?

      import java.io.BufferedWriter;
      import java.io.FileWriter;

      import javax.swing.JFrame;
      import javax.swing.JPanel;

      /*******************************************************************************************
      Program Name: ClientInformation.java
      Programmer's Name: Elizabeth Conklin
      Program Description: This program will accept user input and save the input to a file.
      *******************************************************************************************/
      public class WClientTest {

      public static void main(String\[\] args) {
      
      	WClient myWClient = new WClient();
      	myWClient.setDefaultCloseOperation(JFrame.EXIT\_ON\_CLOSE);
      	myWClient.setSize(650, 175);
      	myWClient.setTitle("Client Information");
      	myWClient.setVisible(true);	
      }
      

      }

      import java.awt.*;
      import java.awt.event.*;

      import javax.swing.*;

      import java.io.*;
      import java.util.ArrayList;
      import java.util.StringTokenizer;

      public class WClient extends JFrame {

      JLabel labelName;
      JLabel labelID;
      JLabel labelStartingBalance;
      JLabel labelClosingBalance;
      JTextField textName;
      JTextField textID;
      JTextField textStartingBalance;
      JTextField textClosingBalance;
      JButton buttonSave;
      
      public WClient() {
      	setLayout(new GridLayout(0,4));
      
      	labelName = new JLabel("Client Name: ");
      	add(labelName);
      	textName = new JTextField(10);
      	add(textName);
      	labelID = new JLabel("Client ID: ");
      	add(labelID);
      	textID = new JTextField(10);
      	add(textID);
      	labelStartingBalance = new JLabel("Starting Balance: ");
      	add(labelStartingBalance);
      	textStartingBalance = new JTextField(10);
      	add(textStartingBalance);
      	labelClosingBalance = new JLabel("Closing Balance: ");
      	add(labelClosingBalance);
      	textClosingBalance = new JTextField(10);
      	add(textClosingBalance);
      	buttonSave = new JButton("SAVE");
      	add(buttonSave);
      
      	event e = new event();
      	buttonSave.addActionListener(e);}
      
      public class event implements ActionListener{
      	public void actionPerformed(ActionEvent e) {
      			try {
      				String name = textName.getText();
      				String ID = textID.getText();
      				String startingBalance = textStartingBalance.getText();
      				String closingBalance = textClosingBalance.getText();
      				
      				textName.setText("");
      				textID.setText("");
      				textStartingBalance.setText("");
      				textClosingBalance.setText("");
      				
      				BufferedWriter outfile = new BufferedWriter(new FileWriter("client.txt", true));
      				
      				outfile
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Just write your own control character after each data item. You could use commas which will give you a CSV file that you can check by loading into Excel, or using a library method that understands .csv format.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups