BestJewSinceJC 700 Posting Maven

Heh. That invalidates everything I just said about customizing the buttons, I didn't realize they already had one with the buttons yes and no on it. *hangs head* ....

BestJewSinceJC 700 Posting Maven
boolean validChoice = false;

while(!validChoice){
//Get the user's input, if it is y or n, set validChoice to true.
}

You said you "need exception", do you mean you want to throw an exception? If so there are a few ways you can do that.

edit: I just realized you're using GUIs to get the input, in which case, James' code is obviously better since it lets the user input through a GUI. There is also a lot of information here showing you how to force the user to input either yes or no (the window won't close until they choose one or the other) and there is an example here of how to put the buttons yes and no on the window. So obviously, combining those two ideas, you can force them to input either yes or no with no loop if you really want to do that.

BestJewSinceJC 700 Posting Maven

Are you doing a Huffman Coding project? If not, I don't see the purpose of what you're doing. (In other words, if you aren't doing Huffman Coding, then what do you mean by 'chunk the file bytes into a certain size before writing'? .... I don't see how you'd know what characters they represent once you wanted to open the file for reading again.)

BestJewSinceJC 700 Posting Maven

And why not use a flux capacitor?

42.

Also, I missed something here, because I was going to answer "You use the malloc function to dynamically allocate the array's memory. ." or something along those lines. Anyone care to clarify?

BestJewSinceJC 700 Posting Maven

I don't understand the second half of your explanation, so hopefully this is useful to you. File class: http://java.sun.com/javase/6/docs/api/java/io/File.html

For example you can easily create a new file using the createNewFile method. There are plenty of useful methods in there.

BestJewSinceJC 700 Posting Maven

Aren't there some potential repercussions from using these programs?

If the program is freeware, than the only potential repercussion is that it might be illegal according to Windows to bypass their OS to change your password. But you don't need to worry about that. Nobody cares about changing your own password. So basically. . no

BestJewSinceJC 700 Posting Maven

Post the relevant code -- the part that is getting the error -- and tell us where the error is occurring. Just paste the error in here.

BestJewSinceJC 700 Posting Maven

Thoughtcoder: You're really going to give me bad rep for giving you bad rep? Wow. I'm not going to make any more negative comments about you, but like I said, you should be more considerate towards other people. I'm done with this.

BestJewSinceJC 700 Posting Maven

Why are there so many spaces between the last 0's but not between the first numbers? In your other post, there are much fewer spaces. Perhaps you should identify some patterns in the input file before attempting to produce the corresponding output file. Either way, I don't really understand what your rules are for the output file; as far as I know, it's a random number of spaces, so I'll stop wasting your time. It seems like James knows whats going on here though so you'll just have to wait until he gets back on. Good luck & happy coding.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

The number of spaces you put before each number needs to be based on the length of the number. So you have to get the length of the String that you want to print out and do some sort of subtraction to figure out how many spaces you need to put before it. Can you post your print method? Also, are these the rules for the output file:

1. there must be at least one space between each column of numbers in the output?
2. The number of spaces between two columns is 3-(number of digits in the second column)?

BestJewSinceJC 700 Posting Maven

I didn't know how to access the class held another class, from that class that is held.

That does not make any sense. Try to clarify?

The problem now is, when users start working in the program(switching from one panel to another), it keeps on adding panels to the JFrame. So I suppose it's going to get heavier and heavier as users keep working. Maybe even errors because of adding the same panel twice.

But when I try to use the remove() or the removeAll() method for the panel, to remove the current panel, i get NullPointerException's when I try to access the parent again, with the getParent() method.

The method Masijade suggested to you does not "keep adding panels to the JFrame". It is a set method, so it basically overwrites whatever the previous content pane of the JFrame was when it sets it to the panel that you passed in. But even if it did keep adding windows to the JFrame, a window does not take up much memory, so I doubt there would be errors based on continuously adding windows to the JFrame, unless you did it in an infinite loop or something. I could be wrong about that, but you won't have that problem anyway if you are careful.

You should be using removeAll() on the JFrame, not the JPanel, if you use it at all. But if you use the method Masijade suggested, you do not need to use removeAll at all.

BestJewSinceJC 700 Posting Maven

^^^ Grisha never even had i = a -2 anywhere in his code? And I'm pretty sure what I mentioned was the actual problem, not what you are talking about.

BestJewSinceJC 700 Posting Maven

I'm working on a program to upload some files to an ftp. I created a thread the starts the upload when the upload button is pushed. When the upload button is pushed the GUI freezes because it is uploading. What change would I have to make to get the GUI responsive

If the problem is that the GUI is frozen temporarily while some other task is being completed, you need to use a SwingWorker thread. Run the task that is freezing the GUI in the SwingWorker thread, and your GUI will not be frozen anymore.

Other SwingWorker info: http://java.sun.com/docs/books/tutorial/uiswing/concurrency/simple.html

(But if the problem is simply that the GUI is permanently frozen, then you have another problem). In the scenario where you'd use a SwingWorker thread, it'd be because you are trying to complete some time consuming task on the EDT, and as a result, your GUI (which executes on the EDT) would have to wait for that task to finish before it can continue. So be careful because if, for some reason, your upload method is blocking & you put it in a SwingWorker thread, your GUI will work again. . but it won't have solved your problem (your upload method will still block, it just won't affect the GUI). Basically, use a SwingWorker thread if there is some time consuming task that freezes the GUI temporarily.

BestJewSinceJC 700 Posting Maven

All of this is do-able in one class. But I've seen the texts before, they usually do it using two classes. Good luck & mark this as solved if your question was answered

BestJewSinceJC 700 Posting Maven

If you're asking if you can output the contents of the JTable into the file, then yes, you can. Using two for loops (nested/one inside the other) go through each row and each column and print whats at the index into the text file. Use a PrintWriter to output to the file.

BestJewSinceJC 700 Posting Maven

@ thoughtcoder

Profound :yawn: . Next time before you post, try removing any arrogant or insulting language from it. Especially when jbennet has contributed much more to this site than you have.

thoughtcoder commented: You really have no clue what you're talking about. +0
BestJewSinceJC 700 Posting Maven

There are also a lot of jobs that are related to computer programming, that you might not think of if you are focusing strictly on coding. Some people here who are in industry might be able to give more examples, but here are some topics to look into:

Software configuration management
CMMI
Testing
Software Design (& User Centered design)

BestJewSinceJC 700 Posting Maven

change "showInputDialog" to "showMessageDialog" on the line where you have your error. And this thread is starting to get unwieldy; if you have solved your original problem, you should mark it as solved and post a new thread explaining whatever problems you are currently having. Also, when you use the code tags, the first one should say (this will give prettier formatting and also will give line numbers)[CODE=Java] (this will give prettier formatting and also will give line numbers)

BestJewSinceJC 700 Posting Maven

Oh, I thought you were talking about updating the same database from multiple different places. Which has got to be possible via the internets. And I do not think that posting your entire program will be necessary.
:)

BestJewSinceJC 700 Posting Maven

Ok, now I understand. Imagine a Node that has two attributes. The first attribute will be the value, which is an Integer. The second attribute will be another Node. (This Node will be the 'next' node, which is what they are calling the link). So basically if you had four nodes, containing: 1 2 3 4, (I'm just going to call the Nodes node1, node2, node3, and node4). So the first Node would be '1', and it would have a link to node2. The Node that contains 2 would have a link to node3. So now lets say that we want to remove a particular Node, node3. Your book is saying that you would need to find the Node before node3. In this case, that is node2.


Your book is saying that in order to remove node3, you would need to use node2.removeNodeAfter(). The code for removeNodeAfter() would look like this:

public void removeNodeAfter(){
link = link.link;
}

Explanation: Since we called the method with node2.removeNodeAfter(), "link" is the variable from node2. Remember that "link" contains the next Node. In this case, the next node is node3, so link is node3. Then link.link is the same as saying node3.link, which is node4. So saying link = link.link; is making node2 point to node4. Essentially, we have just deleted nodeThatContains3.

If that explanation didn't make sense, keep this in mind: In my example, I called the method with node2. So "link" refers to …

BestJewSinceJC 700 Posting Maven

Hi, I'm a fairly good Java programmer, but I have basically no web development experience. I'm posting in the html forum because I know it is the most basic, but I'm sure there are other necessary tools to accomplish this task, please let me know what they are.

I want to create a website that will have the following features (these should be fairly simple?):

-One section where the site admin can post pictures. Anyone visiting the site should be able to view these pictures in two formats: "Fullscreen" where the image fills the entire screen, and "next" and "back" can be clicked to go to other fullscreen pictures, and "icon" where all the images are shown (or a good amount per page are shown) as smaller versions of themselves.

-One section where the admin can post articles. Site visitors should be able to flip from one article to the next, and view a listing of article topics and choose an article from there.

BestJewSinceJC 700 Posting Maven

setValues() takes all the data from the controls on my UI and sets these values to an Object "Day". So each day has the same properties (hours, landings, solo flying, etc.)

I think I'm going to use the Java DB. Quick question, how easy would it be to deploy my application on other systems if I were to use the JavaDB? Would it need third party apps for it to work? How exactly would that work

I don't think your explanation of setValues is clear. Does setValues get each field from the GUI, then construct an Object called Day based on those values? If so, setValues seems like a strange method name, but if not, I don't get it. As for your second thing, I'll let someone more knowledgeable about it answer, but it is definitely possible. You could basically have an app from any computer that knows the location of the database and has access to it update and read from the database, as far as I know.

BestJewSinceJC 700 Posting Maven

[Warning: This is coming from a Java programmer with no C++ experience]

Assuming that clicking 'X' generates an event, and C++ has method overriding - override the method that closes the window when the user clicks 'X', and do nothing in that method. That way, nothing will happen when the 'X' is clicked.

BestJewSinceJC 700 Posting Maven

What? Be more specific and explain your problem fully

BestJewSinceJC 700 Posting Maven

In your paint() method, call super.paintComponent(g). It will clear the screen. Alternatively, you could use this piece of code from inside your paintComponent method:

g.clearRect(0, 0, this.getWidth(), this.getHeight());
BestJewSinceJC 700 Posting Maven

Abbie - try to be nice.

Ramborambo:

Use another for loop, but iterate backwards through the array. As you iterate backwards, add each element to a different array. Use this for loop, and inside the for loop, add code that will put the element at the current index into a different array. If you do a search in the Java forum, you'll find that someone asked an almost identical question to the one you asked.

for (int i = array.length-1; i >=0; i--)
BestJewSinceJC 700 Posting Maven

Use code tags and only post relevant code. I doubt that those huge tables of data are relevant. Your question also doesn't really make sense. What does "stop and wait timeout resend" mean?

BestJewSinceJC 700 Posting Maven

Post all *relevant* code. You definitely need to have implemented some sort of action listener for the check boxes to even begin making this work. Did you do that?

BestJewSinceJC 700 Posting Maven

int value = JOptionPane.showMessageDialog(null,"blah");

if(value == JOptionPane.CANCEL_OPTION){
//do stuff
}

BestJewSinceJC 700 Posting Maven
else if (Balance <100)
MonthlyRepayment = Balance;
Balance = 0;
count = count +1;
System.out.println("Balance at Month " +count+ " is " +Balance+ " after making a payment of " +MonthlyRepayment );
System.out.println();

All I added was MonthlyRepayment = Balance; if you don't understand why that should work, just ask.

BestJewSinceJC 700 Posting Maven

For the first error, you're either using a constructor that does not exist, or you didn't properly import the class.

BestJewSinceJC 700 Posting Maven

You could also use a stack to reverse the order. Put them in a stack, then pop them, and for each pop, put the element that was popped into an array. The array you end up with is the original one but in reverse order....

BestJewSinceJC 700 Posting Maven

else if (Balance <100)
Balance = 0;
count = count +1;
System.out.println("Balance at Month " +count+ " is " +Balance+ " after making a payment of " +MonthlyRepayment );

That's because you set MonthlyRepayment to 100 initially and then you never set the variable to anything else. If you want to continuously pay off 100 except when there is less than that amount remaining, calculate the amount remaining and then set MonthlyRepayment to that amount for the last payment.

BestJewSinceJC 700 Posting Maven

No, it would not, because I declared "ints" as an array of Objects. . not as an array of Integers. Then, knowing it was actually storing Integers, I casted the value that was at the index to an Integer. It runs correctly.

BestJewSinceJC 700 Posting Maven

In Vernon's example, you'd likely have multiple sets of words hash to the same location, but it would still be a lot better than just using an ArrayList. You could use a chained hash table where each index has a linked list and any collisions just go into a linked list at that index.

BestJewSinceJC 700 Posting Maven

If you must, cast each element individually to the appropriate type.

public static void main(String[] args) {
	
		Object[] ints = new Integer[10];
		ArrayList<Integer> list = new ArrayList<Integer>();
		list.add(1);
		ints = list.toArray();
		System.out.println((Integer)ints[0]);
		
	}
BestJewSinceJC 700 Posting Maven

Why don't you just use the normal way to associate an image with the button? http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JButton.html

BestJewSinceJC 700 Posting Maven

// is the bucket in the table?

I don't know, is the table round?

// can it be added to the table?

Perhaps.

// can the bucket be added at its hashed index?

If there's nothing else there, why not?

// what is to be done if the hashed index bucket != null?

Put the bucket there.

// can the bucket be added at a rehashed wrap-around index?

I forget, didn't pay all that much attention in Data Structs. But now that you're in it, I'd say answer this yourself.

// what is to be done if the rehashed index bucket != null?

See above!


:)

BestJewSinceJC 700 Posting Maven

peter - I looked at the compareTo method, it does the same as getTimeInMillis basically, except it compares the two times in millis for you.

OP - if you did firstDate.compareTo(secondDate) it would return a value indicating which one was greater. Have a look at the documentation.

BestJewSinceJC 700 Posting Maven
public static void sendMessage(String message){
try{
PrintWriter write = new PrintWriter(socket.getOutputStream(), true);
write.println(message);
}
catch (Exception e){}
}

Der_Kaiser. . what James is suggesting would make your code look like what I've posted above (Hope I'm not stepping on your toes here James). Then you'd just need to have a loop iterating over the ConnectedClients, where each client calls the sendMessage method. That way you're using the socket of the current client when you call sendMessage.

BestJewSinceJC 700 Posting Maven

The contains method will be a sure way of being fast, with all left upto the implementation of the Collection class, which certainly is much faster.

I disagree. The fastest possible way to search an alphabetically sorted dictionary would still result in comparing to unwanted results (if you're using a List). And if you just used the default contains method without overriding it, it would just do a sequential (log(n)) search of the List, which would take much longer.

BestJewSinceJC 700 Posting Maven

You have a syntax error. Is rosterList an ArrayList? If so, look at the get method here. You'd have to use return rosterList.get(yourIndexHere);

If rosterList is a two dimensional array, then you would have to use return rosterList[row][column].

And the reason for your error is because when you put the brackets [], that means you are trying to get the index of an array. But there is no array there.

BestJewSinceJC 700 Posting Maven

APPROVE_SELECTION is a constant, which cannot do anything on its own. It is simply a variable that has a value. approveSelection() is a method, and methods can "do things". For example APPROVE_SELECTION might be a value indicating whether or not to OK what the user has selected. But the method approveSelection() will go ahead and do something to approve the selection. In other words variables (APPROVE_SELECTION) store values, methods (approveSelection()) do things. I hope that makes sense.

BestJewSinceJC 700 Posting Maven

public class DVD extends Product

He means they have to go above where you make the class declaration. (Also note that if you have a package declaration, they should go below that). Example:

package whatever;
import whatever.*;

public class Other{

}

BestJewSinceJC 700 Posting Maven

Sorry for not giving as much help as I'd indicated I would - its finals time right now, so I'm busier than normal. As far as the toArray method, a lot of times, methods are declared as returning Objects, but that can be casted to whatever type you're using. You have to be careful, but if what you added was a String, the return type of Object can be casted to String. Also - are you having any problems with your program now? It seems like you haven't tried it out.

BestJewSinceJC 700 Posting Maven

There will be a "carry over" if the result can't fit into a 32 bit integer, presumably, which will cause the carry flag to be set. Then you just need to check the carry flag, which will be 1 if there was a carry, 0 otherwise

BestJewSinceJC 700 Posting Maven

I wish I had a banstick right now.

BestJewSinceJC 700 Posting Maven
public Object getValueAt(int row, int col) 
        {    
            return rosterList.get(row);
            for(int i = 0; i < 28; i++) <------- unreachable statement error
            {
                return col = i;
            }
        }

You said return rosterList.get(row) which causes whatever element is at rosterList.get(row) to be returned. When you return something, you are literally "returning" to wherever you were before (so if you called getValueAt from the main method, you'd return to main). In other words, the method you are in exits -- and since the method exits before you reach the for loop, it is giving you an unreachable statement error.

BestJewSinceJC 700 Posting Maven

You're in the wrong forum, but if you were in the correct one, pasting a project description at people is unlikely to get you anything except complaints.