JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hmmmm... curious.
Can you create a small stand-alone version that demonstartes the problem so I can try it here?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you explicitly set a null layout manager for the container "this"?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you sure all the positions are different? Maybe print them out to confirm.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What's wrong with myLong * myLong ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe it's Character vs char. The generic type is Character, but you try to put a char. Autoboxing will often deal with this kind of thing, but not always, maybe this is one of those times? Try put(new Character(...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just add lots of print statements to see where that value is going missing.
ps: Yopur code seems to mix reading chars vs writing ints, and Data IO streams vs ordinary IO streams. That's a formula for confusion. Stick to one type of stream (eg ordinary) and one data format (eg String).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Scanner nameinput = new Scanner(System.in);
name = nameinput.toString

You are trying to use the Scanner itself as a name! You're supposed to read the name using the Scanner.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't think you have access to the actual CPU time, but if your program has no I/O, and there's nothing else running on the machine at the same time, then for most purposes you can assume CPU time == real time.
(ie, roughly, real time = CPU time + I/O time + time taken by other processes)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just pass the Buffer object like any other parameter

 public Reader(Buffer b) {
     ...
     // use b to access the Buffer's methods and variables


 Buffer myBuffer = new Buffer();
 Reader myReader = new Reader(myBuffer);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

WriteOnPanel is (correctly) an instance netrhod, so in your "other" class you need a reference to the instance of LabelStatus that you want to use when you call that method. Somewhere in your code you will create a new LabelStatus object, and you need to pass that into your "other" class, eg as a parameter in its constructor. Exactly how/where you do that depends on how your code is structured overall - so I can't be any more specific.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I suspect that every threaded implementation could be replaced by a sufficiently cunning non-threaded version, so the question is "when are threads useful?" rather than "when are they necessary?".
For your people running about it may make sense to have one thread for each person in that the code is simpler - for example you can simply wait for the person to run into a wall without having to worry about ether some other person may run into a wall sooner.
In short, threads are typically useful when you want one thing to carry on while another is waiting for something. Speed doesn't really come into it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's the code I used in a tutorial a while back to illustrate some of the techniques for exactly this kind of app. The lecture "notes" were all in my head, so the code is all there is. I'm posting it here in case it turns out to be useful for you. Don't try to use it directly, but you may find the coneceptsd it employs useful in your own design. I'm happy to answer any questions.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

/* Runnable demo of Java techniques for an electrical circuit design application
 * has NAND gates with connections etc and a drag'n'drop GUI
 * Main classes:
 * Component - abstract class for gates etc. Has inputs & outputs and a drawing method 
 *   NANDGate - concrete Component - you can create others for NOR etc
 * Connector - abstract class for inputs and outputs
 *   Input, Output - concrete Connectors
 * Connection - joins two Connectors (joins one Input to one Output)
 * 
 * These classes have the logic for GUI interaction (dragging, selecting Connectors etc)
 * but also have the potential for simulating the actual circuit behaviour.
 * 
 */

public class CircuitDesigner {

 // NAND gate drag'n'drop demo with connections etc

 JFrame frame = new JFrame("drag demo");

 ArrayList<Component> …
v3ga commented: Thankyou. This way is much easier than using java.awt.dnd +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I built a lttle training demo on exactly this theme a while back, and it's not easy for someone who has "just started learning Java". You're going to have to build some specific skills and cod techniques first before you try to put them all together into this app. I suggest you start by building an app that has a window with a simple square drawn on it that you can drag around with the mouse. If you want to take this kind of step-by-step approach I'm happy to guide you through it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You overrode paint so you lost all the stuff that normally happens when a JFrame paints itself. Just start your method with a super.paint(g) to get all that stuff painted before you add your own drawing.

jackbauer24 commented: It works now, thanks! +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have lost the original if tests on bgColor and textEditable. You need them both...

if (this is the disable button) {
    if (disableText) {
        disableText = false;
        inResult.setEditable(true);
    else {
        disableText = true;
        inResult.setEditable(false)
    }
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your second and third if tests should look like the first one
if(evt.getSource().equals(theAppropriateJBUtton)
then inside those if blocks you can test bgColor or disabledText as appropriate

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Well. exactly like that! The parameter is a perfectly ordinary array of Strings that you can access or index just like any other array.
Eg

for (int i = 0; i < arg.length; i++) {
    // do stuff with arg[i]
}

or

for (String s : arg) {
    // do stuff with s
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

(Class name should begin with an upper case letter)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to loop through the argument array and search for each element in turn.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

string1 == string2 tests for those being exactly the same object (both have the saem memory address), which they're not in your case.
The equals method for Strings tests if two Strings contain eactly the same sequence of letters - which is what you need. You'll find the documentation for equals in the API doc for the String class (as always)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Because all you need isn HTML link to run it in your browser?
ps: Swing works in applets as well...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your diagnosis sounds probable to me.
Rather than using invokeLater in the constructor, why not move that up to startGame() so all the startup code runs on the same (swing) thread?

DavidKroukamp commented: Thank you James, that was spot on +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I assume you have variables for its position and velocity that you update at regular intervals (Swing Timer) - in which case just add a fixed amount to the (downwards) vertical velocity component on each update. This will result in the downwards speed increasing steadily - just like g.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

http://en.wikipedia.org/wiki/String_interning

I've never heard of a reason why you would force allocation of a new String object with new String("daniweb" as opposed to allowing the compiler to intern it, and right now I can't think of a single reason why you would want to do that...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yeah, the edit button is only available for (I think) 30 mins after the original post. Anyway, don't worry, it's OK.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe an edit to explain why/how that code works - but don't worry, there's no harm done this time. :)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi kolibrizas
Your help, advice, and assistance are very welcome here. But please don't just post solutions to people's homework for them to copy & paste. All they learn from that is how to cheat. Give them guidance that allows them to learn how to do it for themselves. Thanks.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK! Please mark this "solved" for future reference. Thanks J.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You declared MyClass inside MyOwnBM, and you didn't declare it static, so it's just like any other instance member - you can't refer to it without an instance of the MyOwnBM class. See
http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
Unless MyClass needs direct access to instance variables from MyOwnBM, just declare it static, or declare it outside MyOwnBM.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I haven't studied your code enough to see why. But is you really need that extra panel just add it

public CryptoMainMenu()
   ...
   add(primaryPanel);

the getContentPane fails because panels don't have, or need, content panes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why do you have primaryPanel at all? CryptoMainMenu is a panel, so just do the layout and add the button directly on that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think the error is is the (int) cast of the Object returned by the get(...) method, not in the char to Character conversion.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. Declare and initialise your ArrayList as as ArrayList of Games to avoid casting and possible errors ArrayList<Game> theDB = new ArrayList<Game>(); 2. htScore is already an int, so there's no need to use Integer.parseInt - that's just for where the data is in a String. homesum += theDB.get(i).getHtScore(); where getHtScore() is a public accessor method that returns the value of htScore.

3. No need to keep a counter, you can use theDB.size()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

remove, not Remove - Java is case-sensitive.

HashTable takes only objects for key and value - your code relies on auto- boxing/unboxing to convert between char and Character, int and Integer. Your int cast on line 6 is probably interfering with the auto-unboxing

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you mean you want random numbers 1-3 rather than 0-3? In that case, something like:
myArray= 1 + (int)(Math.random()*2);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

int[] myParrot = {1,2,3}; // simpler

You can use Random to generate random numbers. I donlt kniw what you mean by "a given set of numbers"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

another way to specify the current L&F is to use the swing.properties file to set the swing.defaultlaf property. This file, which you may need to create, is located in the lib directory of Sun's Java release (other vendors of Java may use a different location). For example, if you're using the Java interpreter in javaHomeDirectory\bin, then the swing.properties file (if it exists) is in javaHomeDirectory\lib

http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html#properties

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

...One thing your code does that might not make sense: It changes the interest rate and the term at the same time
How many combinations of computations do you want to do?.

The spec says: "Modify the mortgage program to display 3 mortgage loans: 7 year at 4.35%, 15 year at 4.5 %, and 30 year at 4.75%."

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, and that^

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Exactly the same way you do now. Just change print to printf and add the format specifications as the first parameter

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, you just need to enhance them a bit to include formatting info. When you print to your printstream you need to use the printf (formatted print) method rather than the ordinary print method. Then you add one new parameter, which is a format specification. Eg

print(name); // prints the contents of name without any formatting
printf("%-8s", name);  //prints the contents of name left aligned in a column 8 chars wide

That example format works like this:
% this is a format item
- left-aligned
8 column width
s string format

Just try executing these two lines to see it working in pratice:

System.out.printf("|%-8s|%5s|\n","hello", "me");
      System.out.printf("|%-8s|%5s|\n","goodbye", "you");

Google java printf for lots more examples

ps You don't need to create new PrintStream for every print, just create one at the start and use it for all the print/printf calls.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have missed a semicolon on line 143.

(No, not really, but what on earth do you think anyone is supposed to do with anything as unhelpful as "Still not working"?)

stultuske commented: aaah ... well placed sarcasm :) +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you use printf then you can specify the formats for the printed items, including their width. If you set the width for each field >= longest actual data then the columns will line up (assuming you display them with a mono-spaced font like courier).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Typically the OK button's action handler looks something like this

actionPerformed...
   String name = nameTextField.getText();
   String dateOfBirth = dateOfBirthTextField.getText();
   insertInstance.insertPerson(name, dateOfBirth);

and the method to do the insert in the Insert class looks like

public void insertPerson(String name, String dob) {
   ... insert name amd dob into database
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No problem. Please mark this "solved" now.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I haven't time to read all that code, but normally in the actionPerformed you would get the text from the local data entry fields and pass those values as parameters to the insertBotton method. That way the insert class doesn't need to know anything about the data entry fields or any of the variables within the product class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The } on line 43 closes the else {, so the print on line 45 is always executed.
If you indent your code properly (use a programmer's editor or simple IDE) then this kind of mistake becomes very obvious.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, I only use Eclipse... it has so many "industrial" users that it has to be solid.

After 6 ticks you can cancel() the current Timer and prompt the user again.
When the user types yes (as in your code above) call its schedule() again

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You don't stop the timer, so why are you talking about restarting it?