JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please don't be offended - it's nothing personal. People here are more inclined to be forthright than polite for polite' sake. It's the information content that counts. :)

Using = true is wrong. That tries to assign the value true, not test for it. To test for it you need ==

But what I'm telling you is that you don't need the == true at all. It's a common beginner mistake to think every if test needs a logical operator (==, > etc). All it needs is a boolean expression, for instance a call to a method (like yours) that returns a boolean. Using the redundant == is a sign that the programmer didn't really understand boolean expressions - but that's usually just inexperience, not a character defect!

Bottom line: you just code

 if (if (isVowel.isVowelValid(letter)) ...

your method returns a boolean, and that's all you need for an if test.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This web site has an excellent article on how to store passwords (and how not to, and why). There's nothing I can add to what it says.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's no way the client should be starting or stopping the server that is handling the communications with the client! Maybe your problem comes from confusing the server that talks to clients with the server that talks to the printer? In my mind they are two different things.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java RMI would do that. It provides a version of the server's interface at the client end. Have a look at it, but be aware that it's pretty complicated and the learning curve is steep.
You may find it a lot easier to build you own simple protocol where the client sends one of a limited number of requests and the server replies as appropriate.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If it can only approach the wall from one side, then a simple test of the sprite's x value (for a vertical wall) is enough. Something like:

if (sprite.x >= wall.x) 
   sprite.xVelocity = - sprite.xVelocity // bounce off the wall

If the wall is a 2D object that can be hit from either side (or on the top) then use a Rectangle.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

if(user_name<22)

user_name is a String so you can't compare it to a number like that. Maybe you ahould be comparing the user's age, not their name?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This thread ends with a sample program I wrote to demo the best simple way to animate multiple things moving around the window. It also discusses collisions, which will probably be relevant to a ball game. Have a look at that then come back here with your follow-on questions.

NightOwl19 commented: thanks mate!! +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In real life nobody codes applications in bytecode. If you can't do something in Java then its very unlikely that you could do it in bytecode. Unless you plan a career in writing Java compilers or JVMs you will never write a single line of bytecode. The only time "normal" people ever see it is if they are desperate to optimise some terribly time-critical Java code, and even then the very next release of the compiler could invalidate their conclusions.

Executive Summary: Forget about bytecode

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you are entering the item names etc, check to see if there is already an item in the ArrayList with that name and price. If there is, add the quantity to the existing Item, otherwize create a new Item like you do now

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In the sort, instead of swapping names and gpas, just swap the two Student objects. That's easier, and it won't break when you add another field, eg date of birth, to the student class. It's also very bad practice for a sort to change the values in the objects its sorting, suppose the Student data is backed by an SQL table, when you change the name or gpa you will trigger a database update!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The normal way to create a menubar as part of the frame and without confusing the content pane's layout, is

main.setJMenuBar(menu);

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

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just copy/pasted your assignment without even a moment taken to explain what help you need. That's highly disrespectful to the many people who give their time to help others here.

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 helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JeffGrigg commented: Exactly correct. +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Synchronization has absolutely nothing to do with calculating the square of a number.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

i need a correct code that show the square

No you don't. You need to learn to write it yourself.

You have had a massive amount of help from DaniWeb but patience is wearing thin. If you don't start to work and think harder for yourself then you can't expect much more spoon-feeding.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No.
We don't do your homework!
Read the DaniWeb Rules, and start again.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are trying to convert Integers to ints, and you can't use generics to refer to primitive types.

Tarek_2 commented: Exactly, so you must get the Integer[] array and create your int[] array using a loop. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Each of your get methods calls the next get method, despite the fact that the original actionPerformed calls them all anyway. This will result in multiple calls to the later get methods, and thus mutiple error messages

kayleigh0411 commented: Thank you for your help! I deleted those lines calling the next method, and it no longer pops up the error message several times. However, it is still putting text in the output text fields when it should not. How can I fix this? +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that's not complete, but it's certainly heading in the right direction, and almost there. If you need help to proceed, please say exactly what help you need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No.
Nobody here will write those mthods for you. This isn't a "we do your homework" service.
If you would like to learn how to write them yourself then lots of people here will help you learn. Post what you have done so far.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
if(stringproduct == new problem004().reversed)

== for two objects tests if they are exactly the same object (same address in memory etc). In this case these are always two separate objects.
The String class has an equals(String another) method that tests if two Strings contain the same sequence of characters...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Every time you append a word you reverse the entire string, so the last word is reversed once, the previous word is reversed twice, the word before that is reversed 3 times, ... , and the first word is reversed (words.length) times. Of couse an even number of reversals is the same as not reversing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Come on now...
You have the x,y coordinates of the mouse click.
You have two variables: x and y that define the position of the ball
Set the position x and y equal to the mouse click coordinates

It's two simple assignment statements. You can do it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Read the API doc for The Connection class, setAutoCommit method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

if you use a classic model/view pattern then this is straighforward.
Your "model" classes encapsulate the current state of the game (who has which cards, whose turn is it next etc) in a purely logical form (no user interface artifacts). Your "view" classes display the current state as a GUI or whatever (no involvement in how that state evolved).
The model is maintained on the server. The GUI(s) live on the client(s). All clients have a thread that sits in a loop listening on an ObjectInputStream on their server connection. Whenever anything happens to change the model the server sends the latest state to all the clients. When a client receives a new state it displays it.
When the user does something the client sends the corresponding request to the server, which updates the model (and thus sends its latest state to all clients).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The inner loop code is wrong. With i == 1 it will exit on the very first execution because ! j>i

Why not just use the simple form for the inner loop ...

for (int j = i+1; j < numbers.length; j++) {
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Check your switch, and remember that execution wuill drop through to the next clause unless you execute a break or a return...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to explain what help you need.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I was NOT suggesting you did that - I was agreeing with ~s.o.s~ that it would be a difficult/messy thing to do. It would need a lot more code than just changing the method header.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's OK if you are happy to have the answer as a double reardless of whether the generic type for the inputs is Double, Integer, Byte or whatever.
I think ideally you would want to return the same type, ie instead of

public double getSum() {...

you would ideally have

public T getSum() {...

... and that's what ~s.o.s~ is saying is a problem (and I agree with him).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Number has some useful methods such as doubleValue() and intValue(), so conversion to a numeric primitive isn't that hard.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have not restricted the type of your generic argument, so number1 and numnber2 could be any kind of object - Strings, URLs, Files, JRadioButtons... consider

GenericsArithmetic<File> integerNumbers = new GenericsArithmetic<>();

No way you can expect Java to add them.

You need to restrict the type, eg start with something like

public class GenericsArithmetic<T extends Number> {
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

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 helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'd look on the web first, if nothing then do something simple with an animated GIF (unless you already have expertise in video editing).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's the kind of logic the belongs in the Game class. It should know whose turn it is next and instruct the appropriate Player - maybe call a method in the Player class like player.getNextMove().

Get some sheets of paper. Label one "Game" and the others Player1 and Player2.
On each sheet write down what info belongs where. Guess what each needs to do, and write method names for each of those things. Now step through a bit of a game, tracing who class which methods, and whether there is enough info on each sheet of paper to do what is needed. When you hit a snag, fix it and try again. When you get that all making sense then you have a documented class structure, instance variables, and method specifications. Then, and only then, start coding!

(This is a technique called Class Responsibility Collaborator (CRC) Modelling. It works really well, trust me. Here's a good write-up.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What you have done with the variables prices (regPrice, overnightPrice) isperfectly valid, but could be a little better.
The problem is that to find out what value is used you need to look in two widely-separated places, so it's not easy for someone else to folow that code.
It's much clearer if you don't initialise them when you declare them, then set them explicitly like

if (overnightCheck == 0)
   overnightPrice = 0.00;
else
   overnightPrice = 5.00;

Incidentally, you could also use the ? operator, as in

overnightPrice = (overnightCheck == 0) ? 0 : 5;

More importantly, think what happens if the next step in this learning is
"After processing one order, ask the user if there is another to process, and continue processing orders until the user says no." With the code as you have written it, the prices will default to their values from the previous order.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

titus.k.s
Stop posting the same question twice. Next time you will get an infraction, possibly leading to a complete ban.
Read the DaniWeb rules carefully before you post again
https://www.daniweb.com/community/rules

And yes, as people have already pointed out, there's no point trying to work with GUIs and databases when you seem to have skipped over the basics.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Think about this example.
The Comparable interface defines a method compareTo that compares two objects so they can be sorted etc. Many classes implement this interface - eg Integer, String etc, and each implementation is different because the way you sort Integers is different from how you sort Strings (etc).
Java has methods to sort arrays and Lists of various kinds. It can sort anything that implements the Comparable interface because it knows it can call compareTo to compare the elements of the array or List. If the array or List contains objects that do not implement Comparable then they can't be sorted.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Was that 64 bit NetBeans?
What's wrong with Java 8 (the current version)?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Small point: Java programming conventions prefer the use of "camel case" rather than underscores, so accountBal would be better advice than account_bal.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you think about it...
You need to know what all the abbreviations are before you can start processing the text file. So the overall plan needs to be:

read all the abbreviations into an array or other data structure
for each line in the text file
  search the line for any abbreviations
     add the < and > for any abbreviations you find
  write the updated line to the output file

Don't try to do it all in one go. Real programmers test their code early and often. Eg:
Write the code for "read all the abbreviations into an array", then add some temporary code to print out that array, and run the program to test that you have tread the abbreviations correctly. Don't go any further until you have fixed any bugs.
Then write and test the code to read the text file line by line, and write them (unchanged for now) to the output file. Run that and get it working.
Finally, do the code to find and mark the abbreviations.

By working like that you will find and fix your bugs one at a time, which is by far the easiest way. You will also have the satisfaction of seeing results and progress as you work.

Thurston_1 commented: Thanks +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that's exactly the scenario I guessed in my first post. You cannot do it like that becuase of the way the EDT works.
SwingWorker is definitely what you should look at. The API doc starts with a couple of examples - the first one should give you what you need. In your actionPerformed set the message and call execute() for your SwingWorker. In the SwingWorker's done() method just turn the message off again.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Nice example.
You can push the Stream usage a bit further, depending on the overall requirements, along the lines of:

Files.lines(Paths.get("studentTest.txt"))
.map(line -> line.split(":"))
.filter(parse -> parse.length == 2)
.map (parse -> new Student(parse[0], parse[1]))
.collect(Collectors.toList());
llaspina commented: Fantastic! I knew it could be done in one line. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java Stream buffer size may affect the efficiency of your execution, but it won't change whether it works or not.
Maybe the problem is that you waitFor the process to terminate before you start to read your input stream. The Process API doc says

Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, or even deadlock.

... in which case you need to swap the code around so that you read all the input from your process, before you waitFor to get the return code, like this example

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The obvious choice is a LinkedBlockingQueue. As the API doc says:

BlockingQueue implementations are thread-safe. All queuing methods achieve their effects atomically using internal locks or other forms of concurrency control. ... a BlockingQueue can safely be used with multiple producers and multiple consumers.

so there's no need for any additional synchronisation when you add or remove items from a BlockingQueue. Neat, don't you think?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could:
1. Have each thread synchronise its file I/O using the File object as the lock. This is simple, but may block the client/server connections for too long.
2. As each client sends it data, append that data to an in-memory queue (one queue for each file), then have one thread for each file taking the data from its queue and writing it to file. Apart from never blocking the client, this has the huge advantage of allowing the transactions for each file to be batched up for more efficient I/O.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You seem to have got this all twisted up, and I don't know why. I'd just make it a constructor:

public MyLayerTest(){
  ImageIcon backGround = createImageIcon("/Images/Blackjack Table.jpg");
  setPreferredSize(new Dimension(800, 600));
  //Create the JLabel for the background image and add the image.
  back = new JLabel(backGround);
  back.setBounds(0, 0, 800, 600);
  add(back, new Integer(0));
}

then in createAndShowGUI()

JComponent lp = new MyLayerTest();
frame.add(lp);

(but first I'd rename "MyLayerTest" to something that helps the code make sense like "BlackjackTable", as in

JComponent blackjackTable = new BlackjackTable();
frame.add(blackjackTable);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I just mentioned XMLEncoder as a simple way to encode your complete program state as XML. It's an alternative to XStream but it's a standard part of the Java API. Each has it's own plus and minus points - it's your choice.
With XMLEncoder you specify the output stream where the XML is to be written. If you use a ByteArrayOutputStream then the XML is written to a byte array in memory. You can then encode that with AES or whatever and write that to a file safely. I belive XStream will write your XML to a String, so you can encode that before writing it to a file.

Slavi commented: I see, thank you +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry - correct class name is XMLEncoder
Just make sure your classes follow Beans standards (no-args constructor, getters/setters etc), put them in standard Collections (ArrayList etc) and you just need a single call to encode the top-level object of your app and it will automatically encode the entire tree below that. Use a ByteArrayOutputStream for the output so you can encode that before writing to a file.
XMLDecoder then re-creates your entire app tree from the decoded XML in one call.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

(This is a copy of my replies to the earlier thead - repeated here for simplicity)

That's a common problem with Swing (or any other powerful GUI toolset), and there isn't any good solution. An IDE with code folding helps when you are editing the code.
You can certainly put it all in a method in the same class, but if you use a different class then you have to worry about accessing all the variables for the different components in the GUI. If that's not too serious a problem then you can create a subclass of JPanel (or layered pane etc) that implements all the content, and in your main form just add a new one of those.

When I'm doing this for real I usually create a JPanel subclass containing all the contents, then provide a public interface in terms of the logic rather than the presentation, thus keeping all the actual JComponents private. Eg: Its a roulette application - I may have stuff like

class RouletteTable extends JPanel {
    public RouletteTable() {...
    public void showBet(int amount, Place p) {
       // enum Place is a number, colour. odd/even etc
       // may display piles of chips in the right place tec
       ...
    public int spinWheel() {
       // animated, retunrns final result

Note that this does very complicated and beautiful graphics, but it knows nothing about the processes of a game of roulette... it just displays what it's told to display.

Now I can program the logic …