masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, if you're simply going to be reading the entire file into a single String without any kind of work on the lines read until after the entire file is read, I wouldn't use either of those, and wouldn't use a Reader at all. I would do it like this

File f = new File("filename");
FileInputStream fis = new FileInputStream(f);
byte[] b = new byte[f.length];
int read = 0;
while (read < b.length) {
  read += fis.read(b, read, b.length - read);
}
String text = new String(b);

This is, of course, missing all error handling. That's for you. This also assumes that encoding won't be problem.

You are not forced to use a Reader simply because what you're reading is a text file.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Sorry masijade I happened to look at this a few nanoseconds later I posted the second post. Did the slim chances just get FAT ? ;)

Not first-hand, but second-hand, definately.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

but the master links would certainly not carry wrong information

Well, these ones I don't believe do, but I wouldn't be too sure of this being a 100% correct statement either. It does happen.


BTW These are just a little colligate ribbing (don't go getting all defensive or anything).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

who would not be someone the author/developer trusted to do the job.

Are you sure of that? Chances are slim, but hey.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

can you please explain in your words

No. That's the whole point of your homework/test question. We are not going to do it for you. It is against the terms and conditions of this forum which you agreed to by signing up here (besides being morally and ethically wrong).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

hmmm in one program its also easy, he can do it also, if he know java ! well let me also post all these program into 1 class code ..

No, don't. Read the terms and conditions of this forum again (which you agreed to when you signed up here), as you've already violated them once, with your first post, don't do it a second time with just your third.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What part of your homework do you not understand? We are not simply going to do it for you. If you post what you have, and ask some specific questions about what you're having problems with, we will help though.

If it is simply that your personal life took precendence, then let it take precedence and own up to the fact and accept it's consequences.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because you didn't do it right?

Come on, how should we know, when you haven't given us any information to work with.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

they haven't provide any code or documentation for that ...

i searched but i didnt find any thing suitable..i need to write that code in myapplication.. i haven't find any smaple code which will help a bit..

You mean you didn't find anything you could block copy and paste.

The documentation describes how you interact with it (usually through http). So now the question is not "how do I send/receive sms", but rather "how do I perform an http connection/interaction". The answer to that is Http(s)URLConnection and another bit of Googling.

Gods, not everything you get will give you 1-to-1 examples of what you need to do in language "X". They will simply tell you what you need to do (I.E. use http protocol in "this manner"). Then it is up to you to implement that in language "X". So then you can start to research how to implement that.

Learn how to do a bit of thinking and research on your own or you will never be anything but a "code monkey" and not a very good one at that.

Ezzaral commented: Absolutely. +15
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Find an SMS Gateway (they provide internet service) and then read their documentation.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I checked all of my {'s.

Seemingly not.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I have looked at that thread before, didn't find it was of much help.

How could it not be? Do you honestly need someone to tell you how to access an environment variable?
( echo $RANDOM )
Or maybe how to store it's results?
( varName=`echo $RANDOM` )

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No, I was refuting your statement of "Shipping an exe file essentially keeps your source code protected".

You are more than welcome to help, but posting false information (knowingly or not), does more damage than good.

Edit: And that statement that was being refuted is definately not an opinion.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Native executables can be decompiled just as easily as class files. This is a "non-argument".

Edit: And don't ask me how, because I won't tell you. I am not here to instruct people on reverse engineering. I will say this though, "Just because you don't know how to do it, does not mean that it cannot be done."

masijade 1,351 Industrious Poster Team Colleague Featured Poster

mjah ... sarcasm doesn't take well in digital form, does it? :P

It's a bit hard to get the vocal stress points right. ;-)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

well...
excuse me for answering your question then

There is no excuse for you. ;-)

(Replace you with him, and the statement is true, though.)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Read the article I gave you.

And if you are receving through the handy, why don't you also send through the handy?

Conversly, if you are sending through nowsms, why are you not receiving through nowsms?

If they don't provide a reception service, then find a different gateway.

Edit: Of course, I hope you have some very, very, very good authentication system for this, as I am sure the customers would not want their balances to be broadcast to anyone with an sms service.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You don't, you create executable jar files (not "exe"s).

http://java.sun.com/docs/books/tutorial/deployment/jar/index.html

Edit: And, if you want a "real exe" (i.e. a native executable), then use a language designed to produce a native executable (which Java is not).

If you insist on doing something that will negate all the "advantages" gained by using Java and produce a native executable with it, then Google for some thrid party tools that are designed to do this (there are plenty of them). It is not a recommended course of action, though, so your on your own.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, hopefully you have a handy attached to the Server running the Tomcat.

IOW, AFAIK, you need some sort of Gateway to send/receive sms messages from the computer. There are some sites out there that let you do so (and you may be able to use them as a proxy, but if they find out you are using it for a commercial app, it would be probably get very expensive, very quickly), but to do it on your own, you are going to need a modem, not just a connection to the internet. And the use of this modem has nothing to do with Tomcat.

Check out this for more info (although not Java related it has some good general info) http://www.developershome.com/sms/

Edit: Nevermind, I see you are using a gateway. But, if that is an internet SMS gateway, what do you need your mobile for? You should be able to use it using HttpUrlConnection, right?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Who says a tomcat server would accept an SMS?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Welcome.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Assign that class instance to an instance variable, rather than a local variable, if you want to use that same instance throughout the class.

I.E.

public class A {
    private B bObject;

    A() {
      bObject = new B();
    }

    void whateverOne() {
        bObject.whatever();
    }

    void whateverTwo() {
        bObject.whatever();
    }
}

rather than

public class A {
    A() {
    }

    void whateverOne() {
        B bObject = new B();
        bObject.whatever();
    }

    void whateverTwo() {
        B bObject = new B();
        bObject.whatever();
    }
}
jbennet commented: fast reply +33
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Like I said, try JSch.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

:sigh:

Once again, that phrase about a posters knowledge of Java being inverse to the prominence of the word Java in the posters moniker, applies.

public class BogusExample {
  public static Random rand = new Random();

  public static void main (String[] args) {
    int one = 1;
    int two = 2;
    do {
        one += two;
        two *= rand.nextInt();
    } while ((one * 3) < two);
  }
}
public class BogusExample {
  public Random rand = new Random();

  public static void main (String[] args) {
    Bogus random = new Bogus();

    int one = 1;
    int two = 2;
    do {
        one += two;
        two *= random.rand.nextInt();
    } while ((one * 3) < two);
  }
}
masijade 1,351 Industrious Poster Team Colleague Featured Poster
Scanner myInput = new Scanner(System.in);
String input1 = "";
...
do {
  input1 = myInput.next();
  ...
} while (....

Split the declaration from the definition and put the definition as the first line of the loop.

Laidler commented: this post helped my fix my problem and was very helpful +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster

now the

}while(!(my Input.equals(s4)));

does not work because the myInput variable is not stated outside of the loop

You're right my Input is not, but myInput is.

Unfortunatly "myInput" is a scanner, not a String, and you want to compare Strings, so aside from moving the "read" line into the while loop (but leaving the declaration of Input1 outside of the while loop), don't you think you should be using Input1 in that conditional expression?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Ask IBM?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

i dont want you to do it I just needed some help where to get started, now can you help me that i posted my code so far?

Like I said

... this post looks like a "do it for me post", ...

with emphasis on the looks like.

What else are we to assume when all you do is block copy your assignment text?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Place the numbers generated into a Set. When you attempt to add something to a set that already exists in the set, the add method will return false, so keep generating numbers and adding them to the set, until the add action succeeds.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

True, do not do this from a JSP.

If you feel you absolutely must do this (regardless of whether you do it from a JSP or not, and, again, you shouldn't do this from a JSP), check out JSch from JCraft (www.jcraft.com). It is a (nearly) complete implementation of SSH2 protocol as a Java API.

Also, why are you attempting to copy JSP's around? This seems to me, to be a hacked way of attempting to implement a distributed/clustered/HA application. If so, look into admin tools that are designed to do this (and they won't be executed from the application itself).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The description is pretty detailed. Give it a try, and if you have problems with the code, then post what you've written and we'll help you correct it. But, this post looks like a "do it for me post", and that is not something we're going to do.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Define "does not work".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Only the one with the access modifier must be outside of the method, the rest, simply outside of the loop.

And, if you want to define (and not just declare) myDie outside of the method, then you must do it all at one time, not on two separate lines.

But, if it is not going to be static, then you will need to instantiate your class and use it through the instance.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

private, public, protected are access modifiers. They only apply to class and instance variables, not local variables declared inside of a method (which myDie is).

Also, in a loop, if you want to use a variable (lets call it var) in the conditional (i.e. in the var != whatever part), that variable cannot be declared inside of the loop (it can be defined there, i.e. getr a new value there), but it can't be declared there.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You can' use access modifiers inside of a method and you can't use variables declared inside of a loop as part of that loops conditional expression.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

what I meant by add line is 'append'. sorry for the misunderstanding, though. I thought that it is the common 'language'.

The thing is, there is no reason to read the file. You can create a FileWriter in append mode, so that anything written using it will be written to the end of the file, rather than overwriting the file (and if the file did not exist in the first place, it will still be created).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

so u know how to check whether or not the file is empty. Read the file then write it to your order.txt along with the new order.

that is the simplest way.

Uuuhhmm, what about "append"?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

So take a look at liang's answer again. It has nothing to do with the if statement, it has to do with the fact that you are creating a new FileWriter with every "button-click", which will overwrite everything that's been written before it.

If you want to recreate the FileWriter every time then do it in append mode

new FileWriter(file, true);

And, you should be closing the writer in the finally block, and, as your code is now, even if there is an exception, the "success" message will still be shown (that should be in the try block, and the close in the finally block).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

In what way?

You do know, it is always helpful if you post exactly what it is that is not happening as expected (along with all compiler/error messages).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

just change this

latestLine = read.readLine();
              System.out.println(latestLine);
            while(latestLine != null)
            {
                latestLine = read.readLine();

to

read = new BufferedReader(new FileReader(file));
            
            latestLine = null;
              System.out.println(latestLine);
            while((latestLine = read.readLine()) != null)
            {

It's because you are using the results of readline without first checking what it returned, and readLine returns null at EOF.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Maybe ask at a NetBeans Forum (www.netbeans.org maybe?)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

HelloWorld?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I was under impression that repaint() is called only when you working explicitly with some graphical content (images, lines, shapes etc.)

Well, it is a "Graphical User Interface". :P

I was under the impression, however, that validate triggered a repaint, which is the reason I waited until the end to try it. Guess I was wrong. Not the first time, won't be the last time. ;)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I'm sorry, but with some tests, it seems as though simply calling repaint after calling validate accomplishes your goal. (At least it did for me, although without it I also saw what you were experiencing.)

I would normally assume that a call to repaint() after a call to validate() would essentially be redundant, but seemingly not.

peter_budo commented: Yes in deed, reapint() does the magic. Thank you +12
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Yes, but what contains "mainPanel"? And how is mainPanel added to that container. Or is "mainPanel" the contentPane?

I have a more involved possibility but it involves the component that contains "mainPanel" more than it does "mainPanel" itself.

But, since you're saying that your adding "premade" Panels to mainPanel, then try this, as well:

Dimension d = mainPanel.getSiez();
mainPanel.removeAll();
mainPanel.add(addEP);
addEP.setPreferredSize(d);
addEP.setSize(d);
mainPanel.setPreferredSize(d);
mainPanel.setSize(d);
validate();

(and, if that works, you should probably be able to remove the two mainPanel.set*Size calls, but try including them, first).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

How is the component containing "mainPanel" constructed? Can you show that (without any of the code behind the constructs, but simply what components are in it and how they get placed in it).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The problem is that the panel will only cover as much area as it needs. Anything beyond this area is "ignored" during a validate on the panel (since that area no longer "belongs" to the Panel. 2 "quick" possibilites (I would try the second first).

Have you tried

Dimension d = mainPanel.getSiez();
mainPanel.removeAll();
mainPanel.add(addEP);
mainPanel.setPreferredSize(d);
mainPanel.setSize(d);
validate();

or

mainPanel.removeAll();
mainPanel.add(addEP);
mainPanel.getParent().validate();
masijade 1,351 Industrious Poster Team Colleague Featured Poster

A DB. JavaDB if you don't want to have to use a server.

Edit: Although this still looks like a "do my homework for me question", I will give you the benefit of a doubt, at the moment.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Nah, Pirates of the Caribbean ;-)

BTW (so you don't get the wrong impression) that was because of my kids. They watch that thing (at least until about 6 months ago) all the time.

aye, aye, captain!
Sponge Bob Square Pants!
Sponge Bob Square Pants!

Aaaarrgghhh, just shoot me now and get it over with! ;)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

How do you normally use an array?

String[] files = file.listFiles();
int numFiles = files.length;