JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

if(names.equals(n))

names is an Enumeration

n is args[0] which is a String.

An Enumeration and a String can never be equal.

ps: Hashtable is designed for this kind of thing, so it has other methods that you will find very useful... spend 10 minutes reviewing all its methods before choosing which to use.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you only need one array.
Yes, the numeric value of the char the decimal for it in the ascii table.
Not exactly ... Java uses 16 bit UniCode to store characters, and these are only the same as ASCII for codes up to 127. ASCII extended characters are basically irrelevant in Java as UniCode handles all such symbols far better.
Having said all that, you don't really need to know the decimal equivalents, just use chars and they will work as both letters and numeric values as if by magic, eg

for (char c = 'a'; c <= 'z'; c++) System.out.print(c);
or
array++;

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Remember Java chars are numeric - ordinary characters correspond to integer values under 128. If you have an array of 127 ints you can use a char as the index to access an element of the array and increment it...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are confusing Objects with variables. A variable is reference (pointer) to an Object. You can't assign null to an Object - that doesn't even make sense. You can assign null to a variable - it means that the variable stops referring to an Object and now refers to nothing.

Box yellowbox=new Box();
Box redbox=new Box();
...
redbox=yellowbox;

You create two Box objects by executing new Box() twice. Variable yellowbox refers to the first Box, and redbox refers to the second Box. But then you copy yellowbox to redbox, so now both variables refer to the same object (the first Box). You no longer have a reference to the second Box, so you can never use it in any way, and it will be garbage collected.
Some time later you assign

redbox=null;

Now redbox refers to nothing, and if you try to use it you will get a null pointer exception. The Object is not affected by that statement, and yellowbox continues to refer to it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could use an inner class for the listener that has the x,y coordinates as instance variables, that can be set by parameters in the constructor. When adding instances of this class to each button pass the appropriate values into the constructor.
Now there's no need for getSource or any of that stuff; just use the instance variables

buttons[i][j].addMouseListener(new myListener(i, j));

class myListener extends MouseAdapter {
   private final int x,y;
   public myListener(int x, int y) {
     this.x= x;
     ...
   public void mouseEntered(java.awt.event.MouseEvent evt) {
      System.out.println("*hover over* I am button " + x + ", " +y));
      ...
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

|| will only work for boolean expressions, but equals(...) does return a boolean, so it's perfectly OK like that. I don't know what your error message was, but it wasn't because you used || between two calls to equals(...)

Maybe you tried something like
while(grade.equals("A" || "B" || ...
becuase that certainly won't compile.

joankim commented: thanks :) +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Glad that' solved, so here are a few comments for next time...

That's Java code and Java syntax problems, so this is the right forum to post in. while(grade.equals("A" + "B" + "C" + "D" + "F")) I think I can guess what that was intended to do, but it would never work. For Strings, + is the concatenation operator, so you code is equivalent to while(grade.equals("ABCDEF")) which it never will be. You presumably meant something like while(grade.equals("A") || grade.equals("B") || ... although if you want to be cunning about it you could use while("ABCDEF".contains(grade)) Instead of all those if / else if blocks you could use a simpler and clearer switch statement. From Java 7 you can use Strings, but for earlier versions you just need to convert your grade String to a char. hasF == true is a redundant expression, exactly equivalent to hasF

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. For GUI -related timing you should use a java.swing.Timer rather than a java.util.Timer because it integrates with the whole swing event queue/ thread environment.
http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html
2. If you are updating some thing that affects the GUI you need to call repaint() or one of those methods to let the GUI know that it needs to be updated.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DaniWeb Member Rules include:
"Do not hijack old threads by posting a new question as a reply to an old one"
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe missing a revalidate or pack() or one of those things that update the layout manager after adding the second panel? - I don't use BorderLayout in dynamic situations like this, so I'm not sure...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
p2.setLayout(null);
p2.add(label, BorderLayout.CENTER);

Why set a null layout then try to use a BorderLayout option? If you want a null layout manager then hypou have to supply complete bounds for p2.

ImageIcon img = new ImageIcon(x);

There's a gotcha with new ImageIcon - if it fails for any reason whatsoever it just returns null - no Exceptions are thrown. null is a valid parameter for the image icon in a new JLabel, so that doesn't give you an error either, you jus don't get an image. So, you should always test for your ImageIcon being non-null.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, so it's in text/string format.

As you have already been told, you can't just overwrite line 2 in the file. You have to read the file in, update it , and write it back out again.

What follows isn't the slickest or most expert way to do that, but it breaks it down into three easy steps for you to code one at a time.

1.1 Create a String array big enough to hold all the lines of the file (4?)
1.2. In a loop read each line of the file into the array, one line per array element.
1.3 Print the array [ System.out.println(Arrays.toString(myArray)); ] to confirm that's working. Debug as necessary.

When that is working:
2.1 Convert your new long value to a String
2.2 Use that to replace the second element in your array
2.3 Print the array [ System.out.println(Arrays.toString(myArray)); ] to confirm that's working. Debug as necessary.

When that is working:
3.1 In a loop write each element of the array to the file, one line per array element.

stultuske commented: can't make it much more clear than this +12
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Lines 17,18 are executed regardless of whether you have found the account to delete or not - they are outside the if test.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can populate a JComboBox with any kind of Objects, and it will use the objects' toString() method to display the object, but when you query the selected item you will get the original object.
If you don't want to have your toString() method just returning the name, then use a ListCellRenderer on your JComboBox to format the objects the way you want

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The threads do not "give control to each other randomly". The Operating System gives control to neither, or one of them, or all of them, according to its own rules.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The only problem with that is if there are many many such lists you will have to go to all of them to remove any possible references. If that really is a problem then use the solution I mentioned - in Item have

ArrayList<List> placesWhereThisIsReferenced = new ArrayList<List>();

then whenever you add this item to a list, add the list to placesWhereThisIsReferenced
The to delete the Item everywhere

for (list list : placesWhereThisIsReferenced) {
   list.remove(this);
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm here to help you learn Java, not do your homework for you. It's not hard, just give it a try.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 7 is that a "" or a " " ?
When you get bugs like this try printing your working variables at key stages in the code, eg if you printed the contents of decryptArray, or even just decryptArray.length, that would confirm whether or not your split was working.

Ntropy commented: What a legend +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, they are doubles, and nothing can change that.
When you use df.format that takes your double value, formats it according to the specified format, and returns that value to you as a String. So you need to declare a String variable to hold the formatted value.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No. I said declare the parameter as final, as in

public void ammend(final Broadcast[] item){

bRyANthen commented: A brief guide, understandable =] +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You didn't declare item as a local variable, but you did use it as a parameter name, which is much the same thing, thus masking the class-level variable. Try declaring the parameter as final.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

At a guess that actionListener is attached to a JButton, yes?
So e.getSource() returns the source of the action, which is your JButton
You then try to cast it to a (JPasswordField), and that's illegal. You can't convert a button to a password field.
What you need there is to access the password field that was declared in you main form/window somewhere (code not posted, so I can't say more)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Assuminbg this is a Java question, not JavaScript, use a JFormattedTextField

Formatted text fields provide a way for developers to specify the valid set of characters that can be typed in a text field. Specifically, the JFormattedTextField class adds a formatter and an object value to the features inherited from the JTextField class. The formatter translates the field's value into the text it displays, and the text into the field's value.

Using the formatters that Swing provides, you can set up formatted text fields to type dates and numbers in localized formats. Another kind of formatter enables you to use a character mask to specify the set of characters that can be typed at each position in the field. For example, you can specify a mask for typing phone numbers in a particular format, such as (XX) X-XX-XX-XX-XX.

http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in doing your homework for you.

DaniWeb Member Rules include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies
http://www.daniweb.com/forums/announcement8-2.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you're using Windows then it's possibe to get this problem because Windows file names are not case-sensitive, but files within a jar are case-sensitive. So if the file name in you code differs in case from the real file name it will work in Windows, but not in a jar.

Joey_Brown commented: Gr8 guy! +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

On the contrary, it's absolutely essential. Every view class instance needs a reference to the controller class instance so it can pass requests back up to the controller.

ps: Normally its the controller that creates the new view window/tab, and passes a reference to itself as a param to the constructor. The other common parameter is a ref to the Model instance that this view is expected to work with. So somewhere in the controller you usually see something like:

JComponent aView = new OneOfMyViews(this, theModel);

Bladtman242 commented: Thank, this has been bugging me for a looong time :) +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, absolutely. And they can be very useful too.
Those things are called "Types", and the whole topic is called "Generics"

Here's the tutorial:
http://docs.oracle.com/javase/tutorial/java/generics/index.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you try following the instruction in the error message and changing it to

switch (dir) {
  case RIGHT:
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Was that sarcasm? I wanted you to work it out for yourself. That way you will really understand it, and never make that mistake or any variant of it again. I could have just posted a corrected version of line 3 from your original post, and you could have pasted that into your code - problem solved, nothing learned. It's the DaniWeb way.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If the field is an Object then yes (unless null is a valid value for it). But if it's a primitive then no, because they all have default values (0 or false).

Looking at all the info you have provided so far I would suspect that ip is null for some value of i

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In my opinion, that shouldn't be a problem because I haven't specified values for indexes 2 and 3. However, I changed the number of elements in my array to two elements and I'm still getting the same error. Anyway, thanks for your comment.

Unfortunately for you, in Java's opinion any attempt to reference an element bigger than the array is an error. If you have an array of 3 elements you can only refer to nums[0], nums[1], nums[2]. Any kind of reference to nums[3] is an error, whether you've specified values or not.

You still have exactly the same problem in your for loop. The way you coded it gives values for i of 0,1,2, and 3. When you use i=3 as an index for your array that's the error. Look again at your for loop, and especially it's termination condition.

stultuske commented: well explained for those who actually read it. +12
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is normally done by using a JScrollPane (which has the scroll bar(s) and handles all the sizing and scrolling activity). Just create your JPanel and place it in a JScrollPane. Here's the tutorial:
http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Not exactly sure what you mean... is that like in front of/behind, or higher than/lower than (ie not overlapping logo & buttons). If its the second, then you could create 2 JPanels - one with the logo and the other containing all the buttons, and place one of these panels above (higher than) the other.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't have time now to understand the whole structure of your code, but at a guess you have two methods there, a paintComponent that should finish around line 62 and an initialisation method that includes all the following code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

With the code you posted it looks like you lost a } when you commented out all that code from line 40 in logo. It now looks like you have all your GUI creation code inside the paintComponent method, so every time it repaints it creates new stuff.

David321 commented: Really helpful +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Instead of all those text-style menus in dialogs, you could pop up a small window or dialog with buttons for each of the functions - that would be a more Windows-like approach. You could also decorate that window with a bank logo in the background.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Thank you so much it is working, can i know about the how to write the code ?

@zeroliken:
This is why you should never just post a solution to someone else's homework. You have successfully given the OP an opportunity to cheat, but taught him nothing. Next time please help the OP to learn how to solve their own problem and write their own code.

ps; If you must post code please indent it, and follow the normal Java conventions for variable names. Your post was not a good example for beginners.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, sorry about the confusion. writeInt in a for loop sounds right. Can you post the exact code? Remember that Java ints are 4 bytes, not 2. For a 2-byte int you need a "short".
Maybe you can post the original int array values, and a hex dump of what you expected and what you actually got in the file. That would allow us to home in on the correct solution.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Right. Now there a few things you need to fix. Here are some to start with.

Your String arrays are size 0. That means you won't be able to store anything in them. Later in the code you get the number of lines in the file, so you could use that to create arrays of the right size at that point.

You use a LineNumberReader, but you don't use the line numbers, so an ordinary BufferedReader will do instead.

You need to read each line into a String so you can parse its contents.

The way you call expand doesn't make much sense - you pass an (empty) array and a number, then assign the result back to the array. You have the same call for ip and port, but there's no way inside expand to know which is which and therefore what to do. And expand has no access to the actual input data to parse it anyway.

There's no attempt to parse the data, using either split or search'n'substring.

You never print the ip and port arrays, so there's no way to see if it worked properly.

ps: Or is expand supposed to re-size the array? That may make more sense. Since you provided neither code nor comments for it I just had to guess.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have an arraylist of Objects, that happen to be Integers, which you try to use to create an array of Strings. You can't store Integers in an array of Strings.
Here's what the API doc says:

public class ArrayStoreException
extends RuntimeException

Thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects. For example, the following code generates an ArrayStoreException:

Object x[] = new String[3];
x[0] = new Integer(0);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

k is defined as a String. There is no insert method in the String class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Simple rule of thumb:
Make all your variables private.
More complex real-world version of this rule:
Make all your variables private.

If, later on, you discover that other classes need some kind of access to something, create a public method.

In this particular case Scanner is a part of your user interface. That kind of console-based UI should all be in one class; if you have a Scanner used in multiple classes you lose control over the state of the Scanner - eg if you call nextInt() should you do something to move the Scanner to next line or not before some other class tries to read the next token?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. maybe next time a quick look at the forum guidelines before posting?
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies
You'll find we're quite friendly here, but a bit impatient with people who don't want to do any work themselves.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

reverser.toString();
This line creates a String and returns it, but you do nothing with the returned value. It doesn't change reverser in any way.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could try setting a timeout before the receive ( setSoTimeout(2000) ) and see if your code continues as expected after the timeout elapses (catches a java.net.SocketTimeoutException) - this would confirm that your code is OK but you are not receiving any UDP packets on your port (maybe a firewall or other network configuration problem)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You're getting into a tangle with inner classes and whether they are static or not. Rather than get into all that obscure theory, I would not make them inner classes at all. You can keep them all in the same package if you need to group them together for access control or whatever.

abstract class Person{}
abstract class Employee extends Person implements myInterface{}
class Agent extends Employee { ... }

ArrayList<Employee> employeeList = new ArrayList<Employee>();
employeeList.add(new Agent(myStringArray));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you define a variable you can initialise it with a single expression that returns a suitable value. You already know about int a = 99; or maybe int secondsPerYear = 365*24*60*60; so this is just a slightly more complex example int b = readF.getNumberOfLinesInMyFile(); What you cannot have is an initialisation expression outside a variable declaration.

(To be exact - there are also things called instance initialisers, but you don't need to worry about those now.)

ps: You don't need your lignesDeMonFichier variable because ArrayLists have a size() method that gives you the number you need. By calculating it yourself you just do more work, and create the possibility of getting it wrong sometime.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You've made the common mistake of overriding paint rather then paintComponent.
JPanel's paint method calls paint for all its child objects as well as calling its own paintComponent, but you have overridden it thus bypassing the calls to paint the label. Just override paintComponent instead of paint and let Swing do its work.

http://docs.oracle.com/javase/tutorial/uiswing/painting/problems.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you mean join side-by-side, or overlay one image on top of the other?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So how many server computers are you talking about? If you want to hand the connection off to a different computer in a server farm, then sorry, I don't know how to do that. If it's two threads on the same machine then there's no advantage in changing ports.