sukh singh

Greenhorn
+ Follow
since Nov 30, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sukh singh

i am trying to browse for any text file and load the context of the text file in my input text area.
the browse button is supposed to browse for any text file and bring up the loaction i.e, H:/mydocuments/code.txt in the FUText field and when the load button is pressed the context of the chosen browsed file should appear in the input text area.
18 years ago
thank you for your help, i have put in the missing bracket but i might have put it in the wrong place because i now have 4 errors.

if (Arrays.binarySearch((words), currToken) > -1)


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

class halstead{
//for keyboard input
static BufferedReader keyboard = new BufferedReader(new
InputStreamReader(System.in));
//for screen output
static PrintWriter screen = new PrintWriter(System.out, true);
//main method - first method to be executed
public static void main(String[]args)throws IOException{
String line = null;
String file;

String[] words = { "ADDHANDLER", "ADDRESSOF", "ANDALSO", "ALIAS", "AND" };

//use screen object (class PrintWriter) to display
//string on screen
screen.print("enter the name of the file to be read: ");
screen.flush();
file = new String(keyboard.readLine());

//a bufferedreader object that takes a stream of characters
//from the fileraeader object and sends a string into
//the program
BufferedReader reader = new BufferedReader(new FileReader(file));

//the bufferedreader method readline() reads from the
//character stream to program a line of characters
line = reader.readLine();

//while loop where readline method returns a null value when
//the end of the file is reached
while (line!= null)
{

//decleration of string tokenizer
//used to seperate each word for comparison to terms specified
StringTokenizer words = new StringTokenizer(line);


Arrays.sort(words);
String currToken = words.nextToken();
if (Arrays.binarySearch((words), currToken) > -1)
++count;


line = reader.readLine();
}

}
}
18 years ago
hi, i have made a GUI and i am having problems with browsing for a text file and loading it on to the GUI. i can get a browse dialogue box to appear, but thats all i can do.

any help will be much appreciated.

thnak you.

here is the code for my GUI:-

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.JTextField.*;
import javax.swing.JTextArea.*;
import java.awt.print.*;
import java.io.*;

class JFrameDemo extends JFrame {

private JTextField FUText, inputText, resultText;
JFrame jWindow;

public JFrameDemo()
{
super("Halstead Metrics");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Container contentPane = this.getContentPane(); //we add components to the contentPane
contentPane.setLayout(new GridLayout(0,1,3,3));

JPanel topPanel = new JPanel(new GridLayout(0,2,2,2));
JPanel middlePanel = new JPanel(new GridLayout(1,1,5,5));
JPanel bottomPanel = new JPanel(new GridLayout(0,2,5,5));
JPanel endPanel = new JPanel(new GridLayout(0,1,5,5));

//JPanel topPanel = new JPanel();
JLabel FULabel = new JLabel("File or URL", JLabel.CENTER);
topPanel.add(FULabel);
FULabel.setToolTipText("Enter File or URL");
FULabel.setVisible(true);

FUText = new JTextField(10);
FUText.setToolTipText("Enter File or URL");
FUText.setText("Enter File or URL");
FUText.setEditable(true);
topPanel.add(FUText);



JButton browse = new JButton("Browse");
topPanel.add(browse);

browse.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFileChooser browse = new JFileChooser();
browse.showOpenDialog(jWindow);
}
}
);

JButton load = new JButton("Load Script");
topPanel.add(load);




contentPane.add(topPanel); //add the panel to the frame

final JTextArea inputText = new JTextArea();
JScrollPane scrollingArea = new JScrollPane();
scrollingArea.add(new JTextArea(5,5));
inputText.setEditable(true);
middlePanel.add(inputText);

//JScrollPane jsp = new JScrollPane();
//jsp.add(new JTextArea(5,5));


JButton execute = new JButton("Execute");
bottomPanel.add(execute);



JButton clear = new JButton("Clear Screen");
clear.setToolTipText("Click to Cancel Request");
bottomPanel.add(clear);

clear.addActionListener ( new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
FUText.setText(null);
inputText.setText(null);
resultText.setText(null);
}
}
);

JButton refresh = new JButton("Refresh");
bottomPanel.add(refresh);

refresh.addActionListener ( new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
resultText.setText(null);
}
}
);

contentPane.add(middlePanel); //add the panel to the frame

//JPanel bottomPanel = new JPanel();
final JTextArea resultText = new JTextArea();
resultText.setEditable(false);
endPanel.add(resultText);



JButton exit = new JButton("EXIT");
bottomPanel.add(exit);

exit.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
);

//creates menu bar.
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);

JMenu menuFile = new JMenu ("File");
menuBar.add(menuFile);

JMenuItem fSave = new JMenuItem("Save");
menuFile.add(fSave);

JMenuItem fPrint = new JMenuItem("Print");
menuFile.add(fPrint);

fPrint.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
PrinterJob printJob = PrinterJob.getPrinterJob();
//printJob.setPrintable(this);
if (printJob.printDialog())
try {
printJob.print();
}
catch(PrinterException pe)
{
System.out.println("Error printing: " + pe);
}
}
}
);

JMenuItem fExit = new JMenuItem("Exit");
menuFile.add(fExit);

fExit.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
);

contentPane.add(bottomPanel); //add the panel to the frame
contentPane.add(endPanel);

//--------Other javax.swing components-------------

this.pack();
this.setVisible(true);
}

/* Test */
public static void main (String[] arg) {
JFrameDemo jf = new JFrameDemo();
}
}
18 years ago
thank you for your help. i tried your code and got one error and i was hoping you could tell me where i have gone wrong.

i get the following error:-

H:\qp&e\halstead.java:45: ')' expected
if (Arrays.binarySearch(words), currToken) > -1)
^
1 error
Finished


here is the code so far:-

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

class halstead{
//for keyboard input
static BufferedReader keyboard = new BufferedReader(new
InputStreamReader(System.in));
//for screen output
static PrintWriter screen = new PrintWriter(System.out, true);
//main method - first method to be executed
public static void main(String[]args)throws IOException{
String line = null;
String file;

String[] words = { "ADDHANDLER", "ADDRESSOF", "ANDALSO", "ALIAS", "AND" };

//use screen object (class PrintWriter) to display
//string on screen
screen.print("enter the name of the file to be read: ");
screen.flush();
file = new String(keyboard.readLine());

//a bufferedreader object that takes a stream of characters
//from the fileraeader object and sends a string into
//the program
BufferedReader reader = new BufferedReader(new FileReader(file));

//the bufferedreader method readline() reads from the
//character stream to program a line of characters
line = reader.readLine();

//while loop where readline method returns a null value when
//the end of the file is reached
while (line!= null)
{

//decleration of string tokenizer
//used to seperate each word for comparison to terms specified
StringTokenizer words = new StringTokenizer(line);


Arrays.sort(words);
String currToken = words.nextToken();
if (Arrays.binarySearch(words), currToken) > -1)
++count;


line = reader.readLine();
}

}
}
18 years ago
i have created a program below and i am having a problem with a variable called numWords i am trying to call this variable from near the bottom of of my code but i keep gettin the following error:

H:\qp&e\mess\halstead.java:1178: variable numWords might not have been initialized
N_2 = numWords - N_1;
^
1 error
Finished


i dont know what i'm doing wrong. numWords has been declared near the top of my coding. numWords counts the total number of words in a text file and i want to subtract N_1(total operaters counted) from numWords but i keep getting a error. N_1 is declared near the bottom of my code.


below is my code, its very long:


[ EJFH: Added UBB "Code" tags for formatting ]
[ December 08, 2004: Message edited by: Ernest Friedman-Hill ]
18 years ago
i need help with counting operands from a text file.
i have a code that count operaters which i have set in the porgram and i can count how many times they appear in the text file, but now i need to exclude the operaters i have set, which inturn will leave me with the operands.

any help will be welcomed.
18 years ago
can any one help me scroll down a editable and uneditable textfield
18 years ago
hi can any one help me, i need to count specific words which are kept in a array list and then i need to count how many times theses words appear in a text file.
so far i can count specific characters from a array list and see how many times they appear in a text file. i am also able to count the number of lines, characters and even how many words appear in a text file.

below is the code i have done so far andy help would be welcomed.

thank you for your time.

[ December 06, 2004: Message edited by: sukh singh ]

[ Jess added UBB [code] tags to perserve whitespace ]

[ December 06, 2004: Message edited by: Jessica Sant ]
18 years ago
i was given help to create a code to count operaters such as:-
'+','-', '*', '/', etc.....
this works fine to count number of operaters which are a single character, but i a m having trouble counting operaters which are words such:-
"if", "else", "while", ect.....
i tried to modify the code counting single character operaters but i keep gettin a error.

i get the following error:

H:\qp&e\1\StringCount.java:52: cannot resolve symbol
symbol : method toStringArray ()
location: class java.lang.String
String[] cReadline = sReadLine.toStringArray();
^
1 error
Finished


here is the code which i have tried to use:

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

//*******************************************************************************************************************************

public class StringCount
{

int iADDHANDLERCount = 0;

//*******************************************************************************************************************************


// change this array according to your need.
String sOperatorsArray[] = {"ADDHANDLER"};


//*******************************************************************************************************************************


private int getADDHANDLERCount(){
return iADDHANDLERCount;
}


//*******************************************************************************************************************************


private void readMyFile(String sFile){
try {
try {
FileReader fReader = new FileReader(sFile);
BufferedReader bReader = new BufferedReader(fReader);
String sReadLine = null;
while((sReadLine = bReader.readLine()) != null){
countOperators(sReadLine, sOperatorsArray);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}


//*******************************************************************************************************************************

private void countOperators(String sReadLine, String[] sArrayOperators){
String[] cReadline = sReadLine.toStringArray();
int iReadLineLength = cReadline.length;
int iNoOfOperators = sArrayOperators.length;

for(int i=0; i<iReadLineLength; i++){
for(int j=0; j<iNoOfOperators; j++){
if(cReadline[i] == sArrayOperators[j]){

// add the loops according to your need here.
if(cReadline[i] == "ADDHANDLER"){
iADDHANDLERCount = iADDHANDLERCount + 1;
}

}
}
}
}


//*******************************************************************************************************************************



public static void main(String[] args)
{
StringCount sCount = new StringCount();
sCount.readMyFile("H:/qp&e/1/Shapes.txt");
System.out.println("ADDHANDLER count is --> "+sCount.getADDHANDLERCount());
}
}
18 years ago
i tried to modify the code you sent so i could count operaters like "end", "if", "while", etc.....
but i keep gettin errors, the program wont accept a string as a operater.

i get the following error:

H:\qp&e\1\StringCount.java:52: cannot resolve symbol
symbol : method toStringArray ()
location: class java.lang.String
String[] cReadline = sReadLine.toStringArray();
^
1 error
Finished


here is the code which i have tried to use:

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

//*******************************************************************************************************************************

public class StringCount
{

int iADDHANDLERCount = 0;

//*******************************************************************************************************************************


// change this array according to your need.
String sOperatorsArray[] = {"ADDHANDLER"};


//*******************************************************************************************************************************


private int getADDHANDLERCount(){
return iADDHANDLERCount;
}


//*******************************************************************************************************************************


private void readMyFile(String sFile){
try {
try {
FileReader fReader = new FileReader(sFile);
BufferedReader bReader = new BufferedReader(fReader);
String sReadLine = null;
while((sReadLine = bReader.readLine()) != null){
countOperators(sReadLine, sOperatorsArray);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}


//*******************************************************************************************************************************

private void countOperators(String sReadLine, String[] sArrayOperators){
String[] cReadline = sReadLine.toStringArray();
int iReadLineLength = cReadline.length;
int iNoOfOperators = sArrayOperators.length;

for(int i=0; i<iReadLineLength; i++){
for(int j=0; j<iNoOfOperators; j++){
if(cReadline[i] == sArrayOperators[j]){

// add the loops according to your need here.
if(cReadline[i] == "ADDHANDLER"){
iADDHANDLERCount = iADDHANDLERCount + 1;
}

}
}
}
}


//*******************************************************************************************************************************



public static void main(String[] args)
{
StringCount sCount = new StringCount();
sCount.readMyFile("H:/qp&e/1/Shapes.txt");
System.out.println("ADDHANDLER count is --> "+sCount.getADDHANDLERCount());
}
}
18 years ago
i just dont know where to start it.
i know i have to create a array holding the operaters i want to count, buti dont know what to do next.
i've tried to use the code, which i have shown above as a guidline to count the operaters, but i keep messing up. i am able to read from the text file, but i am unable to compare the words in the text file to the words/operaters in the array list and count them.

for example if had the following operaters in my araylist
if, else, while, +, -, *, etc....
how can i count how many times each operater appears in a source code from a text file.
18 years ago
i am having problems in counting the operaters in a source code which has been saved as a text file.
i have to set set certain operaters like "end", "if", "+", "*" etc... in arraylist and then i need to compare these operaters to the text file and see if they appear in the source code and then count how many times they appear in the source code.
18 years ago
hi can any one help me with counting the operands and operators of a source code from a text file

[ November 30, 2004: Message edited by: sukh singh ]


the code below is what i have got working so far, but i dont know how to count slected operands and operators form a text file

[ November 30, 2004: Message edited by: sukh singh ]

[ Jess added UBB [code] tags to perserve whitespace ]
[ December 01, 2004: Message edited by: Jessica Sant ]
18 years ago