BestJewSinceJC 700 Posting Maven

A queue implementation, if you wanted to write it yourself, is simple enough that you could just start coding if you know what a queue is, so I'm thinking maybe you have a more specific question, a part of the queue implementation or a concept you don't understand?

BestJewSinceJC 700 Posting Maven

I have a feeling you wrote it in your head but didn't actually type it Masijade. Cheater! Lol.

BestJewSinceJC 700 Posting Maven

File: "first word in the sentence"

Code to contain that file:

//Lets pretend this Scanner is linked to the file.
Scanner input = new Scanner();
ArrayList<OneRow> file1 = new ArrayList<OneRow>();
OneRow theOnlyRowInTheFile = new OneRow();
//store "first" in firstColumn
theOnlyRowInTheFile.firstColumn = input.next();
//store "word" in the ArrayList that contains the rest of the row
theOnlyRowInTheFile.restOfTheRow.add(input.next());
//store "in" in the ArrayList that contains the rest of the row
theOnlyRowInTheFile.restOfTheRow.add(input.next());
//store "the" in the ArrayList that contains the rest of the row
theOnlyRowInTheFile.restOfTheRow.add(input.next());
//store "sentence" in the ArrayList that contains the rest of the row
theOnlyRowInTheFile.restOfTheRow.add(input.next());

You see, one OneRow object stores one row/line of a File. In order to store the entire File (assuming the file is more than one row/line long), you need an ArrayList of OneRow objects.

BestJewSinceJC 700 Posting Maven

You could download a picture of a mouse and then paint that image. Or, you could always get some mice from under my stove - I think that's where they're all hiding.

BestJewSinceJC 700 Posting Maven

No, you don't need to add anything manually. The button that looks like a # is the code tags button. Then you just put =Java after the first CODE.

And I spent a few minutes looking at your code, but I don't see anything wrong with your sorting algorithm, but it was difficult for me to understand the code, not having used that algorithm before - I'm sure you'll get some more replies if you use the code tags. Good luck.

BestJewSinceJC 700 Posting Maven

Whenever you no longer need to use an Object in Java, if you simply get rid of any references to that Object, Garbage collection will take care of it from there. Set any references to that Object to null.

BestJewSinceJC 700 Posting Maven
for(int scan = index+1; scan<list.length; scan++)
if(list[scan].compareTo(list[min])<0)
min = scan;

temp = list[min];
list[min] = list[index];
list[index] = temp;

You need to use code tags, i.e., what I used in this post. The problem might be your use of brackets; did you mean to use brackets after the if statement?

BestJewSinceJC 700 Posting Maven

Are you sure you're looking at http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html ? It's possible that you have used the wrong import statement, it should be import java.util.ArrayList. And I typed the code up in this thread, I never compiled it. For the comparison method, it seems like I forgot a parenthesis. It should be:

if ((index = file2Column1.indexOf(file1Column1.get(i))) != -1)

For future reference, a good way to check that is to count the opening parens first, then go back and count the closing parens. The way the computer probably checks this is by pushing any open parens on a stack, then popping an open parens every time it sees a closed parens.

BestJewSinceJC 700 Posting Maven

To confirm his opinion: ShawnCPlus is absolutely correct. You'd be wise to follow his advice.

BestJewSinceJC 700 Posting Maven

Thanks guys. And yes, I was assuming that the rand.nextInt() was returning a positive number.

BestJewSinceJC 700 Posting Maven

After a little research I discovered some Calendar methods that were pretty nice.

Date date = new Date();
int daysSinceSeen = - ( rand.nextInt() % 365 );
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, daysSinceSeen);

How could this code be returning a date in 2010? Do I have a bug that I can't see? The Javadoc for the add method says to use Calendar.DAY_OF_MONTH, but that also returns dates in 2010. Hm.

BestJewSinceJC 700 Posting Maven

I thought you marked my second post for bad rep, not the first, hence the confusion. But like I said, why is this such a big deal to you? Hmm. And I do "know C programming", I admit to not knowing it very well. That doesn't mean I can't answer common issues. Also, I usually browse this forum and read threads I'm interested in. Who are you to tell me what forums I can't post in? While I can see you having a problem with my original post (which is why I apologized to begin with), your immaturity is incredible.

BestJewSinceJC 700 Posting Maven

Let's review:

I misread his question, then made a mistake. I then realized this mistake, admitted my mistake, and apologized to monkey king. I didn't whine for rep nor did I ask anyone for rep. I wanted to know why you would disapprove of someone admitting a mistake, or why you would even get involved.

BestJewSinceJC 700 Posting Maven

Why would you give me bad reputation for admitting I made a mistake? That doesn't make very much sense.

BestJewSinceJC 700 Posting Maven

In Java you can think of 'this' as being the same thing as the name of the Object. So if you are in the class MyClass, 'this' is your MyClass Object.

BestJewSinceJC 700 Posting Maven

My mistake, monkey king.

BestJewSinceJC 700 Posting Maven

Oh, I was referring to where he said "Or make row an ArrayList of ArrayLists." I thought maybe there was some difference in syntax between how you did it and he did it or something. Nevermind.

BestJewSinceJC 700 Posting Maven

Some things you can do to help us help you:

1. Use code tags. There is a sticky at the top of the forum that explains how to use Java code tags to put your code in a format that will show up with line numbering next to it and indentation.

2. Try to point out specific sections of code (i.e. methods) that aren't working, tell us what they are supposed to be doing, what they are doing, or if they are causing compile time errors, point us towards those (along with the java code tags, just point out the line numbers).

BestJewSinceJC 700 Posting Maven

I don't know very much C programming but I am pretty good at google. http://www.elook.org/programming/c/strtok.html

jephthah commented: come on, man. :icon_rolleyes: -2
tux4life commented: This doesn't deserve bad rep :) +12
BestJewSinceJC 700 Posting Maven

...or...
use nested arraylists
ArrayList<ArrayList<String>> rows
and access the inner ArrayLists, and their Strings in the usual way.

James, out of curiosity, isn't that the same thing as what Vernon suggested?

BestJewSinceJC 700 Posting Maven

Correct me if I'm wrong: What you are trying to do is compare the first column of file 1 to the first column of file 2. So let's say you put all of the Strings from column 1 of file 1 into an ArrayList. Now, let's say you put all of the Strings from column 1 of file 2 into another ArrayList. This gives you the following variable declarations, if I were you, I would make them class variables (so declare them inside the class, preferably right under the class name):

public class yourBeanInfoClassIForgotTheNameOf{
ArrayList<String> file1Column1 = new ArrayList<String>();
ArrayList<String> file2Column1 = new ArrayList<String>();

//Blah blah blah, your methods go here
}

Now, you have a few issues at this point. You need to read in your data into those ArrayLists, and you want to know whether or not what's in file1Column1 matches anything that's in file2Column1, but you also want to keep all of the other Strings (the ones that aren't in the first column) from the two files, and you want to know what column they were in so you can print them out later. Going back to where we declared our two ArrayLists, at this point, I'd probably make a small class to handle keeping the data together.

public class OneRow{
//This is the String from the first column
String firstColumn;
//This is the remainder of the row
ArrayList<String> restOfTheRow;
}

For example, if you had the following file:

book, chapters, pages
phone, plastic, …
kvprajapati commented: Great explanation. +5
KirkPatrick commented: You did a great job explaining in this post, appreciate the effort. I didn't fully understand it back when you posted it. Thanks again bud +2
BestJewSinceJC 700 Posting Maven

And also post what error you are getting. If you are successfully reading in the radius, then 2 * radius should give you the diameter without problems as long as the radius is declared as the correct type (i.e. float or double).

BestJewSinceJC 700 Posting Maven

Put your code in code tags so that we can see what line numbers those are.

BestJewSinceJC 700 Posting Maven

I don't understand your code, but it shouldn't matter what order the user enters the Dates in. You can still get the difference between them either way. Also:

Use classes that already exist. http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html

If you wanted to, you could extend Date and override the compareTo method, making it return the number of years difference between the two Dates. This way of doing things would be a lot easier than what you are doing right now. Essentially, to extend the Date class and override the compareTo method, you would declare your class like this:

public class YourClass extends Date{
@Override
public int compareTo(Object o){
//Your code for comparing the dates goes here.
}
}

Alternatively, you could write your own Date class that had the variables you want (such as Month, Day, Year), and write a method that compares two dates in there.

BestJewSinceJC 700 Posting Maven

I'm not saying that ignoring the warning is a good idea, but it has never caused me problems before.

BestJewSinceJC 700 Posting Maven

And inner classes can provide specific functionality for their parent classes. There are relevant examples in the Sun tutorials on inner classes.

BestJewSinceJC 700 Posting Maven

Try to post things when you figure them out so that other people can see them. Not a big deal, just saying.

final JOptionPane optionPane = new JOptionPane(
    "Yes or no?",
    JOptionPane.QUESTION_MESSAGE,
    JOptionPane.YES_NO_OPTION);
BestJewSinceJC 700 Posting Maven

edit, sorry guys. Combined the two posts.

BestJewSinceJC 700 Posting Maven

Yes. Because you have no main method - you need to put any code (other than variable declarations) inside methods. The main method is the method that runs when you first start your program, *edit*


Oops, nevermind - I see that you do have a main method. For statements like String lang, then lang = "abc", you would need to initially just say String lang = "abc"; . . and what I said about only having variable declarations still stands. lang = "abc" is an assignment statement, and thus, isn't allowed unless you do it inside of a method.

BestJewSinceJC 700 Posting Maven

Yeah, I think that is what vidaj was talking about. . if the OP wasn't running his code on the EDT, then I think vidaj was saying that is why it wasn't working.

BestJewSinceJC 700 Posting Maven

1.

add( new DynamicPanel1().getD1());

Calling the "getD1()" is redundant here because when you say new DynamicPanel1, you are creating a DynamicPanel1 Object. The getD1() method returns a DynamicPanel1 Object, so you see, you already did that anyway.

2.

"got the removing.. but my main problem is how to add my panel 1 to the main frame if click the button from panel 2?"

Think the problem out a little more thoroughly: You have three Objects - your main frame, your panel 1, and your panel 2. What you want to do is add panel 1 to the main frame from within panel 2's class. So if your panel 2 constructor takes two arguments: the main frame and the panel 1, then you can accomplish this. For example:

public class DynamicFrame extends JFrame{
      public DynamicFrame(){
         public void actionPerformed(ActionEvent e){
              add(new DynamicPanel1(this));
          }
      }

....

public class DynamicPanel1 extends JPanel{
 DynamicFrame myFrame = null;
      public DynamicPanel1(DynamicFrame frame){
       myFrame = frame;
      public void actionPerformed(ActionEvent e){
          //Is this where you want to create your DynamicPanel2?
          //I noticed you never created one... I'll show you how you'd
          //create it though:
          new DynamicPanel2(myFrame, this);
      }
      }

....

public class DynamicPanel2 extends JPanel{
     DynamicFrame myFrame;
     DynamicPanel1 myPanel1;
      public DynamicPanel2(DynamicFrame frame, DynamicPanel1 panel1){
       myFrame  = frame;
       myPanel1 = panel1;
     }
      public void actionPerformed(ActionEvent e){
       myFrame.add(myPanel1);
      }

It seems like you're making a legitimate effort to learn, so in this case, I think it is best to see how it is done …

BestJewSinceJC 700 Posting Maven

It also looks like you need to separate your logic into methods that each do one specific task. Right now your code is pretty hard to read and understand.

KirkPatrick commented: Thanks again for everything, hard to believe that you are also an intern. You're quite a few steps ahead of me, but im definitely glad to get the chance to learn and have such helpful fellows around to show me the right techniques +1
BestJewSinceJC 700 Posting Maven

I disagree. The Sun tutorials are quite good. The reason they extend JFrame a lot of the time is because your code is an implementation of the JFrame class's functionality. But whether or not you subclass JFrame is largely irrelevant - it can be done either way and doesn't really impact your design negatively either way. But anyway, the Sun tutorials are extremely good, they give a very good and detailed foundation to begin doing some serious work with Swing. You're the first person I've ever heard of complaining about those tutorials... btw, do you use SWT? In Swing they are called Components not widgets...

BestJewSinceJC 700 Posting Maven

No. But I'll help you more tomorrow & explain in more detail, I have to look at your problem more closely to give you more specific advice.

BestJewSinceJC 700 Posting Maven

You can pass the frames and panels around as necessary to your classes. For example, if you needed to use a JPanel inside of a class called MainFrame, your MainFrame constructor could look like the following:

public MainFrame(JPanel panel){
varToStoreThePanelIn = panel;
}

Then when you needed to add things to other containers, it would be easy to do using the container's add method.

BestJewSinceJC 700 Posting Maven

As far as I know, a psychology degree doesn't really help all that much in the computer industry. But the good news, if you're a US citizen, is that IT is not suffering in the US economy. Yes. . I think you can get an internship even though you are a senior. I don't think you will have trouble just because you started late. But like I said before, I'm an intern myself, not a hiring manager or anything. Just be confident and don't be shy in interviews. Good companies are interested in interns who are social, intelligent, and interested in learning. Not necessarily people who already know everything going into the job. Out of the interns at my work, only maybe 10% had a decent amount of experience with the tools we're using. Yeah, I'm decent at Java programming. . but I wasn't asked many programming language specific questions in my interviews. Questions are more about your strengths and weaknesses.

BestJewSinceJC 700 Posting Maven

In the actionPerformed method put your code that removes the panel. The easiest way to remove a panel would be to keep a reference to the panel, i.e., have a JPanel class variable and set it to the JPanel that you are going to want to remove later. Then use the remove method found here: http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Container.html#remove(java.awt.Component)


So you'd say jPanelItsStoredIn.remove(jPanelThatYouWantRemoved);

Alternatively, at least for BorderLayout, you can use the BorderLayout's methods to get the Component at a specific place in the BorderLayout. You can probably do this for all the Layout Managers. But keep in mind that no matter how you remove the Component, you'll have to keep track of some information to remember which Component you want to remove (if the Container [JPanel in this case] you're removing it from has more than one component in it). If it only has one Component in it, you can use the Container class's getComponent type methods to get it easily.

BestJewSinceJC 700 Posting Maven

So let me see if I understand. You have five "areas", each of which you want to be connected to the other areas, and you want to be able to adjust the size of each of them?

Sun tutorial on JSplitPane, some paragraphs in:

"You can divide screen space among three or more components by putting split panes inside of split panes, as described in Nesting Split Panes"

BestJewSinceJC 700 Posting Maven

You should not use Frame. Use JFrame. I've never even seen anyone use Frame before, so it's safe to say that it doesn't matter why it isn't working as long as using JFrame works for you.
http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html

And I think it's safe to ignore the warning about Serializable unless your class implements Serializable, which it does not.

BestJewSinceJC 700 Posting Maven

Hi... use code tags as explained in the stick. And what is your question/problem?

BestJewSinceJC 700 Posting Maven

sillyboy is right, that is what I meant. But it was just a guess, I'm not positive that is what's going on. If the email account normally goes into the regular inbox, then it is probably a good guess though. And I have no idea about solutions, but that is territory that the mods here might not want answered anyway.

BestJewSinceJC 700 Posting Maven

Your explanations at the bottom look like a teacher wrote them. Nice attempt at a disguise. Either way, we don't do projects for people - post your attempt at a solution, then we'll guide you.

BestJewSinceJC 700 Posting Maven

for loosely related info, you could check out this thread that James and Ezzaral helped me out in before:

http://www.daniweb.com/forums/showthread.php?t=187103&highlight=mvc

BestJewSinceJC 700 Posting Maven

I actually don't understand the pattern. Enlighten me.

BestJewSinceJC 700 Posting Maven

Probably because Gmail detected a script was sending it?

BestJewSinceJC 700 Posting Maven

*Explanation: You can only use the getValueAt method to get the value that is currently showing in the JTable. In order to "get all of the values in the JComboBox" (that's what you want to do, right?), you would first have to get the JComboBox itself, then you would have to loop over the items stored in that JComboBox. I modified the code I'd shown you earlier (from Sun's tutorials) to do just that. Below, you'll notice the line sportColumn.setCellEditor(new DefaultCellEditor(comboBox)). This line is important. sportColumn is your column from the JTable; Each column has what is called a Cell Editor. The Cell Editor controls the rules for editing a cell's data when the cell is being edited by the user. From the line I showed you, you'll see that a new DefaultCellEditor is created, and the comboBox is passed to this editor. Hopefully now it'll be clear why later, I call sportColumn.getCellEditor().getTableCellEditorComponent() - the ComboBox is the component that your values are stored in, so it is what we want to get (so that we can save the values to a file later).

JTable table = new JTable();
table.addColumn(new TableColumn());
TableColumn sportColumn = table.getColumnModel().getColumn(0);
JComboBox comboBox = new JComboBox();
comboBox.addItem("Snowboarding");
comboBox.addItem("Rowing");
sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
		JComboBox box = (JComboBox)sportColumn.getCellEditor().getTableCellEditorComponent(table, null, false, 0, 0);
		for (int i = 0; i < box.getItemCount(); i++) System.out.println(box.getItemAt(i));

*hopefully this helps, I just looked into it for you, so its possible that what I said was wrong, lol. But I've done a decent amount with …

BestJewSinceJC 700 Posting Maven

To give you an example of how to get the JComboBox that is the editor for your Table, specifically, for a TableColumn within that JTable. Note: I'm unsure if the way I called getTableCellEditorComponent was technically correct, so you should check the javadocs on what the arguments for that are for, but it got back what I was expecting.

JTable table = new JTable();
table.addColumn(new TableColumn());
TableColumn sportColumn = table.getColumnModel().getColumn(0);
JComboBox comboBox = new JComboBox();
comboBox.addItem("Snowboarding");
comboBox.addItem("Rowing");
sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
		JComboBox box = (JComboBox)sportColumn.getCellEditor().getTableCellEditorComponent(table, null, false, 0, 0);
		for (int i = 0; i < box.getItemCount(); i++) System.out.println(box.getItemAt(i));
BestJewSinceJC 700 Posting Maven

Someone could easily come here and STEAL the code and claim it as their own.

I don't want anyone STEALING my code.

From now on I am NEVER posting here.

Daniweb is the WORST place for help anyways. I got it resolved myself. Great.

I am DONE with this forum and WILL NOT recommend it to my fellow students or anyone in the future.

I don't know which part of your post is more ignorant. I'm still dumbfounded that you have the audacity to waste people's time (James in this case) and then tell them that their help was not worthwhile. And I'm also wondering why you would post on a forum which primarily deals in programming questions and programming help, and expect those posts and those people's efforts to help to be erased just because of your selfishness. Furthermore, this site has 500,000+ members, and nobody cares if some bratty kid who expects quick solutions - not guidance - to his problems doesn't recommend the site to his friends. I'm sure there will be no shortage of kids who expect their homework done for them. [/irony]

VernonDozier commented: I agree wholeheartedly. +17
BestJewSinceJC 700 Posting Maven

Whoops. Good point. I'd give you more rep for that but apparently I can't since I gave you rep today.

BestJewSinceJC 700 Posting Maven

They are not going to do that. I've seen them refuse to do it before, and rightfully so. Anyway, by posting here or on any other site, you essentially give the site the right to display that work indefinitely. Are you afraid of failing a class or something?