BestJewSinceJC 700 Posting Maven

Get the x and y coordinates of the button and the line/rectangle or whatever it cannot pass. Compare these x and y coordinates; do not move the button any further if it is at or past these coordinates.

BestJewSinceJC 700 Posting Maven

hollywood - if you need more help, look at the example I provided.

BestJewSinceJC 700 Posting Maven

Your class is named Video. The Video class has a String and an int as data members. Your other class is VideoStore. It has an array of videos as its only data member. If you know how to create an array, then you should have no problems.

Video[] theVideos = new Video[howeverManyVideosYouHave];

If you wanted to make a class called Car, it might look like this

public class Car{
//The data members
public String color;
public int weight;

//The constructor
public Car(String theColor, int theWeight){
color = theColor;
weight = theWeight;
}
}

Now, consider a 'Car Dealership' where the Car Dealership typically has a lot of Cars...

public class CarDealership{
Car[] theCars;

public CarDealership(Car[] cars){
theCars = cars;
}
}
VernonDozier commented: Good examples +12
BestJewSinceJC 700 Posting Maven

Well, I figured out that if I set the size of the JFrame before switching the JPanel on the tab, the JTabbedPane resizes itself according to how large the JFrame is. So although I'm still mad that I can't figure out how to setSize explicitly, this is good enough.

PS

I read in an article called Java pitfalls (or something like that) that the layout managers override calls to setSize because they perform their own sizing afterwards, so overriding the setMinimumSize method works better.

BestJewSinceJC 700 Posting Maven

Yes. . just update threads from 5 years ago

BestJewSinceJC 700 Posting Maven

Well, I'm afraid I can't help you since I know nothing about those protocols. Sorry & good luck

BestJewSinceJC 700 Posting Maven

Use the String class's toCharArray method, then loop through the character array using a for loop, only printing out every even position or odd position. You can print out even positions or odd positions by using modulus. What modulus does is it returns the remainder of a division. So an example of modulus would be 4 % 2 = 0 and 6 % 4 = 2 (the % sign is modulus).

Good luck!

BestJewSinceJC 700 Posting Maven

Your problem sounds extremely application specific. From my understanding, persistence layer is where the data is stored, so your question doesn't make sense anyway -- why would you be doing transaction management in your database? Maybe I don't know what I'm talking about here.

BestJewSinceJC 700 Posting Maven

How are we supposed to know what the class Plane is? If it's a standard library class, at least link us to the documentation or something.

BestJewSinceJC 700 Posting Maven

A recursive method calls itself in order to come up with the final answer. Your method is returning count, which does not do what I just said. Your method should have the following parameters: currentIndex (the index the array just checked), count, array (your array). A recursive method also needs a base case to tell it when to stop the recursion. In your case, since you want to go through the whole array, counting the number of times 5 appears, where do you want to stop the recursion? Clearly, you want to stop when you have gone through the entire array.

To help you out, here is the pseudocode, or at least part of it:

count(currentIndex, count, array){
if currentIndex is at the end of the array, return count.
else if the next index has a 5, return count(currentIndex+1, count+1, array)
else, the next index does not have a 5, so return count(currentIndex+1, count, array)
}

It is a little sloppy but that is the general idea. You have to call the method for it to be recursive, and you have to have some mechanism that stops it from calling itself. In this case, when it is at the end of the array, it should stop calling itself, because it has no more indexes to look at.

darkagn commented: Good explanation of recursive calls with example pseudocode +4
BestJewSinceJC 700 Posting Maven

Well I have to use the GroupLayout Manager at this point, because I like how it arranges things, generally. After you made that comment, I've been looking through the java tutorial on it, and there is some stuff that might be useful to me. However, I'm still somewhat concerned about setSize not doing anything.

I have:

tab 1 - tab 2 - tab 3 - tab 4

And at runtime, I want to dynamically change tab 1 to be a completely different JPanel. This JPanel is much larger than the one that was originally there. I'm successfully changing the tab's JPanel to another JPanel... but I cannot resize it at all.

BestJewSinceJC 700 Posting Maven

What if when you resize the JFrame, you pass the JTabbedPane the width and height through the

resize(int width, int height)

method while resizing the JFrame?

I already thought about this solution, and decided that I did not want to go the route of adding a WindowListener or something, and resizing the JTabbedPane every time the JFrame is resized. Not out of laziness, but out of the complexity of layers that I have.

@ Ezzaral - You are correct, I have been using netbeans lately. The first time I ever asked for help on a project (this was months back) I was coding by hand. Now I switched to netbeans and I've been using it since you suggested using it for UI prototypes. And I'll check out what you said about the layout managers.

FYI, I have the following hierarchy of windows

JFrame -> JTabbedPane -> (JScrollPane->JPanel). So there is a JPanel which has a JScrollPane for it. The JPanel is one of the tabs on the JTabbedPane, which is in a JFrame. I'm trying to get some sort of sizing going that looks nice (and allows me to view most of the JPanel, which is fairly large) but I can't get anything except the JFrame to resize, even when using the setSize method. I thought that maybe the JScrollPane wouldn't resize because the JTabbedPane was too small, and I thought the JTabbedPane wouldn't resize because the JFrame was too small, but I resized the JFrame, and neither …

BestJewSinceJC 700 Posting Maven

I have a JTabbedPane inside a JFrame. I've been having a lot of problems with resizing and things like that. . how do I get the JTabbledPane to resize with the JFrame? So when the user drags the window open to a larger size, the JTabbedPane should be dragged to the same size. Can this be done automatically?

BestJewSinceJC 700 Posting Maven

Tizzie: what are you doing? Make your own thread and post code in code tags and read the rules first.

brizwhiz's only problem appears to be what ezzaral pointed out, the semi-colon should not be there.

BestJewSinceJC 700 Posting Maven

That's because this code

 if (Character.isLowerCase(characters[i]))

               {
               characters[i] = Character.toUpperCase(characters[i]); 
               }  

Converts all of the lower case characters into upper case ones. If you don't want to do that, then remove that code.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

I can't help much since I use Windows, which is the forum you are in (Vista) btw, but I had a similar problem and I removed my current driver, installed the new one, and it worked ok after that. Good luck!

BestJewSinceJC 700 Posting Maven

...???

I'm not sure what you mean by that. Put it like this: since every architecture has it's own set of instructions, a compiler needs to be capable of breaking a high level language's statements down into those instructions. Those instructions are then broken down into the machine code.

BestJewSinceJC 700 Posting Maven

Yes, I suppose I should. . :(

*Goes back to the Java forum*

BestJewSinceJC 700 Posting Maven

http://java.sun.com/developer/onlineTraining/java3d/index.html

I started reading it myself, but gave up a while back due to not enough time.

BestJewSinceJC 700 Posting Maven

Post your full code, in code tags.

I feel like I say this 100x per day.[CODE=Java]

I feel like I say this 100x per day.

BestJewSinceJC 700 Posting Maven

I don't like to speculate on what I "would" do (since I've never tried anything like this, so the advice could be totally off - try at own risk of wasting your time :) ), but I would try to make a custom class that extends JButton and modify the paint method. The Graphics class has methods to draw shapes such as ovals, rectangles, etc.

BestJewSinceJC 700 Posting Maven

Try to identify the area of your problem. You can do this by using print statements to verify that your major pieces of code are working correctly. For example, does your code ever get inside of the if statement? Then tell us where your areas of difficulty lie.

Also, post all relevant code, and post that code in code tags, read the sticky if you don't know how to do this. . I read your code but I don't see any errors.[CODE=Java]. I read your code but I don't see any errors.

BestJewSinceJC 700 Posting Maven

Just curious. . you posted a link to a c++ website. The use of that function is the exact same in c++ and c?

BestJewSinceJC 700 Posting Maven

You can make earlier Circles disappear by removing this code:

for (Circle a : pointList) {
            a.draw(page);
        }

It seems like that code draws every single circle that you added to pointList.

BestJewSinceJC 700 Posting Maven

The brackets tell you what code belongs to what method.

public class Whatever{
}

^ Anything between the brackets in bold is code inside of the class.

public class Whatever{

public void main(String[] args){

}
}

^Anything inside the brackets in bold is code that belongs to the main method. (So when you run the main method, the code between those brackets gets executed).

BestJewSinceJC 700 Posting Maven

Do what JavaAddict suggested, I would suggest one minor modification though: use an integer array of size 12 (one for each value) to keep track of the number of times each has occurred. Simply increment the index- increment index 0 if you see a 1, index 1 if you see a 2, and so on.

BestJewSinceJC 700 Posting Maven

Yes, you are correct - you would not notice a difference. However, if you started playing games, chatting, listening to music, and downloading files off the web, you might notice a difference between a single core and quad core machine. Also, FYI, each time you start a Java application, the main method is run in a new thread.

BestJewSinceJC 700 Posting Maven

No. The String class and the Character class both have toUpperCase methods. If you try to use the String class's toUpperCase method with a Character, it will not work. However, if you use the Character class's toUpperCase method, it will work. You need to understand that the Character class's toUpperCase method is a static method. Therefore, the way that you call the method is Classname.methodName(arguments). In this case, that means Character.toUpperCase(yourCharacterHere). I hope you will read the article I linked you to about static methods.

Note: If you read the documentation for the toUpperCase method, you will notice that it takes an argument of type 'char', which is a primitive type (such as int, double, etc).

BestJewSinceJC 700 Posting Maven

NeutralFox - I'm glad you solved your problem - James is correct in saying "If you have a single processor the two (or more) threads will share it according to some process that you don't get involved with". As an example of that, consider the fact that you can use your email, play music, and IM all at the same time.

BestJewSinceJC 700 Posting Maven

You can use a while loop to implement the solution James suggested. Be careful not to try to indexes that are not actually in the array. And mark your threads as solved when you are satisfied with the help you've been given, or when you've found a solution, as you indicated above.

BestJewSinceJC 700 Posting Maven

You can easily find out what a static method is on your own. There are plenty of resources available to you that already say anything we can tell you about static methods. Here is one, if it doesn't work for you, use google to find more

http://leepoint.net/notes-java/flow/methods/50static-methods.html

BestJewSinceJC 700 Posting Maven

Yeah. You have your brackets in the wrong place.

public class PayrollProgram3
{

public static void main(String[] args) {

}
}

That's two open brackets and two closed brackets. Since the brackets match, you have no code in your main method, and no code in your class.

BestJewSinceJC 700 Posting Maven

Here is an example to show you how to create arrays.

String[] aBunchOfStrings = new String[10];
for (int i = 0; i < 10; i++){
aBunchOfStrings = "";
}

So basically, when you create the array you need to use the full amount that you want, 10 in this case, but when you index the array, you use 0-9 (in this case).

And on the thread that I linked you to, I wanted you to look at post #3 by JavaAddict. He usually gives good advice so I think what he is suggesting will work. In any case, it is very easy to implement so it's worth a try. You can basically copy and paste that code, you'll just need to call the Array.sort(yourArray) method each time you want to sort your array.

BestJewSinceJC 700 Posting Maven

Adding or removing depends on how you are storing things to begin with. If you are just storing a book in a variable, you could set the variable to null to 'remove it'. If you are storing things in an array of books, you would have to remove the book from the array's index. You should read the sticky at the top of this forum, it links to many helpful Java Tutorials. Read one of them.

BestJewSinceJC 700 Posting Maven

You could also use the String's toUpperCase as long as you converted the char to a String first. Since charArray is a char, if you did charArray + "", that is now a String in Java. Pass that to the toUpperCase method and it will return an uppercase String version of that letter.

(James' solution is better than that, just telling you that it is possible to do so)

You could also use the ANSI table and add the appropriate amount to the character to convert it to upper case.


edit: I said ANSI, java uses unicode character set though, sorry

BestJewSinceJC 700 Posting Maven

1. make sure it is clear to the user how to exit your program. So change your print statement to something like "Enter the composer's name or 'q' to quit."

2. You declared your arrays as having 999 elements, not 1000. If that was your intent, that is fine, just letting you know.

3. It seems like your main area of struggle is with sorting the array. You want to sort it alphabetically, by composer, correct? You'll have to be careful to make sure that the piece and the composer always stay in the same index for each array (So if you move the composer to index 3, their piece has to be moved to index 3 as well). Check out this daniweb thread on sorting Strings alphabetically: http://www.daniweb.com/forums/thread133150.html . Also, the String class has a compareToIgnoreCase method that I (think) would do what you want (compareTo typically returns an integer which indicates whether the first object was < = or > the second object).

BestJewSinceJC 700 Posting Maven

You'll also need to implement ActionListener for your JButton. Then you can get the selected index from in the actionPerformed method. Here's an example
http://java.sun.com/docs/books/tutorial/uiswing/examples/components/TableSelectionDemoProject/src/components/TableSelectionDemo.java

BestJewSinceJC 700 Posting Maven

So there must be different versions of a compiler for different architectures.Is it right?
And does the word architecture returns just to CPU?

Yes, since different architectures have different sets of instructions (instructions break down into machine code), different architectures would need a different compiler.

BestJewSinceJC 700 Posting Maven

Hi
I have 4 questions
1-Is it right that when you learn assembly you learn machine language,too?How?
2-What makes a programming language feature OS dependent?
3-Does Assembly have OS dependent feature?what about HLA?
4-How can i write an OS independent program(bootable programs)?
thanks alot

In response to the poster above me, no, Assembly is not machine language. Assembly is a language that is translated into machine code by the assembler. Programming languages are not OS dependent, they are dependent on the hardware. The Operating System is a piece of software, not hardware. And no, Assembly does not have an OS independent feature, since 1. the OS is software, not hardware; 2. Assembly breaks down into machine code, and machine code is dependent on the specific architecture you are running on.


-A specific hardware has a specific set of instructions that it can execute. http://en.wikipedia.org/wiki/Instruction_set_architecture
-If your programming language wants to run on that architecture, it must somehow break all of its high level statements down into instructions that that architecture can understand. So if I want C code to run on a specific architecture, there needs to be a compiler that breaks the C code statements into machine code that the machine understands.

Note: I think this process happens by first breaking the C code down into assembly language statements that the machine understands, then breaking the assembly into machine code. But I'm not positive about that.

BestJewSinceJC 700 Posting Maven

It's ok. You might be better off just re-posting this in the correct forum, seeing as no mods have moved it yet.

BestJewSinceJC 700 Posting Maven

Since you're using the File class, you can use the class's getName method to return the name of the file associated with it. If that method doesn't work for you, here is the Javadoc http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html

BestJewSinceJC 700 Posting Maven

And your teacher is trying to tell you that the String's length method will tell you how long their name is. So what everyone else here has said applies, let me put it all together for you:

1. Prompt the user, asking them what their name is
2. Use a Scanner Object and the readLine method to read their name into a String
3. use the length() method of the String class to figure out how long their name is. Lets call this "nameLength"
4. Use a for loop to print out the *'s. Inside the for loop, have an if statement that says for (int i = 0; i < nameLength; i++){
//print the *'s and other stuff in here
}

BestJewSinceJC 700 Posting Maven

This is the Java forum. Java is an Object Oriented programming language. Javascript is a web-based scripting language.

BestJewSinceJC 700 Posting Maven

Yes. An Object is created like this:

Classname variableName = new Classname();

In your case, that means

Factor whateverYouWantToCallItGoesHere = new Factor();

BestJewSinceJC 700 Posting Maven

URLs, unless what I've grown up knowing and loving is no longer sacred, point to resources on the interwebzzzz

BestJewSinceJC 700 Posting Maven

Post your code in code tags. When you click on the code tag icon, Change it from

to [CODE=Java]. Also, your code seems to have numerous errors, so I will get to that.

[CODE=Java]class Factor{
public int calculateFactor(int n1, int n2){
public Factor newFactor()
int factor;
factor=n2%n1;
if(factor==0)
return factor;
else {
return 0;
}//end public
}//end class

Your line public Factor newFactor() has numerous errors with it. First, an Object is declared like this (using String as the class in this example): String str = new String();. Your declaration doesn't have a semicolon at the end and does not have the correct syntax. Second, since you are in a method, using the word 'public' before you create the Object is not necessary and doesn't make sense. The Object can only be used inside of that method.

It should say: Factor f = new Factor();

I also noticed that you are not using the Factor Object you created, so what is the point of creating it?

BestJewSinceJC 700 Posting Maven

With Google.

April Fools!

Read this tutorial, I think it is what you are looking for. And I also think I linked someone to it maybe a day ago. http://java.sun.com/docs/books/tutorial/2d/images/index.html

BestJewSinceJC 700 Posting Maven

Yeah, I've already read a lot about the Swing threading model and memory consistency and WorkerThreads etc, if that's what that link is all about. But I'll check it out. And thanks for your help.

BestJewSinceJC 700 Posting Maven

Ok. So Events can be fired on the Components as soon as they are realized (which happened due to pack) even if they are not visible on the screen yet?

Also, the reason these glitches or inconsistencies could occur is...what exactly? Because setVisible invokes the paint method, so essentially two threads are trying to paint the same window at once, resulting in glitches?