masijade 1,351 Industrious Poster Team Colleague Featured Poster

It doesn't implement it, it uses what the systems provide, logically. To implement it, it would need to be able to reach must deeper into the OS (and probably the hardware) than Java is meant for, of course.

Edit: Besides, the JDK comes with the src. Look at those classes and follow them through and you will see for yourself where it "disappears" into the system with the "native" calls.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If you need to ask this, then you definately do not need a new networking protocol, but simply want a new protocol on top of either TCP or UDP (like HTTP, SSH, most DB protocols, etc, etc, etc).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The "search" function would be performed in a Thread of its own, of course, but that does not, necessarily, mean that the "search" function need be a class in and of its own. You will need to create a Class extending SwingWorker (if you use that) that does nothing more than execute your "search" function, however you do not, necessarily, need to rewrite whatever classes/methods you already have that actually make up the "search" function. You probably need to study up a bit on threads in general, but for starters, like I said, see the SwingWorker class and tutorial.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

See SwingWorker. Your problem is that you are performing your "action" on the Event Thread, rendering it incapable of responding to "user events".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Then actually use that socket, and have the "second" one simply send a "message" to it and have the "first" react to that.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Do not cobble together statements like this unless you want to allow SQL injection attacks to succeed or want seemingly "random" SQL syntax errors due to invalid characters. See PreparedStatement.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Aside from your croos-post see the API docs for the File class and see if you can combine the length and delete methods.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Like I said, the foreach splits the input line, so now you do have a list of distances. The body of the foreach (the part between the braces) then uses each of these distances, one at time, as a key in the hash and increments the value at that position. If you know that the first part splits the line into individual distances, and you know what a hash is, and you know what foreach is, then I don't understand what it is you don't understand about that line.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If you'll notice, $_ in the hash is inside the foreach loop, meaning that it refers to that individual value for that iteration of the loop, or a single value resulting from the split of "string of distances" making it refer to a single distance.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Looks like the reader can't find what it is it is suppossed to be reading. The real question, though, is what that has to do with anything. You don't plan on directly incorporating this demo code into your code, do you? If so, we're back to "teh codez".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

This?
The first hit, looks promising (it "says" textfield, but uses textarea).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Yes, okay, it seems you already have an idea, so work with it. What, exactly, are you asking? (although I would say that "FileDialog" is wrong, "JFileChooser" is better). I would also use two JTextAreas. One to show the original text (possibly with the "searched" word highlighted), and one to show the search results (although a JTextField would be enough for a single word search.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

It seems to me you have everything you need, except "teh codez", of course, but those you're going to have to make yourself.


Now that that comment is out of the way, what do you need help with here? What about those requirements do you not understand?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, concentrate on the first one and try to fix that, then compile again, and again, concentrate the "new" first error, repeat the process.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Please describe "doesn't work".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

cross-post

And, according to a post in that thread, he's very happy to let people waste their time.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

So search on the forum. This question has been asked literally hundreds of times. Usually ridiculed, but there are some suggestions. If you feel you absolutely must ask, then start a thread, but be prepared to be ridiculed.

Closing this thread.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because a SimpleDateFormat is a SimpleDateFormat not a String.

new Date() will give you the current Date. and SimpleDateFormat's format method will allow you to format a String representation of that Date in any format you want.

Now, armed with that info and the API docs try it again.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No. Read my post again, read the api docs, and give it a try. This is not a homework service.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

- Clone the first arraylist into a third arraylist
- Call removeAll on the third arraylist using the second arraylist
- Clone the second arraylist into a fourth arraylist
- Call removeAll on the fourth arraylist using the first arraylist
- Call addAll on the third arraylist using the fourth arraylist
The third arraylist is now your end result. That is, if you need to retain the original two list.

If you not need to retain the original lists
- Clone the first arraylist to a third arraylist
- Call removeAll on the third arraylist using the second arraylist
- Call removeAll on the second arraylist using the first arraylist
- Call addAll on the third arraylist using the second arraylist
The third is, again, the result.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

echo "string" | grep "pattern"

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Edit: Nevermind.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Point taken, especially that no effort by Sunshineserene in at least delivering a sample code. ...That is the point...we should point that out to him, but do not be obsessed by the fact that you are doing homework for people, that you are helping people and that kind of stuff!!!! If these guys want their homework done, there are many avenues of doing such including paying to get perfect code.

No. The point is that he should write the code and others here should help him crrect it. The code should come from him and not you. Give a few hints at to what is to be done and let him do it. If it doesn't work he should post that code and ask for further help/clarification. Then you give him the next clue(s) as to what he has done wrong and let him try again. You still do not post a complete code. Repeat the process until the problem is solved. Guaranteed something will have been learned in that process in a manner that will stick. Normally, when provided with code, even if they do look at it and say "Oh, okay, now I understand", it is still something that is, normally, quickly forgotten, and so, useless.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Masijade indeed if this is his homework, Sunshineserene should be advised to avoid copying it because I must have been out of my mind to post the code:

Sunshineserene I understand your concern just study the charAt() method.

Oh C'mon how can you think it is not homework? What real-world application would ever need what is descibed there? And, knowing that, how do you think that doing it for him teaches him anything? He'll take it and hand it in and that's that, and tommorrow he will be even more lost than he was today.

However, if you insist on continuing to do homework for people, hopefully they come to work at the same company you work for (if you even do, yet, or ever) so that you can continue doing their work for them and let them get paid for it and you eventually get fired since your own work is not getting done.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

mbugua, do you consider the OP too stupid to understand the first reply so that you found it necessary to do his homework for him?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What do you think the "toCharArray" method of String is for?

See the API docs for String.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Is there whitespace at the end of the string?

Try with str.trim().starts... and str.trim().ends...

Or do str = str.trim()

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Anymore?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

That "code" doesn't even fit that "explanation".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I don't need to as I know it doesn't help. First, the OP is already past the part of reading the file and secondly (among others) using == true and == false is just plain braindead coding.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Hi,

I wrote for you an entire function see below

public void extract(String str1)
{
String str2 = null;
File file1 = new File(str1);
FileReader fr = new FileReader(file1);  
BufferedReader br = new BufferedReader(fr); 

while(br.readLine() != null)
{

str2 = br.readLine();

if(((str2.startsWith("ATOM") == true)) && (str2.endsWith("H") == false))
{
System.out.println(str2);
}

else
{
//do something if you want
}

}

}

The argument is the file location as a string

Richard

And how does this help?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

When you create a FileWriter you are creating a new file or overwriting an existing file (unless you use another constructor, but we are not going to get into that as it is not applicable here), as a look at the API docs would have clearly spelled out. So, create and close the FileWriter in the same places as the FileReader and simly write to it in the loop.

You really need to learn how to read the documentation, and then actually do that. You also really need to learn some investigation skills rather than hoping someone else will solve your problems for you. All of this has been fairly (when not really) simple problems with a little thought and investigation and all these threads of yours have taken days (actually weeks).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Look at the API for Color. What are those int values in that statement?

Now, what do you think you might try if you want Green?

In any case, see the Class JColorChooser, and then Google for the JColorChooser demo and run it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Simply show the lines that match. If you need to write them to a new file, then you also, of course, need a FileWriter.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What do you want to do? Do you simply want to display them, or do you wish to process the data in some way?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

$ matches end of String so how can you have the H after the end of String. And, of course, you want to match to the read String ("str") not to some bogus string "filename". What was that suppossed to achieve?

Also, why not startsWith and endsWith as already suggested (in a few of your other threads on this)?

if (str.startsWith("ATOM") && !str.endsWith("H")) {

will give all lines that start with ATOM and do not end with H. Is that not what you wanted?

P.S. Actually posting the code you try (as you finally did) rather than simply whining that it doesn't work, or doggedly pursuing your original path (which you'd already been told won't work), allows us to finally help you fix, and allows you to finally advance.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Yes, and No. A implements, and so, by default, those methods are "available" through the B Class, since B is an A, but B, it self, does not, technically, implement the other interface.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

As also said here. And, there was an old thread in which I had already said this, too. Stop starting new threads simply because you don't like that people are not telling you "yeah you're doing everything right, Java is just corked and so it's not working".

masijade 1,351 Industrious Poster Team Colleague Featured Poster
s/\/.*$//
masijade 1,351 Industrious Poster Team Colleague Featured Poster
if (s.charAt(i)=='1') count=count*value[i];//actually i want to use this data

Okay? That is how you access a single element of an array (the reason for the brackets containing an int index). That has nothing to do with referencing the array as a whole.

Like I said, go through those tutorials.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And I said to remove the brackets.

I.E. not

int value[] = ...
// or
generate(value[]...

but rather

int[] value = ...
// and
generate(value...

And, show me the real method signature for generate, as I hope that what you showed above is simply some psedo-code fill-in. If its not pseudo code, then compare that signature with the "main" signature and tell me what you think is missing (besides static although being called from main it needs to be that too), and your local variables in main should not be static.

Have you ever done anything in Java, or are you just throwing things around from PHP, or something, and trying them in Java directly. Because the more I llok at that code, the more it looks like something copied, and then modified by someone who has no clue what they're doing.

If you are just starting then go to the official tutorials and work through those before you attempt anything else.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

remove those brackets from the end of the variable name, both when calling the method and in the declaration. In the declaration, place them after int, not after value (they both work but this way is clearer).

Edit: And I hope that that "generate" signature is not a serious attempt.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

getComponents and instanceof

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If they are both on the same machine, or have access to a reliable shared disk (although the processes that create and maintain that shared disk also use sockets, so I guess that one doesn't count) yes. Is it practical? No. Is it effecient? No. Does it make any kind of sense, what-so-ever? No.

How are they to communicate? Telepathically?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If not is there another way to do this?

Yes, have the method return that "new" array.

Java is pass-by-value and pass-by-value only. If you want pass-by-reference, use another language. If you want to use Java, then you need to abide by pass-by-value.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

for the "beginning" of the scrollbar

scrollPaneVar.getHorizontalScrollBar().getValue();
scrollPaneVar.getVerticaalScrollBar().getValue();

Add these values to the above values to get the "end" of the scrollbar

scrollPaneVar.getHorizontalScrollBar().getModel().getExtent();
scrollPaneVar.getVerticaalScrollBar().getModel().getExtent();

Divide those summed values by 2 to get the "middle" of the scrollbar.

See the API docs for JScrollPane, JScrollBar, and BoundedRangeModel.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

It may seem helpful to a beginner, but it's not. IDE's are for people who already know what they're doing in order to increase their effeciency. You need to understand the tools and the processes behind everything and an IDE shields that from you.

stephen84s commented: Eggjactly +5
tux4life commented: Totally agree. +13
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Take a look at this.

class A {
  private JPanel p = new JPanel();
  public JPanel getP() {
    return p;
  }
}

class B {
  A a = new A();

  public void doit() {
    a.getP().add(new JLabel("A"));
  }
}

That's the way you do it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, where are you actually displaying PhotoPanel? I see you crating one, but you are not adding that Panel to anything. Part of "displayGui" in that Psuedo code above also inlvolves creating PhotoPanel and adding it to a JFrame of some sort. Then later you simply use setImage(image) and validate/repaint on the already displayed PhotoPanel object. You do not create a new PhotoPanel everytime you change the image, especially when you don't even do anything with that PhotoPanel. It doesn't just magically pop up onto the screen somewhere, you know?

Edit: Also, as already said, do not override paint, even if all it is doing is calling super.paint.