JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Class structure looks dumb to me. 2Dice is not a "kind of " Die.
It would make more sense to have a (non-subclassed) class called "HandfullOfDice" that took an int numberOfDie as a param on the constructor, had a list of Die objects as an instance variable, and had public methods like rollAllDice and getTotalScore etc.

majestic0110 commented: agreed +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Add some instance variables to your class (eg a list of shapes, colours, positions ...). Add some public methods to set those variables. Use the variables in paintComponent method to control what/where/how you paint

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Was this a question, or just some insane light show?

jokers6 commented: HAHAHA ! +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
int numStudents; //number of total students

public static void main(String[] args)throws Exception {
  ...
  numStudents = inFile.nextInt();

>>> non-static variable numStudents cannot be referenced from a static context

numStudents is not static, you use it in a static "context" (method) >>> error

VernonDozier commented: Some good comments on this thread. +13
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have lost your import for java.util.*, which is where Scanner is defined.
You still declare inFile in main, despite all that was said.
You now declare a String called inFile in your class. That's really confusing.
Finally
Your methods are static, which means they execute inthe context of the class itself, without any particular instance of the class.
You declare variables without the static keyword, so they belong to individual instances, so they cannot be used in static methods where there is no instance. That's why you get "non-static variable n cannot be referenced from a static context". Static methods need static variables.

jon.kiparsky commented: Couldn't have said it better. +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Of all the layout managers GridBagLayout is by far the most capable. There's a bit of a learning curve because there are so many options, but IMHO it's worth it. You can play with the easier ones for little homework apps, but if you are going to use Java seriously then sooner or later you will end up using GridBagLayout. Why waste time mastering the others? I say go for it!
http://download.oracle.com/javase/tutorial/uiswing/layout/gridbag.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a look at
http://download.oracle.com/javase/tutorial/uiswing/components/table.html#renderer
in particular the section "Using Other Editors" that starts quite near the bottom...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All java parameters are call-by-value. (Remember that all variables that are not primitives are references to Objects, so it's the reference that's passed by value)
So in your example on line 3 parameter is a reference variable that contains a copy of the reference that was used in calling the method. Line 3 changes the value of parameter, but it has no effect whatsoever whatever was passed to the method. It is therefore impossible for a method to change the value of anything passed as a parameter.
Despite that, given a (copy of) a reference to some Object, a method can still modify the Object whose reference was passed, if that Object has mutator methods or public variables.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

According to the Language Ref 15.18.1
"Hello" + intArray
is evaluated as
"Hello" + (new Integer(intArray)).toString()
ie primitive types are boxed and the resultt of toString() on the boxed value is concatenated.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think 2118789 is the object. as I was suppose to store the player's info such as age,weight,height,games played and goals scored. and using the club class I was suppose to fetch a player's info using his name. the thing is, it only fetches the name and 2118789 instead of the supposing objects. Player stored are the objects.

Read jon kiparsky's post again. He's almost certainly right.

jon.kiparsky commented: Gee, that's nice to see first thing in the morning. :) +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java DB (a version of Apache) is bundled with the JDK from version 6 onwards and is guaranteed compatible, supported by Sun/Oracle, free, and runs on the same platforms as Java itself (apart from some Java ME versions). It's a safe choice and all you need for small-medium apps.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A very good reason for not just copying code snippets from the web!

catch blocks contain the code you want executed when an error is detected. An empty catch block says "I don't want anything done about any problem, don't tell me about it, I don't want to know". There are some circumstances where that's right, but normally not.

If you have no better idea, it's a good idea to just put
e.printStackTrace();
in the catch, eg:

catch(Exception e) {
   e.printStackTrace(); 
}

That will print a complete explanation of what the error was and where it happened.

cwarn23 commented: Excellent reply and easy to understand :) +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

An instance of the Class class represents a class in your program. Using that instance you can find and access all the attributes of that class (variables, methods, annotations etc etc). Its used as part of Java reflection (that's the keyword to Google), which is used to find out the attributes of a class at runtime because you don't know them at compile time.
Here's a good place to start
http://download.oracle.com/javase/tutorial/reflect/index.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your overall approach, with the public getData is good. The problem lies in

FormA page = new FormA(); // displays a new copy of the form
String user = page.getData();  // gets the data immediately - before the user can enter anything!

Somewhere you should have a button or some such that the user presses after entering the data, and that's when the call to getData needs to be executed. Either formA needs a reference to formB, or formB needs a ref to the existing formA for that to work (ie you need to call getData on the existing form, not a new one)- details depend on exactly how you have structured the rest of your code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. To use Button's getLabel() method you must cast the Object returned by getSource() to a Button
2. You can't compare Strings with ==, use equals(String) instead, if you must.
3. If you want to know which button was pressed, test that directly

if(  (ae.getSource() == ok) ...

just remember to declare ok as

final Button ok = new Button("ok");

in your class, not in the init method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Use an AlphaComposite to set the drawing mode and alpha before drawing your image. Here's a simple sample...

Image myImage = ...
float alpha = 0.5;
@Override
public void paintComponent(Graphics g) {
	Graphics2D g2D = (Graphics2D) g;

	AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
	g2D.setComposite(composite); // Set current alpha
	g2D.drawImage(myImage, 0, 0, null);
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@ztini is right.
But if you can't do that for some reason then you can enhance your sort methods to sort both arrays at the same time, eg
in sortGradesByNames you swap elements with

int temp = grades[largest];
grades[largest] = grades[i];
grades[i] = temp;

so then, in the same place, you need to swap the same elements in the other array to keep them in step

String temp = names[i];
names[i] = names[smallest];
names[smallest] = temp;

but really, make a Student class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like you're at a dead end here. You can't do this kind of thing without a least some of the right tools. All I can suggest is either find another project to do on your current PC or find another, less restricted, PC to work on.

zach&kody commented: Thank you for your help +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I made leftSide a container and that worked. I didn't realize that I hadn't done that in the first place. Thank you very much.

OK, glad to help. Mark this solved?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

firewall problem and/or a router problem ... Do you know how I can fix this?

Sorry man, that depends on exactly what hardware & software you are running in exactly what configuration. I'm not best person to ask. There are loads of excellent sites on the web dealing with network config issues like this - it shouldn't be hard to find some relevant instructions.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Second problem sounds like a firewall problem and/or a router problem blocking and/or not forwarding inbound traffic.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

leftSide is the contentpane for the window (previous listing line 5)
bothSides is also the contentpane for the window (previous listing line 14)
so on line 17 you are trying to add the content pane to itself, == error.

At a guess, leftSide should be a new container.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just a guess... but maybe your import statements have the wrong package name? I suspect that should be org.junit...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could add a layer instance variable to the cube class, then in the paintComponent (not paintComponents, not paint!) method sort the cubes on the layer variable before painting.
Or
Keep another list of cubes, this one in layer order. Shuffle the list when you want to change a cube's layer.
Or
Combine both for maximum efficiency

paycity commented: You solved my problem with your great ideas. Rock. Thank you! +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. x=0; is an assignment statement that can only be used in a method or constructor, so you can't just have it in your class like that. You can use an initialiser as in int x = 1;
2. Making the object of the class dabba in the dabba class's main method is a very common and standard thing to do. No problem.
3. x is an instance variable; it only exists within an instance of dabba, and every instance has its own value. So to print x without specifying which instance you want just doesn't make sense.

ps: No need to import java.lang - its always automatically imported
pps. Class names should begin with a capital letter (Dabba)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
public Person(int age) throws Exception {
  if (age <= 0) throw new Exception("Age must be positive");
  this.age = age;
  (etc)
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In your method you have access to the size of the current CyberPet, and you also have access to the size of the other CyberPet that is passed as a parameter, so you can write a couple of if tests comparing those two things to decide what String to return. You may be looking for something difficult, but this is more simple than you realise.
Here's a starting point:
you method signature is invalid. It should be something like
public String encounter( CyberPet other )

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ME is the Micro Edition - specialised version for smartphones etc
SE is the Standard Edition. It's all you need for ordinary desktop apps and applets and is (roughly) a superset of ME.
EE is the Enterprise Edition - for large-scale corporate client/server/database apps - it's a superset of SE


Most people start with SE, unless they have a good reason to do something different.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This from the junit FAQs may help?

How do I install JUnit?

First, download the latest version of JUnit, referred to below as junit.zip.

Then install JUnit on your platform of choice:

Windows

To install JUnit on Windows, follow these steps:

Unzip the junit.zip distribution file to a directory referred to as %JUNIT_HOME%.
Add JUnit to the classpath:

set CLASSPATH=%CLASSPATH%;%JUNIT_HOME%\junit.jar

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It only does what you tell it to do! You haven't written any code to display anything.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Beware: the link you found is to source for the Apache "harmony" project, which is an attempt to build a fully open-sourced alternative to Sun/Oracle's original Java; it's completely new code.
There has been stupid and destructive political infighting about this, and it seems unlikely that this version will be able to get certified (unfortunately).
Its very likely that the code you find there will execute to give the same results as Sun/Oracle Java, but its not the same code. In particular it has less in the way of comments compared to Oracle version.
Here, for example are the two versions of the same method in ArrayList - first Apache:

/**
  615        * Returns an array containing all elements contained in this
  616        * {@code ArrayList}. If the specified array is large enough to hold the
  617        * elements, the specified array is used, otherwise an array of the same
  618        * type is created. If the specified array is used and is larger than this
  619        * {@code ArrayList}, the array element following the collection elements
  620        * is set to null.
  621        * 
  622        * @param contents
  623        *            the array.
  624        * @return an array of the elements from this {@code ArrayList}.
  625        * @throws ArrayStoreException
  626        *             when the type of an element in this {@code ArrayList} cannot
  627        *             be stored in the type of the specified array.
  628        */
  629       @Override
  630       @SuppressWarnings("unchecked")
  631       public <T> T[] toArray(T[] contents) { …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The contains method is defined as having an Object as param to make it suitably universal, so it does start by checking the type of the param against each element and goes no further if the types don't match.
Since Java 1.5 you should always specify the type of your Collections eg
ArrayList<URL>
which will (a) ensure you don't put anything incorrect into it and, more usefully, (b) when you retrieve anything from the list the compiler already knows what type it and you don't need to cast or toString() them.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The ArrayList class has a boolean contains(Object o); method that returns true if the ArrayList already contains this Object, so you can use this for your if(newurl is not in visitedarray) test.
The test used to see if Object o is already in the ArrayList is o.equals(any element in the list). So you need to ensure that the elements you are putting in the list have an equals method that works the way you need. The API doc for URL (or whatever other class you are using) will explain how it implements equals. If it's your own class, then its up to you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What version of Java are you using? It's OK with current versions of 1.6.

tunlinaung commented: Useful post +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Nobody else has answered so, despite the fact that I've never actually done this myself, there's nothing to lose by having a go!
The doc says that JavaFX can use Java classes, so in theory you should just be able to call the Java System.getProperty(p); // where p is "os.name", "os.version" etc. Even if you can't. for some reason access System directly like that you should be able to create a tiny Java class of your own that just wraps those calls, and use that from JavaFX
If this is rubbish, please just ignore it.

ps Just looked a bit further and it looks like you just have to import java.lang.System; and you're good to go.

pps: public class javafx.lang.FX also seems to support public static java.lang.String getProperty(java.lang.String key)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

JLabel doesn't allowed custom painting

Not true. You can subclass JLabel and override paintComponent just like any other Swing JComponent. This is a recommended practice if you just want a single custom painted object without any children, especially if that is to be painted on top of something else.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hello again.
I don't know what this is about - where does this code come from?
TextFileIndexer and searchIndex are not classes, they are methods. They will be defined inside a (or two) classes, but that info is not in your post.
INDEX_COLLECTION is not a variable, it's a parameter that has to be passed into the TextFileIndexer method. You can't "get it". You have to look for where that method is being called and see what value is being passed in.
Sorry, but without a lot more info on what this is all about I don't know what other help I can give.

ps: This seems like a completely different problem from the ArrayList / TreeMap thing we were discussing before. Maybe you should mark this thread as "solved" and start a new one for this new problem.

kekkaishi commented: such patience. kudos. :D +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Paint paints the component, any children in that component, and any frames, borders, decorations etc - everything related to the component. If you override it you can suffer from vanishing borders etc.
paintComponent just paints the internal direct content of the component, so you override that and all the borders/children etc still get handled properly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

one more question regarding the hashmap

So this is this morning's quota answer:
re-read previous posts. I told you repeatedly what to do with your HashMaps, and asked repeatedly for clarification as to where the duplicates were happening (which you never answered properly). There's really nothing I can add regarding your duplicates at this point.
Either use your IDE's step execution / variables tracing, or add lots and lots of print statements to your code so you can see for yourself what's happening.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hang on, this is going wrong, and it's my fault.
It's essential that you develop your own skills in analysing problems, researching, reading the API, and trying& debugging solutions. What's happening here is that you are asking me before exhausting those processes, and I'm encouraging that by answering too quickly.
For you own benefit I'm going to limit this to one question/answer per morning or afternoon (excluding follow-ups for clarification only). Sorry if that sounds harsh or unkind, but it's time for you to fly on your own wings.
J

jon.kiparsky commented: Your patience is admirable. +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The other thing that comes in here is the Java package structure - so if one of your desktop .java files imports (for example) jcode.SomeClass, then the compiler will search for a jcode directory in the classpath and look inside there for SomeClass.class or SomeClass.java. If it only finds the .java it will compile it.
See http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html - in particular the section headed "SEARCHING FOR TYPES".

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The only way I know is HTML, but that's really easy - eg
myJLabel.setText("<HTML><This is a test<BR>on two lines</HTML>");

HelloMe commented: straight to point with example +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have two challenges - first to think through the logical process you need, second to translate that into Java code. You can't start the second until you've completed the first.
So the best thing you can do is to set the PC aside, grab a pencil and pad of paper, and work out how you would do this manually.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To keep DaniWeb a student-friendly place to learn, don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
catch (IOException e) {}

That is a big mistake.
If there is any problem locating or reading the file, you have opted for Java to do nothing and tell you nothing. How can you debug that?

catch (IOException e) {e.printStackTrace()}

will ensure that you have a proper full explanation of problems that arise.

jon.kiparsky commented: Damn straight +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Move as much code as possible out of paint(...) - eg read the image file or create the new Font just once at startup, not on every call to paint(...).
How and how often are you updating? You should be using a javax.swing.Timer to call update the heading then repaint() pretty frequently, eg 50 mSec

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

//this would make change to be 0 because 4/1000 * 1000 is 4. (original value of change). 4-4 is 0.

Just to avoid any possible confusion here...

4/1000*1000 is not 4. Evaluation is all integer, left to right, ie
(4/1000)*1000
4/1000 in integer arithmetic is 0, so the intermediate value is
(0)*1000 which is zero.

4.0/1000*1000 is 4.0 because the arithmetic is done in float.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe you forgot to covert degrees to radians for the Math. methods?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. Your print expression has one correct + operator, but it needs two!
2. You define and create your arrays inside the loop, so each iteration of the loop creates and destroys a new set of arrays. You need to define and create them before starting the loop so that each iteration of the loop is working with the same arrays.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Don't have it in front of me now, but its part of the support for the vista/w7 sidebar. sidebar.exe is also a COM automation / activeX server that gives access to stuff that sidebar gadgets like to display, and battery power info is in there as well. I found jscript gadget examples that accessed System.Machine.PowerStatus.batteryPercentRemaining from that COM interface.
I guess the rest is just plumbing, although there's maybe some implicit bit of initialisation that Gadgets have that will also be needed.

peter_budo commented: Thanx for info +16