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

"Components" don't have any kind of "positioning" features. You place components into layout that is part of a container, and that layout takes care of the positioning. Also, the border is "removable" on all swing elements, see the "sertBorder" method and the "EmptyBorder" class.

For full positioning control use GridBagLayout (you have x/y coordinates there, but probably not how you're thinking of them), but that is the hardest layout manager to use correctly.

If you feel you really must control all features of the layout then google for "Java Swing Null Layout". Be forewarned, however, that the slightest differences from machine to machine (I.E. resolution, OS, system font settings, etc, etc, etc) will probably "break" your GUI using Null Layout.

Olliepop commented: Thanks for the great reply, bookmarked :) +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster

What do you think, and why (do you think that)?

We are not here to do your (home)work for you, we will help to correct your errors, though.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Like I said, use substring on the strings and call hashcode on that substring.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay, but you claimed that the second block was catching the exceptions, and, in fact, the code doesn't even compile, so on what were you basing your supposition?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay. So what's wrong?

The try block, as posted, doesn't even compile, bacause, with the point we just illuminated above, the ArithmeticException block is an unreachable block of code which is, then, uncompilable.

So, what's the actual, compilable code look like, and what's your problem with it?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay? So would you expect the ArithmeticException catch block to ever be executed?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

According to the API docs What class does ArithmeticException extend?

Considering that, do you expect that catch block ever to be reached?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Use substring on the string first and call hashcode on the returned substring.

Edit: BTW "as part of a project" tells us nothing I still don't even know what it is you are actually attempting. If you were to tell us the why you only want the hashcode of the last few chars (or the last few digits of the hashcode, you don't seem to be too clear on what it is you actually want), i.e. what the eventual goal is, we could probably help you out a bit more.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

With a post requet you simple feed the var=value&var=value String through into the output stream.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Why do only want the last two digits? In any case, to return those as an int simply do modulus 100. Do you know what hascode is meant for? Even if you do only return the last two digits they will still never match the original String. What, exactly, are you trying to acheive? What is your goal with this entire thing?

BestJewSinceJC commented: Haha, whoops. My answer was overkill +4
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, certainly not with * and +

You're looking for substring if you really want to do that, but I don't see any poinf to it, especially since hashcode is suppossed to return an int and not a String, so returning the "last 2 or 3 chars" isn't even applicable.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

It looks as though you executed the script without any arguments.

I.E.

./display

instead of

./display a b c
masijade 1,351 Industrious Poster Team Colleague Featured Poster

i'm confuse now i'm using bash shell but is my code above correct or not?

Works for me, but it wouldn't for you if you were using a c-based shell (csh, tcsh, maybe others). That's why I asked, since you said it wasn't "working".

How does the output differ from what's expected?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Did you include a "#!" line in the script (if you don't know what I mean, that means you didin't)?

If not, what is your shell?

If yes, what shell did you use (hopefully a bourne based and not a c based)?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You need to use $0 - $3 (and $#, etc) in your code. Try again. And then post your code. No one here is just going to give it to you.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What is wrong with this thread?

What is this int[] that you want? If it is the RGB values for the entire image, then simply use the getRGB method I posted in your other thread and don't worry about creating a "Raster" object at all. If it the RGB values for a single pixel row of the image, you can still use that method I posted in your other thread, you just need to slightly change the arguments.

Edit: And I am locking this thread now, continue in your other thread.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

One of the simple read methods.

FileInputStream fis = new FileInputStream("file");
String text = "";
byte[] buf = new byte[8192];
int read = 0;
while ((read = fis.read(buf)) >= 0) {
  text += new String(buf, 0, read);
}
fis.close();

As a simple example.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Try using '\r' with indexOf. The other thing that would help us is knowing how you're reading the file. If you are using "readLine" then \r \n \r\n are taken as line endings and stripped from the returned String.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, getDataBuffer is only contracted to return a "DataBuffer", whether that "DataBuffer" is a "DataBufferByte" or "DataBufferInt", I would assume varies from image type to image type, and, seemingly, your compress method winds up changing it the to different type than what "createScreenCapture" returns, thereby changing the type of "DataBuffer" that underlies the image.

If you need the int color values array behind an image (and you have a BufferedImage anyway) then use the getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) method.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What? What are you talking about? If you need these "bytes" as "chars" then do new String -> toCharArray There is no reason you cannot do that, unless those "bytes" do not represent characters (i.e. a String) and so "converting" them to chars would be pointless anyway.

I still have no idea what you mean by "Her teststr is Vector". Are you saying that this "byte buffer" is a serialised Vector object maybe? In which case this "conversion" is less than pointless anyway.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Uhm don't cast?

We might be able to give you some real help if you would post the exact and complete error message and full stack trace as well as some relevant code (using code tags).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If some of those "things" are Strings, use String's equals method rather than == to compare them. (I'm assuming efname is a String.)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Why use getBytes? Why don't you use toCharArray? In any case, the easiest way (although not necessarily the most effecient) is to do new String(byte[]).toCharArray() .

masijade 1,351 Industrious Poster Team Colleague Featured Poster

When you pass a string to .split instead of a regex, it uses that string to create a regex, instead of using the original string object you've passed.
This is a bug I make every possible time. :S

Huh? Every String you "pass to split" is a regex, whether you intended it to be one or not.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, first I can say that doing e = null after having done e= idx is redundant. If idx is null at that point so is e.

Another thing I don't understand is why you only ever return the first item. Is that what you want?

Also, if the method "does not stop", I can only assume you have a loop somewhere in your list I.E. (0 is start)
0 -> 1
1 -> 2
2 -> 3
3 -> 1

masijade 1,351 Industrious Poster Team Colleague Featured Poster

no i havent got a main method in the calsses....this is an applet program..if so where should i include the main method in the class???

Well, then say it is an applet, because when you post an unformatted mess, like you did, although another mod now added the code tags, I am not even going to attempt to read it.

When you simply plop code and an error message onto the forum and don't provide anymore info, such as what you've tried to fix it, what you think the exception might mean if you don't understand it, etc, etc (IOW showing us that you are at least trying), then you are going to get answers from people taking as much thought posting them as you did posting your question. I.E. no thought what-so-ever.

If you'll notice, a link was included that explained the main method, which is what the error message was about and was so the only thing we had to go on, so I don't know what it was you had to complain about.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Read that link Peter posted and/or this one.

No, an Applet does not have a main method, but you don't execute from the command line either (although you can using the appletviewer command instead of the java command).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, do you have method "main" in those classes?

http://java.sun.com/docs/books/tutorial/getStarted/application/index.html

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You had better explore the legality of that, first.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay? I have no idea why anyone would want to "vote down" that post, but ......

To each his/her own, I guess. What about it was disagreed with would interest me though.

Salem commented: Sod the up/down thumb twiddlers, here's a vote that kicks ass! :) +19
BestJewSinceJC commented: .. up vote .. +4
masijade 1,351 Industrious Poster Team Colleague Featured Poster

An IDE is an Integrated Development Environment. It is, at it's most basic level, a jumped up editor with compiler capability.

Java Beans, at their most basic, are simple Java Classes where all members are private with getter and setter methods.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If you mean "the day after" the date provided, then see the Calendar class and it's add method.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No problem. Check the JCreator preferences/settings/options for a possible setting to "keep the execution shell open" or something to that effect. I do not know JCreator myself, but I assume it is opeing a command shell to execute in, which means that as soon as the execution is finished the shell will close. So, once again, simply search the options.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You can only change private members with a lot of effort, and none of them are recommended. Like I said, do not confuse access modifiers with real world security. That is the last time I am going to say it. Go through that posted tutorial and read the The Java Language Specification for more detail. I'm sorry, but I'm done here.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If it is public you can just directly access it (as shown above), if it is private reflection can still retrieve and/or modify it's value (definately not recommended), and with some libraries (E.G. BCEL) you can actually change the binary class definition (also, definately, not recommended), and all of this whether you are using an IDE or not, an IDE simply presents it to you without you having to dig for it yourself. I.E., an IDE makes it simpler, as with so many other things.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I never said you see the source code (although with decompilation, you do, at least a "compatible" version of it). You see it's declared members and declared methods and declared constructors.

Edit: I.E. their "names", their types, their access level, and their parameters (with type).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

if
totalPerDay += sales[j];
the total is total of the 6 days only rite?
i wan the total sales of each day(7 days) by all salesperson

Read the hint. Where did you declare the totalPerDay array, and with what length?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Reflection, decompilation, javap, hell, on Unix, the strings command, not to mention that every IDE will show it to you (they can also show you the private and protected members). It is not a secret. The format of the byte code is publicly available, and so there are many ways to read it, and many ways to change it. Do not consider these access modifiers to be real world security measures.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

u dont have the source code and u dont even know that there exits a variable by name tos.

And? Reflection, and or any IDE will show it to you.

all that u can do is enter the elements into the stack or popout the elements from the stack

so using of public or private
what differernce will it make?

As already stated, public you can easily change, private you cannot.

u dont have source code
u dont know that there exits a variable by name tos

The assumption, of course, will be that if it is public, it will documented just like the methods, so you will know about. And, even if it's not, reflection and every IDE will show it to you.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

When it is public, of course, when it is private, then only through the use of reflection. default (i.e. package) is good enough as long as you sign the packages in jars so that others cannot create classes in the same package.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

From PM

hai i am the one who posted the question by name data protection
in the stack program that i presented
lets change the aces specifiers to public..

now all the i provide the users is a compiled code.
now what difference will the usage of private make when compared to usage of pulic.

Can the user change the value of stack size if it is public?
but how can he change?
all that he will be able to give as input is elements
HOw can he aces the public data members?


one do private prevent accesing of data maliciously?
What is meant by acesing the data values maliciousl?
how is it done?

plzz help me with these questions:confused:

Keep it in the thread

You access public data members with

WhateverClass c = new WhateverClass();
c.whateverVar = whatever;

With private members you cannot do this.

See the tutorial posted previously.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No, not until I see what you want as public as there is also no "tpo" or "stacksize" variables. Post code, or ask a question, that actually pertain to each other, or we cannot help you.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

this

totalPerDay[j] += sales[i][j];

should not that first j be i?

Hint: Yes it should, according to the way that array is declared, but maybe (guaranteed) you declared the array wrong, in which case it shouldn't be.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Um, no, nothing in that class is public, not even the class itself.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I was taking that more as pseudo code and hoping that it wasn't an actual implementation. ;-)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If they are static there is no reason to create a "bank_account" object, simply reference the class (i.e. bank_account.search(whatever)). If your application is going to be threaded, however, you are going to have to synchronize those methods. A better solution in this case is probably a Singleton. Google for "Java Singleton Pattern" for information.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I didn't know that this was possible. Good.

Yep. Works with all static items, not just final static items, and not just variables.

//Class Test1
package t1;

public class Test1 {
  public static void printIt(String s) {
    System.out.println(s);
  }
}

//Class Test2
package t2;

import static t1.Test1.printIt;

public class Test2 {
  public static void main(String[] args) {
    printIt("Hello");
  }
}

Edit: Note. You can also use "*" instead of the var or method name and get all static items from the class. I would, in general, strenuously object to this. I also do not recommend using static imports at all except for static values that are being used multiple (i.e. more than 2 or 3) times in the "current" class. For the maintenance developer, it quickly becomes confusing. I.E. "Now where does that variable come from?" This effect is much worse with the "*", but can also be, at least, annoying for single values.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

There are no such thing as either golobal nor global vars. There are "constants" i.e. public static final variables, but they still need to be referenced through the class. That can be done in the imports however using a static import. I.E.

// class Test1
package test;

public class Test1 {
  public static final int cons = 1;
}

// Class Test2
package anotherPackage;

import static test.Test1.cons;

public class Test2 {
  public static void main (String[] args) {
    System.out.println(cons);
  }
}
javaAddict commented: Thanks for the new info +5
masijade 1,351 Industrious Poster Team Colleague Featured Poster

What about the following line (which is valid CSV) a,"b,c","d""e""f,g",h which should be

a
b,c
d"e"f,g
h

That's why you should look for a library, or you play around with indexOf and substring yourself (which I have been forced to do).