masijade 1,351 Industrious Poster Team Colleague Featured Poster

Even though the PDF document is something you "see", it is not, truely, part of the view (IMHO), it is the Data, and I would handle it as such and have all actions that affect it run through the controller.

Just my two cents. ;-)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

As you've been told on Sun, "classB" is null at that point.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

gridheight and gridwidth are the number of columns/rows that this element should occupy in the "grid" defined by the GridBagLayout. It is not a pixel height.

So, so by setting

gbc.gridheight = 60;
        gbc.gridy = 0;

you are saying this element should run from gridy 0 to gridy 59, but then you do

gbc.gridy = 1;

(still with a gridheight of 60 BTW) which puts the second element "under" the first.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, it's kind of hard to help you when we can't see your code.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The ability to use any character regardless of the current system character set.

Be careful though. Unicode is translated as the first step in compilation, so you might wind up with some unforeseen complications.

See http://en.wikibooks.org/wiki/Programming:Java_Comments

puneetkay commented: Thanks for the info! +2
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Nope, it can't, mainly because Number itself can't use those operators, only a little over half the classes that extend Number can use those operators (only through autoboxing of course, which Number, of course, also can't do).

The compiler can only work with what it knows it has, and in this case, that is "Number", and "Number", as already mentioned, cannot use those operators (nor can it be autoboxed, of course).

You can still "get away with" some of this by making this an abstract class and making the last three methods abstract, otherwise you will have to implement a somewhat involved case statement in those methods.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You might also explain what you mean by "cannot do that".

And explain exactly what "vec.x" is, as that is not how you access something in a vector.

But, of course, don't forget the actual code.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, are you entering anything after that prompt?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

First is "SETUPS" equal to the length of the arrays, or to the last index (which is one less than the length, of course), or some other number, like the index of the second to last element.

If it is equal to the length, than every one of those returns should throw an ArrayIndexOutOfBoundsException.

If equals to the last index, then the second return will throw an ArrayIndexOutOfBoundsException.

If equal to the second to last element (or a smaller index) than none will throw that.

Also, do you really want to return the element at "SETUPS" index every time? Somehow I don't think so.

Also, you can avoid that "MAKE COMPILER HAPPY" BS by doing the following (and I am assuming you don't want to always return the last element, and I am assuming that "SETUPS" is actually the length of the arrays, and not the last index):

public Component getComponentAfter(Container focusCycleRoot, Component aComponent) {
    Component retComponent = aComponent;  // Original by default
    for (int i=0; i < SETUPS; i++) {
        if (aComponent == bsTextFields[i]) {
            retComponent = fsTextFields[i];
            break;
        } else if (aComponent == fsTextFields[i]) {
            if ((i + 1) == SETUPS) {
                retComponent = descripTextFields[0];
            } else {
                retComponent = descripTextFields[i+1];
            }
            break;
        } else if (aComponent == descripTextFields[i]) {    
            retComponent = bsTextFields[i];
            break;
        }
    }
    return retComponent;
}

Fixed a few other assumed errors, as well. And I don't usually "give out" code as I find it, usually, counter-productive to the receivers learning.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

grep will only match the lines (and return the entire line, not just the matched portions of it), and will not alter them. If you wish to alter the lines you are going to need to use sed, or something similar.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because of this statement

package helloworldapp;
..
..

you have to change the your method of compilation and also execution.

If package is mentioned then your .class must be placed under the package named folder.

No it doesn't. It is convention to do it that way, but you don't have to. You could place every one of your Java files in the same folder, or all of them in wildly scattered directories around the system, you would have a hard time compiling all of them at the same time, you'd probably have to compile one at a time, in the proper order, using the "-d" option, but you could do it, if you really wanted to.

Now, compile your program
>javac HelloWorldApp.java -d .

>java helloworldapp.HelloWorldApp

Note:
>javac HelloWorldApp.java -d .
where, -d option create a package folder and
. means current folder
>java helloworldapp.HelloWorldApp

"-d" does not mean create a package folder, and using "-d ." is absolutely meaningless, as that is the default anyway. The "-d" option is so that the compiled class files do not appear "in place", but rather somewhere else. I.E. You have a folder containing a src folder and a bin folder, you cd to the source folder and then use "-d /path/to/bin" to have the compiled class files appear (with a full package directory structure) under bin, rather than in place under src. Don't forget, however, to include "-cp /path/to/bin" on the javac commands, however.


masijade 1,351 Industrious Poster Team Colleague Featured Poster

This

private Map<Integer, Integer> targetMap;

declares it, but doesn't define it, which is fine, at this point.

This

Map<Integer, Integer> targetMap = new TreeMap<Integer, Integer>();

declares and defines a new Map, local to the method that hides the instance variable.

So, either remove

Map<Integer, Integer> targetMap = new TreeMap<Integer, Integer>();

and add

targetMap = new TreeMap<Integer, Integer>();

to the constructor.

Or Change

Map<Integer, Integer> targetMap = new TreeMap<Integer, Integer>();

to

if (targetMap == null) {
    targetMap = new TreeMap<Integer, Integer>();
}

but then, don't forget to check whether targetMap is null in the other methods before attempting to use it, or you may still throw a NullPointerException in one of those areas.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I assume you want to "put" the values here, but "get" the values in another method, right?

Well, you're declaring the map in this method, so as soon as this method is finished the map goes out of scope (i.e. doesn't exist anymore).

You need to either declare the map as an instance variable, or pass it into the method, rather than declaring it here.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Student is a class, that method is meant to be called using an instance, and not a class, reference. So, either create an instance of Student and call the method using that, or declare the method static.

Either way will work, since that method is not using any instance data, itself.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Also, are you to return the number of bytes, or the number of charatcers? If this is a UTF character stream, those two will be two different things.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If your talking about how you declared the int and incremented it, then yes, if your talking about passing in byte arrays and creating inputstreams, then, well, why do you think I told you to start over at the beginning of the thread?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

In your inital post, you were to take an intpustream as the argument and count the number of bytes in it. Now you're talking a byte array? Well, if in that case the purpose is to return the number of bytes in the byte array smply return b.length.

Somehow or another, you seem to keep slipping sideways whenever you "correct" something, rather than coming closer to your goal.

Go back to the very start of this thread, and the code that was posted there, then, go through the first few posts changing only those parts of that code that you were told you needed to change and you will have your solution as of post #6.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Sorry, but his question started

create a method where it takes a InputStream as a parameter

and not, necessarily, anything to do with a file.

If you want the size of a file, simply use the length() method.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Do you know how to declare an int variable?

Do you know how to increment it?

Well, declare one before the while loop, and increment it within the while loop. And, do nothing else inside the while loop.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I thought you wanted to count the bytes, not write them out to something else (and, actually, you're trying to write it out to the inputstream you're currently reading, don't you see something wrong with that?). That should be where you look. Don't you think you should be incrementing a variable there, instead?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, hopefully, the both of you are at least competent enough to comment and document it. By doing that you might just get some sort of inkling of what was done. Don't really know if I'd count on it though.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You start with a text editor.

Now, do you have an actual question? Or are you just looking for someone to do this for you?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I'm not certain, but I think you are simply hitting up against some "minimum size" type restrictions. As you can see the orange (dark yellow?) square is the same size as the green and yellow squares and it's relation to the red square has become even more skewed than the other relations, but it still has the same size as the yellow and green. In any case, the code is correct, and I don't know of any other way to "do it" that would have any chance of changing what you're seeing.

Sorry. I won't, at this point, be able to contribute anything else to this thread. ;-)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

A slight correction, since set returns the previous element.

// could also be void, make Vecotr so that it can be "chained"
	public Vector sortContacts(Vector v) {
	   for(int i = 0; i < v.size() - 1; i++) {
		   ContactListLabel cll = (ContactListLabel)v.elementAt(i);
		   for(int y = i + 1; y < v.size(); y++){
			   ContactListLabel cll2 = (ContactListLabel)v.elementAt(y);
			   if(cll.getNameLabel().toLowerCase().compareTo(cll2.getNameLabel().toLowerCase())> 0){
				   v.set(i, cll2);
				   cll = v.set(y, cll);
			   }
		   }
	   }
	   return v;
	}

Very minor difference, but you just well use what Vector provides. ;-)

peter_budo commented: Neat solution, I :* +16
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I would have done it this way (as long as you can modify the Vector passed in, conceptually, as technically you can).

// could also be void, make Vecotr so that it can be "chained"
	public Vector sortContacts(Vector v) {
	   for(int i = 0; i < v.size() - 1; i++) {
		   ContactListLabel cll = (ContactListLabel)v.elementAt(i);
		   for(int y = i + 1; y < v.size(); y++){
			   ContactListLabel cll2 = (ContactListLabel)v.elementAt(y);
			   if(cll.getNameLabel().toLowerCase().compareTo(cll2.getNameLabel().toLowerCase())> 0){
				   v.set(i, cll2);
				   v.set(y, cll);
				   cll = cll2;
			   }
		   }
	   }
	   return v;
	}
masijade 1,351 Industrious Poster Team Colleague Featured Poster

See if you can spot the reason. If you can't just ask. ;-)

import java.awt.*;
import javax.swing.*;

public class GridBagExperiment extends JFrame {
	JPanel redPanel, bluePanel, greenPanel, yellowPanel;
	double col1Weight = 0.4;
	double col2Weight = 0.2;
	double col3Weight = 0.4;
	double row1Weight = 0.4;
	double row2Weight = 0.6;

	GridBagConstraints gbc;
	Container container;

	public static void main (String args[]) {
		GridBagExperiment gbe = new GridBagExperiment();
	}

	public GridBagExperiment() {
		setSize (400, 400);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		container = getContentPane();

		redPanel = new JPanel ();
		bluePanel = new JPanel ();
		greenPanel = new JPanel ();
		yellowPanel = new JPanel ();
		redPanel.setBackground(Color.RED);
		bluePanel.setBackground(Color.BLUE);
		greenPanel.setBackground(Color.GREEN);
		yellowPanel.setBackground(Color.YELLOW);

		GridBagLayout gbl = new GridBagLayout();
		container.setLayout(gbl);
		gbc = new GridBagConstraints ();

		AddPanel (redPanel, 0, 0, 1, 1, 0.0, 0.0);
		AddPanel (bluePanel, 1, 0, 2, 1, 0.0, 0.0);
		AddPanel (greenPanel, 0, 1, 2, 1, 0.0, 0.0);
		AddPanel (yellowPanel, 2, 1, 1, 1, 0.0, 0.0);

		gbl.columnWeights = new double[] { col1Weight, col2Weight, col3Weight };
		gbl.rowWeights = new double[] { row1Weight, row2Weight };
		setVisible (true);
	}

	public void AddPanel (JPanel panel, int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty) {
		gbc.gridx = gridx;
		gbc.gridy = gridy;
		gbc.gridwidth = gridwidth;
		gbc.gridheight = gridheight;
		gbc.weightx = weightx;
		gbc.weighty = weighty;
		gbc.fill = GridBagConstraints.BOTH;
		add(panel, gbc);
	}
}
VernonDozier commented: Thank you. +12
masijade 1,351 Industrious Poster Team Colleague Featured Poster

here then

change

String indexAmount = JOptionPane.showInputDialog (null, "Please enter the amount of numbers you will enter");
         int pIndex = Integer.parseInt(indexAmount);

                while (pIndex <= 0)
                {
                JOptionPane.showMessageDialog (null, "That integer is not valid. Enter an integer greater than 0");
                indexAmount=JOptionPane.showInputDialog(null, "Enter the amount of numbers you will enter");
                pIndex = Integer.parseInt(indexAmount);
                }

to

int pIndex = 0;
         while (pIndex <= 0) {
             String indexAmount = JOptionPane.showInputDialog (null, "Please enter the amount of numbers you will enter");
             try {
                 pIndex = Integer.parseInt(indexAmount);
             } catch (NumberFormatException nfe) {
                 pIndex = 0;  // just to be sure
             }
         }
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Try making a "smaller" try/catch block (i.e. only around the "pIndex =" line).

Edit: And, that way, you can, of course, simply do nothing in the catch block (although you would, normally, at least log the fact that the exception occurred, even if you don't do anything about it).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Why a collection. Why not directly to a DB, or, worse case scenario, a file (i.e. randomaccessfile)?

In any case, 65k is not much. You could simply increase the maximum heap size.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Partly, both StringTokenizer and Scanner (in this case, especially, when reading a file) are not the fastest tools around. StringTokenizer, for one, is all, but, deprecated and shouldn't really be used, but there are more problems with that than just speed. And Scanner is great for verifying data types before reading and for automatically converting the string to the datatype you need as you read it, but with that comes a fairly large performance hit.

The other part though, was the fact that both the Scanner and the FileInputStream (with the only 1024 buffer size) were making far too many disk reads. A Buffered(Reader/InputStream) will fill it's buffer with as few disk calls as possible (usually one if there were no problems, and it has, usually, an, at least, 8k buffer), then your read calls are made against this buffer (automatically removing line endings when using readLine).

Ezzaral commented: Nice work. +19
masijade 1,351 Industrious Poster Team Colleague Featured Poster
package whatever;

public class Read {
    String DATE_FORMAT_NOW = "yyyy/MM/dd hh:mm:ss";
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
    long starttime = System.currentTimeMillis();
    String timeS = sdf.format(new Date(starttime));
    void readFile(String fileName) {
        System.out.println(">> time of exe: " + timeS + " milliseconds: " + starttime);
        BufferedReader br = null;
        try {
            br = new BufferedReader (new FileReader(fileName));
            int count = 0;
            String line = "";
            while ((line = br.readline()) != null) {
                String[] lineA = line.split("\\|");
                System.out.println(">> id: " + lineA[0]+ " >> flag: " + lineA[1]);
                count++;
            }
            System.out.println(">> rows: " + count);
            System.out.println(">>> elapsed time: " + (System.currentTimeMillis() - starttime));
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } finally {
            if (br != null) try { br.close(); } catch (IOException ioe) {}
        }
    }

    public static void main(String[] args) {
        String fileName = "\\Id.dat";
        Read r = new Read();
        r.readFile(fileName);
    }
}
masijade 1,351 Industrious Poster Team Colleague Featured Poster
if (number > largestSoFar){
        secondLargest = largestSoFar;
        largestSoFar = number;
      }

of course

And this, of course, will be removed

if (number < largest){
  if (number > secondLargest){
    number = secondLargest;
  }
}

You can also remove all current references to "largest" and then rename "largestSoFar" to "largest".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You want to assign "largestSoFar" to "secondLargest" before you assign "number" to "largestSoFar", but within the same if block.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Read the API docs for FileReader and see if some other method there is better.

Or wrap it in a BufferedReader, then read the API docs for BufferedReader and see if there is yeat another method there that is even better for your purposes.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Don't do it that way. That is Database specific. Read the API docs for DatabaseMetaData.

Ezzaral commented: Good point. +19
masijade 1,351 Industrious Poster Team Colleague Featured Poster

You can't. You would have to extract it and then execute it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Modulus. It produces the "remainder" from a division. I.E. 10 % 3 returns 1 and 11 % 3 returns 2 and 12 % 3 returns 0.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And, with the way the post reads, so do I. That is the reason it is formulated the way it is. The other is still an option though, which is why it was mentioned.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

When you add the keys, upper case them, and then uppercase the "search" key when retrieving one. Otherwise, you are going to have to loop through the keys yourself using equalsIgnoreCase to find the right key.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster

What are you using to compile?

If you are using an IDE, then you need to add that jar as a library in the project properties.

Edit: As that is the CLASSPATH for an IDE. The System CLASSPATH is good for almost nothing, anymore. Do the following concerning classpaths

1. When running from the command line without the "-jar" option use the -classpath option.
2. When running from the command line with the "-jar" option, you must configure the classpath in the manifest file properly.
3. When running/compiling from an IDE, you must configure the librarires in that IDE's project properties.
4. When running from a web container / application server you must place the jars in the proper locaions (see the manula for the web server / application container in question).

IDE's and web containers / application servers ignore the system classpath. When using the -jar option, both the System CLASSPATH and the -classpath options are ignored and only the manifest file's classpath is used. The only time that the system CLASSPATH is still used, is when running or compiling from the command line with neither the -jar nor the -classpath options.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

In Java regex, there is no reason to escape "/", and, if you do need to escape something, then you also need to escape the escape as the escape character also escapes characters in String, in general (i.e. "\\" every place you need a "\").

masijade 1,351 Industrious Poster Team Colleague Featured Poster
while (room.length() == 0)
  {
    System.out.println("Error: This field cannot be empty");
    System.out.println("Enter the name of the lab this computer is located: \t"); } // this } closes the while
  room = scan.nextLine();
} // so this brace closes the method

I am fairly certain your "first" '}' commented above shouldn't be there.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

One, remove that ";" at the end of the for loop declaration. That ";" ends the for loop.

Also, near the end of the block that is suppossed to be the for loop, remove that guesses++; . Using that statement you would be incrementing "guesses" by two through every iteration of the loop, as you are also incrementing it as part of the loop declaration.

Also, remove that int guesses; before the for loop and declare the for loop as for (int guesses=0; guesses < ichances; guesses++) . Notice that the int is declared in the for loop (since it not used outside of it this will restrict to the for loop), and use simply "<", not "<=", or you are giving them an "extra" guess.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

"jdbc:odbc:<DB>" not "jdbcdbc:<DB>"

You also need to configure your DSN (Google for that or ask at a Microsoft forum), and adding the Microsoft Access Driver does no good. Netbeans/Java is not using that, it is an ODBC Driver. Java is using the JDBC-ODBC Bridge which bridges to ODBC Drivers.

Now, all that being siad, if you want a DSNless connection (i.e. you don't want to have to configure a DSN on any system using the app), then do

"jdbc:odbc:Driver={Microsoft Access Driver(*.mdb)};DBQ=<full path to mdb file>;Uid=;Pwd=;"

Edit: The DB Driver (i.e. the JDBC-ODBC Bridge driver) that you do need to configure in Netbeans (instead of the Microsoft ODBC Driver) is "sun.jdbc.odbc.JdbcOdbcDriver"

masijade 1,351 Industrious Poster Team Colleague Featured Poster

As crazy (verruckt is crazy in German, which I assume crazy knows, but maybe it was just coincidence) says, it comes when there is nothing listening at the address:port combination that you attempt to connect to. That could be because the db is not running, or is not configured to accept TCP/IP connections, or is listening on a different port, or is running on a different server altogether, or that there is a firewall in the middle that actually rejects connection attempts rather than simply letting them silently drop.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

It prints that message because it is catching an exception and that is what you are telling it to print. Add a stacktrace to that catch block and try again, so that you at least know what is going wrong.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I agree, but it's not easy for a beginner.

No one said it would be. But the easy way is, often times, not the right way.

Yes, that's right. I don't know how common that would be with default installations.

Quite often considering the number of "unrecognised command" questions I've seen here, and on other forums.

I tested the code with a file on my desktop under XP, where the path includes two spaces. With the extra quotes around the absolute path this does work.

James

So in this instance it did, that doesn't mean it always will. Did you look at what getAbsoluteFilename returns? Does it return the "long" name, or the Progr~1 type name, in this instance?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Parsing a Jar is not hard however. Look at the JarFile class, it's getManifest() method. With that read the Main-Class Attribute, and the Classpath Attribute and build a URL array, and call new URLClassLoader with this array. And, you know, the only real path involved is the path to the jarfile, initially. It is actually quite easy, just need to make sure to cover all the bases, and nothing about the extraneous system changes any little piece of it.

P.S., by paths (in my previous post) I meant the PATH environment variable. If that does not contain the proper path, to the proper bin directory "javaw" (alone without the full path to the command) does not work.

Edit: Also, if there are spaces in that filename (or the path leading to it) be careful. The spaces (due to the way Runtime.exec operates) will cause problems, whether you use quotes or not. Those quotes are evaluated by system shells, and runtime.exec doesn't have one.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No, but PATH defintions are.

Runtime.exec and ProcessBuilder are tools of last resort, IMHO.

And, anytime they are used, it is truely only guaranteed to work on the system on which it was developed as long as no installation parameters have changed. Sorry, that's just the way it is.