BestJewSinceJC 700 Posting Maven

Yet, I have already stated that I agree with you that invoking on the EDT is the best practice. I've already read the Java Sun documents on Swing, as well as many of their examples that use code doing so. But that still ignores the question I asked, which is "why is the code that I provided previously buggy."

Btw, the code in the actionPerformed method always runs in the Event Dispatch Thread, as stated here. Maybe I misunderstand that document or I misunderstand you, because I thought you were implying otherwise elsewhere in this thread.

edit:

Anyway, I'm really not trying to be frustrating, so if it is frustrating to you, just stop replying and someone else will give their input/reasoning as to why you're right later.

BestJewSinceJC 700 Posting Maven

I agree with you about the general Swing knowledge. Of course, it is always a best practice to run code on the EDT. I'm simply unable to produce a buggy test case thus far for this problem, so it is hard for me to see how it is an issue here.

BestJewSinceJC 700 Posting Maven

.. I still don't see how this is an issue. The code I posted above appears to work. Are you saying it doesn't or has hidden errors? @ OP: terribly sorry for jacking your thread, too interesting now though

:)

BestJewSinceJC 700 Posting Maven

You should set your initial lowest value to array[0], otherwise the lowest value variable will probably be initialized to 0, therefore, it will tell you the lowest value is 0 at the end.

flyingcurry commented: Thanks! +0
BestJewSinceJC 700 Posting Maven

Agreed with what you said above, as the Java documentation says. What is the synchronization error in the below code? It looks like it works to me. Like I said above, as far as I'm concerned, only one thread in this program access the UI components, and that is the main() thread.

public class Test {
	public JFrame Frame = new JFrame("Test");
	
	public Test() {
		Frame.setSize(1440,900);
		Frame.setVisible(true);
		Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		final JPanel panel = new JPanel();
		Frame.add(panel);
		
		JButton b1 = new JButton("1");
		panel.add(b1);
		b1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
            	 	panel.removeAll();
            	 	Frame.repaint();
            }
        });

	
	}
	
	public static void main(String [] args){
		new Test();
	}
}
BestJewSinceJC 700 Posting Maven

No, it has nothing to do with thread synchronization. The JFrame removes all of its child components. Even if the JFrame made changes to the JButton when it removes the button, it would not cause any thread synchronization problems, since there is only one thread in the OP's program, which is the main() thread.

BestJewSinceJC 700 Posting Maven

Avoid giving people fully working code. Give them tips that will help them learn and occasionally bits of code.

BestJewSinceJC 700 Posting Maven

Search the ArrayList for the name. Use the indexOf method. Then edit the Object at the index that is returned, and edit the phone number at the same index in the other ArrayList.

http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

It depends how the method is defined; some methods might be defined as "returns XXX under YYY conditions". If so, you could check the returned value for errors. Other than that, I don't know of any ways to do error checking, but Exceptions and return values are really all you need IMO...

BestJewSinceJC 700 Posting Maven

When do you want to check to make sure none of the fields are empty? When the 'add' button is clicked? You need to give more information. Regardless, you'd use an if statement.

if (buttonName.getText().equals("") || otherButton.getText().equals("")) //do something, your button's text was empty!
BestJewSinceJC 700 Posting Maven

edit: nevermind


!!!!

BestJewSinceJC 700 Posting Maven

Two people who have obviously used it before provided it as a resource that would help you solve your problem. That should be enough reason to take another look or at least apologize (or not whine) when you find out you're wrong. You're misusing the word patronizing. At the worst, a sane person would interpret my question as rhetorical and assuming. Your response shows how little you know about this site or the people on it. Almost everyone who asks a question in this forum is a student. I'm also a student myself. Age has nothing to do with learning or teaching, or being wrong or being right. Age in and of itself isn't a good or bad quality. Some people mistakenly associate age with both good and bad qualities, but age only allows a person time to attain good or bad qualities, it doesn't instill these qualities in someone.

> So naturally i won't be back to ask anymore questions - i would rather fail my degree than bow down to people like you who only want to "nit pick".

Great, we'll miss, err...nit picking you.

BestJewSinceJC 700 Posting Maven

...

BestJewSinceJC 700 Posting Maven

No, make your own class, lets call it YourClass. Then to call any methods from YourClass you have to say YourClass obj = new YourClass(); and use the 'obj' to call methods from YourClass.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

AD, that made me lol. Later--

BestJewSinceJC 700 Posting Maven

That's cool man, check the cool tags now!

BestJewSinceJC 700 Posting Maven

VBulletin only has a tab called "infractions" where a member's infractions are listed, which makes perfect sense because the tab contains a listing of violations, and infraction is a synonym for a violation of a rule. Now, the reason why being "given an infraction" makes sense is because when you are "given an infraction" another infraction shows up under this tabbed listing. So you see the word infraction really isn't being abused, the use is only slightly changed, just like many other phrases in the English language.

BestJewSinceJC 700 Posting Maven

Then create an Object of the class type and use that Object to call the class's methods.

BestJewSinceJC 700 Posting Maven

> i.e. to be given one means you were caught committing an infraction.

I think you'll find given means given.

Hence "given an infraction" means "given a breach of the rules".

I.e. nonsense.

I think you'll find that in colloquial English the meaning of expressions change based on the context in which they are used. Hence to be "given an infraction" means you were just penalized.

BestJewSinceJC 700 Posting Maven

Yes I did read it and it was a complete waste of time. Its all very well creating a two dimensional array for a table if you are going to state the arrays values in the code - I mean who really does that.

The examples are way to basic to aid someone who wants to search through a linked list, and where a record is found that matches certain criteria as specified by a user , copy those records into a two dimensional array that is only the size it needs to be to hold those records (ie no empty elements which will result in empty rows in a table) and then create a JTable to display those records to the user.

The examples are meant to provide a foundation on various topics, not provide a complete guide of how to do everything. The JTable tutorials make no attempt to teach topics like LinkedLists and searching, since those topics have nothing to do with JTables. Anyway, I can understand your frustration, since some topics in Swing are definitely difficult to understand. The question I asked you earlier was mostly to determine what level of effort you put into finding the answer, especially since your question has been asked many times before. For example,

This example demonstrates how to adjust the width of a column to be just wide enough to show all of the column header and the widest cell in the column.

BestJewSinceJC 700 Posting Maven

Relax. It was a question, not an accusation. Nice rant though, now I'm a lot more likely to help you.

Ezzaral commented: Yeah, no kidding. Warm fuzzies abound! +10
BestJewSinceJC 700 Posting Maven

^ Wtf ?

I like to wear basketball shorts and t shirts. So comfy.

BestJewSinceJC 700 Posting Maven

Don't use Eclipse's auto complete as a substitute for documentation and research. For example, did you read this?

BestJewSinceJC 700 Posting Maven

"An infraction of the rules" is the example. The word infraction being a synonym in that context for [breach, violation, infringement]. The language "given an infraction" comes from this definition and has only a slightly different meaning, i.e. to be given one means you were caught committing an infraction. I don't see what's complicated here. English has plenty of words that are similarly used.

jonsca commented: Yes +0
BestJewSinceJC 700 Posting Maven

If you want to call the SampleA or SampleB methods, you have to do so using an ObjectA. The only alternative is to declare the SampleA method as static: public static void sampleA(){} and then from within a method in a different class, you can say ObjectA.sampleA(); . So to demonstrate your alternatives:

public class Animal{
int age = 0;
int weight = 0;

public static void killAllAnimals(){
System.out.println("BOOM, all animals on earth just died.");
}

public void setAge(int newAge){
age = newAge;
}

}
public class AnimalTester{

public static void main(String[] args){
Animal a = new Animal();
a.setAge(10);
Animal b = new Animal();
b.setAge(20);

Animal.killAllAnimals();

}

}

As you can see, static methods get called by putting Classname.staticMethodName(); whereas non-static methods, which are called instance methods, can be called by creating a new Object, then using the name of the Object to call the method. For more information on when you should use static methods vs. when you should use class (static) methods, see these links:

http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html
http://leepoint.net/notes-java/flow/methods/50static-methods.html

P.S. I don't know why my example is so violent today!

BestJewSinceJC 700 Posting Maven

http://www.rgagnon.com/javadetails/java-0172.html

Personally I'd just use Jquery though... (which obviously is written in javascript so you could use that like the above link).

BestJewSinceJC 700 Posting Maven

It doesn't fit everyday usage either.

I was just thinking to myself, "what the hell is this kid talking about", so I went and looked up the "dictionary definition" on websters dictionary, which states,

breach; violation; infringement: an infraction of the rules.

The only example websters gives for usage of the word is exactly how it is being used on Daniweb. Communicating effectively is about getting the point across between two parties, and I believe, as does everyone except you, that the infraction system is pretty clear in its meaning: don't do XXX again.

BestJewSinceJC 700 Posting Maven

mm m, I like to add a little salt, herbs, and sig spamming in my pasta dishes! Delicious!

jephthah commented: no one cares +0
BestJewSinceJC 700 Posting Maven

Then you either have to call Piggy.SampleB() or from within the SampleA() method, you have to call SampleB(). Btw, methods should be named in camelcase starting with a lowercase letter: nameMethodsLikeThis() and Objects should be named the same way (although Objects, preferably, should have pretty short names).

BestJewSinceJC 700 Posting Maven

After creating the c object of Class2, is there anyways i can know which class instatiated it

Yes, because the method that instantiates the 'c' Object is inside of Class1, therefore you already know that it was instantiated inside of Class1. Inside of method1(), the word "this" refers to the Object that called method1().

BestJewSinceJC 700 Posting Maven

In general, you should modularize your code so that these things are separate processes:

1. Prompting the user for what type of seat they want
2. Finding an open seat that fits the user's selection from (1)
3. Assigning the user to the open seat
4. Prompting the user for (or with) more information.

Right now you have one big block of code with everything thrown in. Asking passengers for information, finding open seats, and putting passengers in those open seats are all logically different tasks. Therefore, your program should treat them as such. Use methods to separate your code. Once you do that, I will gladly take a more in depth look through your code. Right now, I'm pretty sure you're having so much trouble because everything is in one big jumble, not logically separated into parts.

BestJewSinceJC 700 Posting Maven

No problem. Assuming that you make an Object to put your data in like James and I suggested, the declaration I gave you above would just be changed to ArrayList<YourObject> list = new ArrayList<YourObject>(); . Same pattern applies for using Vector. The ArrayList class is actually pretty simple for someone who has studied Java before; you can check out the get() and add() methods at the Javadoc if you change your mind. Javadoc for Vector is here; you basically call yourVector.add(); to add an Object and .get(index) to get an Object at a particular index.

BestJewSinceJC 700 Posting Maven

I don't think the act of opening or closing this thread has anything to do with Dave either way.

edit: But of course I do agree that it should be treated/closed under the same circumstances as any other thread.

BestJewSinceJC 700 Posting Maven

I would personally make an Object to represent the data coming out of the database, assuming that the data is related. If you want to stuff anything into an array, you can use an ArrayList (or Vector if you need it to be synchronized). If you don't need it to be synchronized use ArrayList. You can use something like ArrayList<Object> list = new ArrayList<Object>(); . I don't have a backround in databases so take that advice with a grain of salt, I'm avoiding being too specific lest I mislead you.

BestJewSinceJC 700 Posting Maven

yes, but they were unaware of what was going on with the 3rd party they worked with.
And now they're being slagged for being associated with someone Obama doesn't like.

The U.S. Security and Exchange Commission files a lawsuit against Goldman Sachs and one of its employees. What is important to understand is that if the people whose mortgages make up the CDO make their payments, then the companies that invest in the CDO will profit. Goldman apparently intentionally set up the CDO so that it would be likely to fail (basically by composing it of mortgages that were unlikely to be paid off for various reasons), then Goldman shorted the CDO, which means they took a position where they would profit if the CDO failed. Any way you put it, they took two opposite positions on the same investment. Highly immoral and illegal since it constitutes a conflict of interest.

A quote from a Goldman Sachs employee email (Fabrice Tourre, Goldman executive who helped set up the CDO)

More and more leverage in the system, The whole building is about to collapse anytime now…Only potential survivor, the fabulous Fab…standing in the middle of all these complex, highly leveraged, exotic trades he created without necessarily understanding all of the implications of those monstruosities!!!

Goldman Sachs employees were a top contributor to Obama's campaign. They aren't being smeared. If anything, they should be pursued more than they currently are. Numerous ex-Goldman Sachs employees

BestJewSinceJC 700 Posting Maven

Call validate() on the JFrame after you reset the panel. You also might want to try creating the GUI like the java tutorials recommend i.e. what they do here. (Although I don't think it is causing your problem, can't hurt to do it correctly)

BestJewSinceJC 700 Posting Maven

post code, ask specific questions, show effort.

BestJewSinceJC 700 Posting Maven

bondgirl, if you attach all of your current code as one post, I'll take a look at it for you.

BestJewSinceJC 700 Posting Maven

As long as it gets the point across I could care less if Dani calls it No-No's

Nick Evan commented: I would vote in favor of "no-no" +0
BestJewSinceJC 700 Posting Maven

Put it at the end of your method that calculates the number of vowels, but not inside of a loop. Don't you know how loops work?

BestJewSinceJC 700 Posting Maven

While some of the information in the article may not be true I don't understand what you mean about them being "duped". They profited immensely.

BestJewSinceJC 700 Posting Maven

Agreed, in this case your method should be declared as static. In general, however, making methods static is not a good solution. Methods should only be declared static when the method applies to the entire class rather than one specific instance.

http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html
http://leepoint.net/notes-java/flow/methods/50static-methods.html

BestJewSinceJC 700 Posting Maven

bondgirl: For the prepositions you could add them all to an ArrayList and then use the contains() method to see if one was there. For example:

ArrayList<String> list = new ArrayList<String>();
list.add("on");

if (list.contains("beneath")){
System.out.println("The preposition is in the list! Do something!");
}
BestJewSinceJC 700 Posting Maven

I might go to the after party but I'm still not sure if I can.

BestJewSinceJC 700 Posting Maven

You should only print out the number of vowels outside of the loops. Print out the number of vowels right before the end of the method.

BestJewSinceJC 700 Posting Maven

Follow Moutanna's suggestion to use Comparators. I misread your post the first time around; I thought you wanted to sort based on "1" then sort based on "2" if there was a tie, etc. But what you actually want to do is sort three different ways, so follow Moutanna's suggestion and use three different Comparators.

BestJewSinceJC 700 Posting Maven

Thanks for pointing out that site, looks a lot friendlier than this one.

It was a joke. Relax.