JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I bet the OP has been waiting impatiently for the 7 1/2 years since he posted and then solved this problem, just in case you would come along with another solution. That's great. He can hand his homework in now.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This seems a stupidly designed Java exercise to me - let's do some cunning logic but no if tests? - but hey ho.
There must be mathematical formulae (using the ceil function) that evaluate to 1 if a variable is larger/smaller than some reference variable, and zero otherwise.
So if formula1 is a purely mathematical function equivalent to
(var-800 > 0)?1:0;
and formula2 is a similar one equivalent to
(2400-var > 0)?1:0;
If you code those formulae then you can use it as in
price = price + price*0.2*formula1*formula2;

I can' think what those formulae are, but I'm sure they exist, and there are an awful lot of very smart people on DaniWeb...

zeroliken commented: agree +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if(table.getSelectedRow()<0) // help required to implement this logic!!
{
JOptionPane.showInternalMessageDialog(rootPane, "Please select a row from the table first!");
...

At a quick look what you've got seems OK. What exactly is the problem with the code you posted?

mKorbel commented: +1 showInternalMessageDialog +11
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The code you posted calls a method resizeImage that isn't part of the standard Java API. I checked the original source and found it was part of that same program, but you didn't include it with the code you posted. Without that method the code you posted will not compile, thus cannot be executed, thus falls a bit short of 99.99%
It's no big deal.
J

ps: Constructive suggestion: new ImageIcon(...) is famous for not throwing any exceptions when it fails to find the file; it just returns null. JLabel is happy to accept null for its image icon, so the final result is no image and no error messages. We see that quite often in DaniWeb "help!" posts.
After a new ImageIcon(...) it's always a good idea to test for null and diagnose or throw an exception so you know what went wrong.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think you may be confused about how many classes there are?
public void paint(Graphics g){... is just an ordinary method in your Eyes class. Like any other method it can simply use the variables of that class, including the ints red, green and blue that were initialised in the constructor.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Decimal 49 in ASCII is the character '1'

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are many ways, but why not go with the easiest to follow and most generic?
create a boolean dataIsValid = true
if you find bad data set it to false
test it before writing to the file.

But in this specific case you could return; from the method immediately after reporting an error.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I guess propertyIDTxt is a text input field of some kind? In which case you should be testing its text, not the field itself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

if (propertyID.length < 1)
propertyID is an array, so you are just testing its declared number of elements.
I guess you intended to test the length of the String propertyID[numberOfPropertiesInArray]

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just Google - there's enough examples on the web, you don't need me to write another one!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That code was to get you started, it wasn't intended to be a complete solution. Nobody here will just give you the complete solution. You will find that it's very useful if you understand what it is doing, and how that differs from your use of nextByte().

thines01 commented: Widsom +11
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Normally you would have a stack where you can push values and operators as you parse them, and pop them when it's time time to execute each operator.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I looked at your files, now I don't understand your question!

how do I create a file with a list of all the words that can be accessed by an user input to verify if the word exists?

You already have that file

I dont know how to create or access this file through the main.

The code already has methods to read the file into memory, and check if a given word is present.

I know that I have to use equals or == to compare the input

The code contains an example of exactly how to do that

Maybe you need to read that code very carefully again - it seems to contain everythung you need.

Finally, when you have code to post, include it in your message and enclose it on CODE tags (highlight all the code and click the CODE format item above the message edit area). That way people can see the code easily, and with comments, constants etc colour-coded.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just set a java.util.Timer to run your method after an initial delay of 30 minutes or whatever.


@stultuske: what are you smoking? Did you miss something out of that code, or was it pure Monty Python?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

this should work 99.99%

Well, it might if it compiled more than 0% (uses method from original solution but not included in your 99.99% code).

stultuske commented: you are the 0.01% ;-) +12
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's good news. Well done!
J

emclondon commented: :D +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What are the actual decisions here? - static vs instance variables, and scope of local variables. All these are determined by the functional requirement of the program - they are not interchangeable so there are no "memory-related" decisions anyway.
Forget the variables, and just ensure that you keep no references to any objects that you have finished with.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

c0rthingy's? nice man, its not hard to scroll down and copy and paste a name hey

Please, I intended no disrespect. I did try to copy it, but it's harder than you think - you can't double click to select the word because that links to your profile, and its near impossible to drag through it without selecting all kinds of adjacent stuff.
Anyway, I apologise if I caused any offense.
ps: I get the "corrupt", but what does the rest mean?

DavidKroukamp commented: not a prob man +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you ddisplay an Object in Java, it calls its toString method. Every Object has a toString method because they inherit one from the class Object. That inherited method prints the name of the class and the Object's hash code (probably, but not necessarily its address). To display something more meaningful for your class, override toString. Eg

class Person {
   String name;
   int age;
   ...
   @Override
   public String toString() {
     return "person " + name + ", " + age + " years old;
   }
}
Twistar commented: Thank you, this solved my problem! +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just noticed you are using keyPressed rather than keyTyped, so you have a keyCode not a keyChar. KeyCodes relate to the physical keyboard, rather than to actual characters, so, for example you get keyChar 'A' from keyCodes <shift key> followed by <a>. Because <space> is a physical key, the previous code will work OK, but it would fail for 'A'. The correct way to test for a keyCode being the space key is

if (keyCode == KeyEvent.VK_SPACE)

Your lack of keyboard events is probably a focus issue - your listener needs to be attached to the component that has keyboard focus. This is often a problem! There is a better way to handle keyboard input like this, it's called Keyboard Mappings, see
http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html
... but it's quite a bit to adsorb at first, so you may prefer to sort out which component has the keyboard focus in your app.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to cast the result of the getClientProperty to the appropriate class, eg
(Boolean) getCli....
then, if you are on a version before 1.5, you need to get the boolean value from the Boolean object.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can pass a String containing any valid JavaScript expression or program and get it evaluated, returning the result to your Java program. This works because JavaScript is a dynamic language, compiled and evaluated at runtime. Requires Java 1.6 or later.
Eg:

ScriptEngine js = new ScriptEngineManager().getEngineByName("JavaScript");
      try {
        String condition = "a==b";  // expression to evaluate
        js.put("a", 2);             // value for a
        js.put("b", 3);             // value for b
        Object result = js.eval("var a,b;" +  condition + ";"); // evaluate expression with values
        System.out.println(result);
      } catch (ScriptException ex) {
          ex.printStackTrace();
      }

Sorry about the late reply.

Philippe.Lahaie commented: very interesting!! +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In this case they probably could use private methods, but the intention of the code is much clearer if they are constructors. It may also be the case that other ordinary methods in the class will call those constructors to create new Files, knowing that the parameters are valid. In general there are other differences between constructors and ordinary methods (eg initializing final variables) that may be relevant.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The code for File comments both those methods as follows:
* Internal constructor for already-normalized pathname strings.
In the File class the public constructors do some validation/pre-processing of their parameters, then call one of the private constructors to do the real work. They are private so nobody can call them directly and bypass the validation/pre-processing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

use putClientProperty to associate the row and column numbers with each button when you create them. In your ActionListener just use getSource().getClientProperty to get the row/col numbers for the button that was clicked. The documentation for these methods is, as always, in the Java API JavaDoc, and can also be found with Google. And no, I'm not going to write the code for you, but if you have a try and post what you have done when you get stuck I'll help you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can use a MouseListener to run your code when the mouse enters or leaves the frame, but I'm not sure whether that will work when the frame is hidden - you may need to have a transparent <something> in the place of the frame when it's hidden so that there's something to trigger the mouseEntered event.
When/if you find a complete answer please do share it with us here - I'd like to know.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, they are constants in the Color class. They look like this: public final static Color gray = new Color(128, 128, 128); You can use reflection to loop through all the variables in the class and select those which are public static final Colors - this code does that and returns a map of all the color names and the corresponding Color instances. Feel free to use it, as long as you leave the Author comment in place.

// get a map of all the Color constants defined in the Color class
   // Author: James Cherrill
   public static java.util.Map<String, java.awt.Color> getAllColors() {
      java.util.TreeMap<String, java.awt.Color> colors = 
         new java.util.TreeMap<String, java.awt.Color>();
      java.lang.reflect.Field[] fields = java.awt.Color.class.getDeclaredFields();
      for (java.lang.reflect.Field f : fields) {
         try {
            if (! java.lang.reflect.Modifier.isPublic(f.getModifiers())) break;
            if (! java.lang.reflect.Modifier.isStatic(f.getModifiers())) break;
            if (! java.lang.reflect.Modifier.isFinal(f.getModifiers())) break;
            Object o = f.get(null);
            if (o instanceof java.awt.Color) { 
               String name = f.getName();
               name = name.substring(0, 1).toUpperCase() +  
                      name.substring(1).toLowerCase(); // convert to title case
               name = name.replace("_",""); // de-duplicate Light_gray and Lightgray
               colors.put(name, (java.awt.Color) o);
            }
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
      return colors;
   }
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

~s.o.s~ is there any particular reason for not using

while (!Thread.currentThread().isInterrupted()) {
  // do something
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Which of these rules am I violating on line 23 where I get the error message? I'm just trying to create an instance of class like I always do. What is the non-static variable that the compiler is complaining about?

It's the inner class Counter, which is not static. So new Counter(); is trying to reference the non-static class Counter. This tutorial may help clarify this (to be honest, rather obscure) problem.
http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The join statement won't be executed until "some heavy work" is finished anyway, so the timeout won't be useful. I think you need to start a second thread (or just a Timer) that waits for timeout milliseconds, and use that to terminate your work thread if necessary.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As always, it's hard to beat the official Sun/Oracle documentation for Java
http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html

zeroliken commented: C +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

...neither should you make a program that continuously creates a new instance every time a new panel is added - what would happen if I'd open 1000+ panels at the same time (it would get really slow if you don't get a heap overflow).

Let's be sensible here. Each panel will involve a number of instances of Swing classes, so anything you do with your own classes will be pretty much irrelevant. As for 1000+ panels - why don't you leave that problem until something suggests you will encounter it. How many panels do you expect?
Remember also that in the end you have to create enough "stuff" to handle the requirements of the application. Much of this "stuff" will have multiple instances. The smaller your classes, the less the redundant "stuff".

Here are some of the classes I'd expect to see in an app like this:

Client:
Main class - app startup and controller (one instance)
Network comms class - handling sockets, connections etc (one instance)
Main window (one instance)
Conversation panel (many instances)

Server:
Main class - app startup and controller (one instance)
Socket listener (one instance)
Connection handler (many instances)
Main window (one instance)
Conversation panel (many instances)

Plus numerous inner classes for ActionListeners etc

... but when developing the code there will probably be other service classes that emerge from the detailed design, such as (maybe) User - encapsulates info about …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If I can make a suggestion...
There's a lot going on here for a beginner. Why not break it down into easy steps that you can work out one at a time:
1. Write, test and debug a version for numbers 1-19 only.
2. When that's working, enhance it to do numbers 1-99
3. When that's working, enhance it for the full range of numbers.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have code to split out the RGB values from each pixel, so now you need some similar code to combine RGB values into a single int pixel. Between splitting them and re-combining them you can set r, g, and/or b to zero.

Or, you can use bi.getRaster().getDataBuffer(); to get direct (RW) access to the pixels, so you can modify and replace them one at a time. You can use & to zero out individual bytes each pixel.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

int[] arrNumbers = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};

ie arrNumbers == i+1

really?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

According to http://compilers.iecc.com/comparch/article/01-03-037 it's LL(1), recursive descent

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... in.read() method returns a string ...

Absolutely wrong.
You are advising a beginner here, so it's essential that you get your facts right. It's unacceptable to create this kind of confusion. You should check your code and your facts before posting.
You should also read the previous entries - the OP's problem was confusion between the numeric value of a char and the letter it represents. By confusing int with String you are just making things a lot worse.

NormR1 commented: Better, you thought about it, I reacted w/o thought +13
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Probably there was something wrong with the file path/name that you typed in.
You could print out the user's input so you have a record of what the path/file name were.
Rather than using
System.err.println("Error: " + e.getMessage());
in your catch block, use
e.printStackTrace();
which will give you much more info on exactly what and where the problem was.

JavaPrograms commented: Great solution! +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Every time you read a line you call displayText, in which you create and add a new TextArea.
You should create the frame etc with a single text area when the application starts, and just add the String to that existing text area in displayText.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

return printer(s); calls printer(s) again, which executes down to the last line where it executes return printer(s); etc infinitely

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just one variable for each kind of boat, and re-use it for multiple new boats.

"Again I get the error" I guess you know what you mean, but I don't. The boats will be stored in the list in the order that you add them.

ps: I'm finishing now. See you next week. Good luck
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, no, that's exactly the wrong thing to do, and that's why "in the output I get same values".
static means there is just value for that variable, and all the instances share that one value. You don't want that, you want each instance to have its own colour and length

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You test for 'e' as a consonant. Did you mean 'w'?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

R32@
This is just a question, because I don't know what you have or have not been taught yet, but did you consider an array of Employees, into which you can store instances of a SalariedEmployee or the other two subclasses?

Employee[] allEmployess = new Employee[100];
allEmployess[0] = new SalariedEmployee...

I'm asking because the way you have it now, with one big Employee class containing arrays for fName, lName etc isn't going to work well with polymorphism and subclasses.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Anything(eg arrays) you create in your Java app is lost when the app terminates. To save data for later use you need to write it to a file or a database. Probably the easiest is to write in in text form (same as printing) to a text file. Google will give you lots of examples and explanations.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like your paint method should loop thru all the shapes in shapeList drawing them, not just the latest one?
ps don't override paint(Graphics g), override paintComponent(Graphics g)
http://java.sun.com/products/jfc/tsc/articles/painting/

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In your valueChanged method ev.getSource() will just be the list box itself, which you probably knew anyway. You can use list.getSelectedValue() to find out which object in the list is currently selected inside your valueChanged method.

ps @stultuske: in this particular case both getSource and getSelectedValue return the actual object in question, so an == test is appropriate.

stultuske commented: learning every day :) +12
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is a common symptom, and the usual cause is that Java is looking for the icon files in the wrong place.
new ImageIcon(iconName) will not throw an exception if there is a problem, it just returns null. If you pass null to a JLabel or JButton for the image icon that also does not throw an exception, it just doesn't display an image. So the net effect is that if there is a problem reading the file you get no error messages, you just don't see the image.

You can use this little fragment to see where Java is looking for your files:

java.io.File f= new java.io.File(iconName);
System.out.println(f.getAbsolutePath());
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe those method definitions belong in the class they apply to, ie in Student there is a delete(Student s) method, in Course there's delete(Course c) etc etc. (These should probably be just named delete() defined as instance methods.)
In a typical controller class you will call those methods, but not define them.
If there's significant duplication between the methods in all those classes then consider inheriting them from a common superclass, or using a low-level utility class or classes that they all call on for common functions (eg database updates)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, because an Enumeration and a String are completely different things; you can't just cast one to the other.