Reference no: EM13940255
Develop an application that counts the number of words, number of characters with spaces and without spaced. The program should display the text file statistics as follows:
File Name: sample.txt
Number of Words: 124
Number of characters without spaces: 1045
Number of characters with spaces: 1200
The application shall be a counsel compatible application-(needs a GUI)
here's what I have so far...
i'm missing both character counters and am not sure how to get files in my gui
__________________________________________________________________
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
//////////////////////////////////////////////////////// CountWords
public class CountWords extends JFrame {
//====================================================== fields
JTextField _fileNameTF = new JTextField(15);
JTextField _wordCountTF = new JTextField(4);
JFileChooser _fileChooser = new JFileChooser();
//================================================= constructor
CountWords() {
//... Create / set component characteristics.
_fileNameTF.setEditable(false);
_wordCountTF.setEditable(false);
//... Add listeners
//... Create content pane, layout components
JPanel content = new JPanel();
content.setLayout(new FlowLayout());
content.add(new JLabel("File:"));
content.add(_fileNameTF);
content.add(new JLabel("Word Count:"));
content.add(_wordCountTF);
//... Create menu elements (menubar, menu, menu item)
JMenuBar menubar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem openItem = new JMenuItem("Open...");
openItem.addActionListener(new OpenAction());
//... Assemble the menu
menubar.add(fileMenu);
fileMenu.add(openItem);
//... Set window characteristics
this.setJMenuBar(menubar);
this.setContentPane(content);
this.setTitle("Count Words");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack(); // Layout components.
this.setLocationRelativeTo(null); // Center window.
}
//============================================= countWordsInFile
private int countWordsInFile(File f) {
int numberOfWords = 0; // Count of words.
try {
Scanner in = new Scanner(f);
while (in.hasNext()) {
String word = in.next(); // Read a "token".
numberOfWords++;
}
in.close(); // Close Scanner's file.
} catch (FileNotFoundException fnfex) {
// ... We just got the file from the JFileChooser,
// so it's hard to believe there's problem, but...
JOptionPane.showMessageDialog(CountWords.this,
fnfex.getMessage());
}
return numberOfWords;
}
///////////////////////////////////////////////////// OpenAction
class OpenAction implements ActionListener {
public void actionPerformed(ActionEvent ae) {
//... Open a file dialog.
int retval = _fileChooser.showOpenDialog(CountWords.this);
if (retval == JFileChooser.APPROVE_OPTION) {
//... The user selected a file, get it, use it.
File file = _fileChooser.getSelectedFile();
//... Update user interface.
_fileNameTF.setText(file.getName());
_wordCountTF.setText("" + countWordsInFile(file));
}
}
}
//========================================================= main
public static void main(String[] args) {
JFrame window = new CountWords();
window.setVisible(true);
}
}
Cost formula for its supplies cost
: Ingram Framing's cost formula for its supplies cost is $1,120 per month plus $12 per frame. For the month of June, the company planned for activity of 610 frames,
|
What is role of material requisition forms in costing system
: What is the role of materials requisition forms in a job-order costing system? Time tickets? Predetermined overhead rates?
|
Components of the new product development process
: Choose two components of the new product development process e.g. idea generation, product development, market analysis, commercialization or product launch and describe and analyse the product development strategy adopted by an energy company as ..
|
Document supersedes all oral promises relating to the sale
: In a transaction for the sale of an auto painting facility, Bright Auto Colors Company tells Custom Cars Corporation that the paints and other supplies on-site are included. The contract says nothing about the supplies on-site, but does state, “This ..
|
Develop an application that counts the number of words
: Develop an application that counts the number of words, number of characters with spaces and without spaced
|
Production facilities across the country
: A privately-owned manufacturing firm has three production facilities across the country. Here are some important facts about these facilities:
|
Proposed above of reducing selling price and undertaking
: Using an excel sheet that shows the relevant formulas; calculate the break-even point (in units as well as in dollars)for the original budgeted income statement provided above.
|
What recommendations would you make to correct it
: How can managers determine if organizational structure is out of alignment with an organization's strategy in a criminal justice organization? If the organizational structure were misaligned, what recommendations would you make to correct it?
|
Discuss the organisation of a maintenance department
: 1. Discuss the organisation of a maintenance department of a large hotel. State the factors for which the maintenance staff is responsible. (1/2 page)
|