JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Those 3 terms are all very similar, and people will use them almost interchangeably. But here's my attempt to distinguish the main uses of them, while ignoring some of the more obscure exceptions:
Data is everything that's not executable code. It's the ints, booleans, bytes, Strings, arrays etc that a program uses and creates, eg 101, "James".
A value is the data associated with a variable or field, eg String personName = "James" ... the data "James" is the value of the variable personName.
Field is a word from the Object-Oriented world. When you define a class it has methods and fields. Fields will typically be implemented as variables in the class (but not necessarily - that's what data hiding is about), and accessed via public setter and getter (mutator and accessor) methods. Fields have values, which are examples of data.
Does that help?
Maybe someone else can explain it better...

ps. Yes, I deliberately didn't talk about references to objects; first things first, time enough for that later.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To "close" a window you have 2 main choices. One is to get rid of it completely by using its dispose() method, then create a new one from scratch next time. The other is simply to make it invisible (visibility false), then you can get it back by just setting its visibility back to true. Which you use depends mainly on whether you want to re-open it with its latest state intact or re-open it in its initial state

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes we can, but why should we? What have you done so far?
Google search both those terms, read the excellent documentation that you will find, then come back here with any specific questions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to request that the new window comes to the front and gets the focus, eg
page.toFront();
see this for more info:
http://download.oracle.com/javase/tutorial/uiswing/misc/focus.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Farhad.idrees
Please don't worry about what Arrorn said. He's making a point that's far too advanced for where you are now. Given the question that you were asked what you did was right.

mKorbel commented: correct +1 +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, your indentation means nothing to the Java compiler, so lines 2-5 apply to "this" (the current Button, which extends JFrame) not to pane.
You need pane.setBackground(Color.blue);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No time to study all your code now, but since you extend JFrame you should be able to use setTitle and setBackground. Because the JFrame is filled by a ContentPane, you need to set the background color of the content pane, not the JFrame.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

textJT array contains 6 text fields, but the clear code (line 157) only clears the first 3

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DefaultListModel implements Serializable, so you can read/write one with a single Object I/O call, or use XMLEncoder/Decoder to write & read the whole contents as XML string data, also in a single call.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Use the join() method from the Thread class - it waits until the thread has finished. Plenty of examples on the web.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
for (int x=0;x<3;textJT[x].setText(temp).x++);

you probably meant

for (int x=0;x<3;x++)  textJT[x].setText(temp);

ps: many people would prefer

for (int x=0;x<3;x++) {
   textJT[x].setText(temp);
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Two comments:
1. if (someCondition== true) is a bit silly. What's wrong with if (someCondition)

2. for (int i = somePositiveIntegerValue; i < 0; i--){... // eg your line 86
How many times will this loop execute (when will i<0 be true)?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you mean that you want to animate the display of the numbers so they slide down out of sight and the next number slides down from the top?
If so, you need to override paintComponent for the text fields and draw the text at an x,y position where the y coordinate is increased every few millisecs by a jaxax.swing.Timer

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is not helping at all, guys. I don't want to change anything written in those classes because they seem to be built on the top of each other.

What would you like us to do to help you? Please believe that we cannot change the way that Java works. You have a project with over 800 errors. There's nothing that anybody on Earth can do to make that work without fixing the errors.
If you have any religious beliefs then maybe praying will work for you.
Good luck.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Previous code is a good example of why an ArrayList is a better choice than an array for returning an unknown number of Objects - there's no need to size it, just keep adding Objects until they are all added.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

At the bottom of the thread you should see a heading
Has this thread been answered?
just under that is a link for "Mark this Thread as Solved". Just click it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is there any other way?

Yes, probably, maybe a custom DataFlavor...
But it's so easy and generalisable to convert any bean-like object to a plain String and back, that IMHO it's the easiest way to get the job done.
Here's a little bit of code to illustrate the XML encode/decode stuff...

public static String objectToXML(Object o) {
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      XMLEncoder en = new XMLEncoder(os);
      en.writeObject(o);
      en.close();
      return os.toString();
   }
   
   public static Object  objectFromXML(String s) {
      ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
      XMLDecoder de = new XMLDecoder(is);
      return de.readObject();
   }

   public static void main(String[] args) {

      JButton jb = new JButton("Hello, world");
      jb.setActionCommand("command");
      jb.setBounds(0, 0, 100, 10);

      String s = objectToXML(jb);
      System.out.println(s);

      Object o = objectFromXML(s);
      System.out.println(o);
   }
murali_quest commented: Usefull +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's right. Java is only pass by value, regardless of whether parameters are primitive types or reference types.

When the method or constructor is invoked (§15.12), the values of the actual argument expressions initialize newly created parameter variables, each of the declared Type, before execution of the body of the method or constructor.

Java Language Specification section 8.4.1

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

from the JComboBox documentation...

setSelectedIndex(int anIndex) Selects the item at index anIndex.
setSelectedItem(Object anObject) Sets the selected item in the combo box display area to the object in the argument.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, it really is just the same as any other array, so you can do stuff like:

GregorianCalendar[] myCal = new GregorianCalendar[99];
myCal[0] = new GregorianCalendar(1980,1,1);
...
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
System.out.println(sdf.format(myCal[0].getTime()));

Just experiment a bit with it. Everything you know about arrays of Strings applies to arrays of GregorianCalendar also.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can create a new Image object in the worker thread, get its Graphics, and draw your page to it. Then in the paintComponent swing thread you just need to draw that Image to the Swing Graphics. Google "Java off-screen rendering" for examples and discussions

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Don't get antagonistic...

I'm really sorry if I gave the impression of being antagonistic. That certainly wasn't my intent.
I'm a crap typist, so I try to get my message across in the minimum number of words, maybe that seems abrupt. The reason I'm here is to help newbies, not antagonise them. So Mea Cupla. Sorry.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What's stopping you from creating an activity class that extends android.app.Activity or one of its subclasses?
http://developer.android.com/reference/android/app/Activity.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The API doc for Printable includes this:

For correct printing behaviour, the following points should be observed:
The printing system may request a page index more than once...
... the Printable should expect multiple calls for a page index and that page indexes may be skipped, when page ranges are specified by the client, or by a user through a print dialog.

So the fact that it's called twice may be just how it works.

This all means that the approach of incrementing the page number when print is called is definitely wrong.
You could possibly pass the page number to the constructor of IntroPage and keep that as an attribute of the page, so the page number is created when the page is created and then doesn't change.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You will create 1000 objects, but the only references to them are in the 1000 local variables myObject. Those variables each go out of scope as soon as the method finishes, leaving the object having no references. That makes it eligible for garbage collection, and the garbage collector will destroy the object and free up its memory at a time of its own choosing. If you are short of memory that may be very soon. If you have lots of memory and your code continues to process heavily, then the garbage collection may be deferred for some time, but sooner or later they will all be destroyed.
The question of whether to use a static reference to your object(s) is answered by the functional requirement, not performance. (Objects themselves are not static or instance, they just exist.) Static and instance variables behave differently, and only one will be right for any given task.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
if(word[x].equals(null))

This code is broken. if word[x] is null then word[x].equals(anything) will throw a null pointer exception. Either the code isn't being executed, or array is initialised to something other than nulls, or you are ignoring the exception.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's no good trying to draw things to the Graphics like that - Swing is in charge of drawing and will ignore/over-paint your drawing.
The correct way is to override the paintComponent(Graphics g) method to include your own drawing code. Swing will call this whenever it is necessary - eg because the window has been resized, or you have requested it by calling repaint();
Look at the second (Swing) part of this:
http://java.sun.com/products/jfc/tsc/articles/painting/

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's nothing wrong with that as an OO design. Well done.
The main thing you could improve are the player1/player2/player3 variables. What happens if you want four players? It would be a lot better to have an array of Players (and an array of boolean results) - this will eliminate a lot of repeated code (repeated code is a bad thing) and allow you to pass the number of players as a parameter to a constructor for the GuessGame class.
One bug: Player's number variable should NOT be static - that means all the Players share the same value for number, which they do not. It would also be clearer if you called it "guess" rather than the not-very-descriptive "number"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

it is Java 1.4 though

Working with Java 1.4 would be a complete waste of time, given the extensive and important changes in the language in 1.5.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

We're going round in circles here, just like you did with Norm. I can't help you if you don't respond to my questions or say anything I can understand. Sorry. Good luck anyway.
J

Majestics commented: thanx +3
mKorbel commented: good +8
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I really want to help here. It's just that I still don't understand exactly how the user interaction is supposed to go, so I can't suggest any coding techniques.

It sounds like a pretty standard thing you are trying to do here, and the usual solution goes like this:
Initially A shows "Apple/Oracle/MS..."; B and C are blank
User selects MS, B is populated with list of MS products; C is still blank.
User selects "Office" from B, C is populated with "Word/Excel/..."
... uses selects from C, selection process is complete OR
... user selects another product from B, C is re-populated appropriately OR
... user selects another manufacturer, B is re-populated appropriately; C is cleared

Instead of clearing/populating entries you can instead have them all present but disable/enable them.

But none of your descriptions seem to match this standard model - how exactly does your desired solution differ from that?

NormR1 commented: Glad you've grabbed this one. +12
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hopefully one day I might be able to add to this board myself.

Hopefully you will! Nobody is so new that they have nothing to contribute, and nobody (except possibly ~s.o.s~) is so knowledgeable that they have nothing to learn.
Time to mark this thread solved. If/when you hit your next problem its best to start a new thread with an appropriate title.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi - just a quick correction and apology.
In the latest versions I suggested adding a null to the queue to signal a shutdown. I should have tested that first - it doesn't work with a LinkedBlockingQueue. Sorry.
Please refer to the earlier example of queue code that I posted where I added a special String value "Please shut down now", then tested for that value in the queue processor (rather than testing for null). That will work OK.
My apologies.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To close a window temporarily just set its visibility to false, then when you want it back just make it visible again.
To get rid of it call dispose(); for the top-level JFrame or whatever. That will get rid of the window and everything in it. If you need it again later you will have to re-execute the code that created it in the first place.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just a heads-up guys.
I had JRE update 26 pushed onto client machines yesterday and it broke an important client-server app.
This point release changes the serialVersionUID for ImageIcon. The app in question sends images from the server to the cients via a simple writeObject/readObject, which fails at the client end with a
java.io.InvalidClassException: javax.swing.ImageIcon; local class incompatible: stream classdesc serialVersionUID = 532615968316031794, local class serialVersionUID = -962022720109015502

Beware, I don't how many more of these there are in this release

peter_budo commented: Thanx for heads-up +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How many sets of coordinates? 1, 2, or 3 points there is always a circle that passes thru all of them (except limiting case of 3 points in a line where the "circle" is infinite radius).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

We don't actually do people's homework for them here.
Have a try, make a start, when you get stuck come back with a specific question and someone will help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

you can use this code to make it more simple...

... unless
You want Java code
You want the brackets to match
You expect to use a loop variable somewhere within its loop
You want the test for "equal" Strings to work
You know that Strings and arrays are different things
You would like an answer within a year or two of when you post the problem

John: It's great that you want to contribute to this forum, but you will embarrass yourself less if you compile and test your code before posting it. Don't be put off, just be more careful.
J

peter_budo commented: Well summarized +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Let me check: you server is still somewhere on the net but your client is on a LAN behind a NAT router? In which case the server just sees the routers's internet address as the getRemoteSocketAddress() for all such clients?
In that case, can't you use the ip address plus port number to distinguish between these clients? (The router should map them all to different outgoing port numbers.)

ps: Even so, ~s.o.s~ has pointed you in a better direction

masterofpuppets commented: that could work as well :) +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, that explanation clarifies it. DefaultListModel sounds ideal - it supports a Vector-like data model and was designed for the JList GUI component to track its changes, but the Listener design pattern it uses will work for any other class that wants to know about changes. I doubt you will find a (much) better solution.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think you will have to wrap the Vector (or extend the Vector class) in your own class that implements an addListener(...) method and overrides add() etc to broadcast the change event forwarding the change to the the Vector.

This is basically what javax.swing.DefaultListModel does to support JList objects - you may find that a javax.swing.DefaultListModel is all you need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you need a display formatted in rows/columns like that then JTable may be the best thing

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe something like...

SocketAddress addr = new InetSocketAddress("192.168.0.23", 10123);
...
Socket socket10123 = new Socket(addr);
...
public boolean ConnectToServer()  {
  try {
    if (!Globals.socket10123.isConnected()) {
       Globals.socket10123.connect (addr);
     }
     return Globals.socket10123.isConnected();
  } catch(Exception e) {
     e.printStackTrace();
     return false;
  }
}

... but you will still have to deal with the input/output Streams that will have closed when the connection was dropped, and any reads that were blocked waiting on an input Stream.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

(30 minutes later) ... no answer. Obviously not urgent after all.

jwenting commented: indeed +15
Salem commented: LOL +17
debasisdas commented: :) +13
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's no code in paint() method because there is no requirement.

So you have a JFrame ibut there's no requirement to paint it or any of its components.

I am not worried about exceptions here in this case since it has no complex code to throw such Heavy Exceptions ..

AFAIK there's only one "weight" for Exceptions and that is "heavy", as in "your code could not be executed". It doesn't take much complexity to generate a null pointer exception, for example.

There's none so blind as those who will not see.
Good luck with your program.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

mKorbel (or an admin)
I suggest you delete the previous post a.s.a.p. - it's copyrighted material that has been posted in violation of the licence agreement, which begins

* Copyright (c) 1995 - 2008 Sun Microsystems, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.

mKorbel commented: thanks for notice +8
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

just looking at your latest code, there's nowhere you add the LWG object to the main JFrame. Since it isn't part of any visible window, it's paintComponent won't be called

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@siviwe
You do realise that this was marked as "solved" in 2008, don't you? It's 2011 in this part of the world...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can do this kind of thing using the indexOf and substring methods of the String class. So myUrlAsString.indexOf("secret_code=") gives the start point of that string, add 12 to get the index of the first char after it, which is where your target text is located. Use the same approach to find the end of your target (either the end of the URL string, or an "&" maybe?). Then use substring to pick out the text between those two indexes.