File

Page 1 of 1

6 Replies - 298 Views - Last Post: 05 October 2012 - 07:47 AM Rate Topic: -----

#1 ric1989  Icon User is online

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 28-February 12

File

Posted 04 October 2012 - 08:00 PM

i need help fix errors for program to compile correctly? i work many
days on this project.
how to to show number of words, lines in file?
program need to copy file to another file and add 9 words on each line?
how to add a delimiter to the program to look for a word is a string
ends with blank space, a comma, a period?

import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;

public class FileChooserGUI extends JFrame
{
public static final JFileChooser chooser = null;
JButton button1;
JPanel panel;
static JLabel R1;
static JLabel R2;
static JLabel R3;
//input = inFile.readLine(); //read a line
static int wordCount = 0;
public static Scanner input;

FileChooserGUI()
{ //Constructor
panel = new JPanel(new GridLayout(9,10)); //first one increase height
//second one increase width
panel.setSize(300,200);
R1 = new JLabel("Number of Words: "); //1st label
R2 = new JLabel("Number of Lines: "); //2nd label
R3 = new JLabel("Target Words: "); //3rd label
button1 = new JButton("START");

panel.add(R1); //adding three labels to the window frame
panel.add(R2); //adding button 2
panel.add(R3); //adding button 3
panel.add(button1); //adding 1 button to window frame

add(panel); //adding panel to window
R1.setVisible(false);
R2.setVisible(false);
R3.setVisible(false);
setVisible(true);
pack();

//button1.addActionListener(new ActionListener());
}

public void actionPerformed(ActionEvent e)
{
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
}

public static class transferFiles
{
private static final String selectedFile = null;

public static void main(String args[])throws Exception{
try{
int code = chooser.showOpenDialog(null);
if (code == JFileChooser.APPROVE_OPTION)
{
File selectedFile = chooser.getSelectedFile();
Scanner input = new Scanner(selectedFile);
}

while (input.hasNext())
{ //while loop to count all thw words in txt file

++wordCount;
input.next();
}
}

catch (Exception output)
{ //catch an error on getting name of file
output.printStackTrace();
}

String out = selectedFile.getName(); //getname of file

R1.setText("File Name is : " + out);
R2.setText("File Size is : " +Long.toString(size));
R3.setText("Number of words counted : " +Integer.toString(wordCount));
R1.setVisible(true);
R2.setVisible(true);
R3.setVisible(true);

File output = chooser.getSelectedFile();
i= new FileReader(selectedFile);
FileWriter o = new FileWriter(output);

while(((i).hasNext())
{
o.write(i);
}
}
}
}



Is This A Good Question/Topic? 0
  • +

Replies To: File

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: File

Posted 04 October 2012 - 08:02 PM

Which errors ?
When you have errors post them ?
Why should we redo the job the compiler already did for you ?

After 72 posts you should know that you have to post the errors ?
Was This Post Helpful? 1
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10662
  • View blog
  • Posts: 39,590
  • Joined: 27-December 08

Re: File

Posted 04 October 2012 - 08:03 PM

I don't mean to be rude, but you have 72 posts and you are still:
-Posting unindented code
-Not posting errors

How do you expect us to help you fix errors if you don't include them?
Was This Post Helpful? 1
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: File

Posted 04 October 2012 - 08:05 PM

Gheez... Mac... great minds think alike :^:
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10662
  • View blog
  • Posts: 39,590
  • Joined: 27-December 08

Re: File

Posted 04 October 2012 - 08:08 PM

You beat me to the punch there!
Was This Post Helpful? 0
  • +
  • -

#6 ric1989  Icon User is online

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 28-February 12

Re: File

Posted 05 October 2012 - 07:41 AM

Sorry about that, you are right.
i will be remove all my other topics since they do relate. this is
the main program that ill be using and
cant seem to get pass all the errors.
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10662
  • View blog
  • Posts: 39,590
  • Joined: 27-December 08

Re: File

Posted 05 October 2012 - 07:47 AM

I'll just close this thread as a duplicate. Please do not open duplicate threads.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1