JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The default access is not public, and public/private are not the only alternatives. See
http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, I was referring to the post immediately before mine, specifically to super.getGraphics() etc.

The code you just quoted is 100% OK as it is.

The overall structure of your code is right, just some details of the implementation were giving you problems.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No no no!

Only ever draw on a Swing Graphics when you override paintComponent(Graphics g) (or, sometimes, paint(Graphics g))
Swing has all kinds of internal optimisation, including double-buffering that you don't see. If you start drawing to Swing's internal Graphics at random times then there's a major risk that it will just be ignored becauase the buffering isn't updated, and then simply overwritten next time any of Swing's paintXXX methods get executed (not under your control).
The standard solution is a Timer-controlled update method that just changes the internal state of your model and calls repaint, plus an overridden paintComponent that draws everything according to its current state. You can delegate some of the drawing by having your paintComponent call other methods passing it's Graphics. If that's not working for you then it's a bug on your implementation somewhere, but the approach is right so don't change that.

Traevel commented: Thanks! I did not know that +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This thread is for people to suggest project ideas, not to post actual projects or solutions. If you want to discuss how to implement one of these, or discuss actual code, please start your own new thread.
Thanks
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Right, your plea has melted my heart. Here's the simplest eg I can come up with. It adds a background label (z coordinate 0) (just solid yellow, but could be image), and two overlapping labels in front of it at z-coodintes 10 and 20. Swap the 10 and 20 to swap which one is in front.

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;

public class Layers {

   public static void main(String[] args) {

        JLayeredPane p = new JLayeredPane();
        p.setPreferredSize(new Dimension(300, 200));

        JLabel back = new JLabel();
        back.setOpaque(true); 
        back.setBackground(Color.YELLOW);
        back.setBounds(0, 0, 300, 200);
        p.add(back, new Integer(0));

        JLabel a = new JLabel("this is a");
        a.setOpaque(true);
        a.setBackground(Color.RED);
        a.setBounds(20,20,80,20);
        p.add(a,new Integer(10));

        JLabel b = new JLabel("this is b");
        b.setForeground(Color.BLUE);
        b.setBounds(30,30,80,20);
        p.add(b,new Integer(20));

        JFrame frame = new JFrame("Close this to exit application");
        frame.add(p);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
   }
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK
You have to master all the material in that tutorial if you want to work with overlapping ojects. I know it's not easy, but programming isn't easy. Just sit somewhere quiet and work through it one step at a time.
I said twice: do not use a layout manager for overlapping objects, use setBounds instead.
Using a GUI drawing tool is a major mistake here. It's not going to give you the results you want, but it is going to confuse you. Stop using it; just type the code yourself so you understand and control it yourself. Start with the first example of the tutorial as a template.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No problem. Any time you get stuck, we'll be here.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Read the Oracle tutorial
http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html
in particular, see the comment under weightx, weighty about half way down.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you really think you have given enough information for anyone to know what you have done wrong?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Use a multi-thread client handler as per the Oracle tutorial! Then the client can do wahtever it likes without upsetting the thread where the server socket is listening.
Maybe this sample code will help you understand the structure...

public class SimplestServer implements Runnable {
   // simple demo of server for multiple clients (eg chat room)
   // sends "hello" message then echoes any input from client
   //
   // NB: This demo has no real error handling or shutdown/cleanup logic - 
   // you have to crash both client and server to stop it.
   // a real application will need an appropriate solid implementation

   public static void main(String[] args) {
      new SimplestServer(999).start();
   }

   private ServerSocket serverSocket;

   public SimplestServer(int port) {
      try { // Create the server socket
         serverSocket = new ServerSocket(port);
      } catch (IOException e) {
         System.out.println("Server couldn't open listen socket on port " + port + "\n" + e);
      }
   }

   public void start() {
      new Thread(this).start();
   }

   @Override
   public void run() {
      try {
         System.out.println("Server is listening");
         while (true) {
            Socket clientSocket = serverSocket.accept();
            System.out.println("Connect from: " + clientSocket);
            new Thread(new ClientInterface(clientSocket)).start();
         }
      } catch (IOException e) {
         e.printStackTrace();
      }
      // shutdown and tidy-up logic (logoff sockets etc) omitted for clarity
   }

   private class ClientInterface implements Runnable {
      // starts a thread to wait for and process input from the client
      // also provides a sendOutput method to send stuff to the client any time

      private final BufferedReader inbound; 
      private final PrintWriter outbound;

      public ClientInterface(Socket clientSocket) throws IOException { …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 22 you create a brand new new tree for every single word you read.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, people here will help - but do read the DaniWeb rules first, especially
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

JeffGrigg commented: Yep; those are the rules. +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That tutorial looks good, but surely if anyone is learning JavaFX now they should be using the Java 8 version of it. There are very significant improvements, eg Properties, that change how you use JavaFX.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ps Forgot to mention media support. At last we can bury the old Java media framework in the dungheap of history where it belongs. I use FX's MP3 player even in Swing apps because (a) it's trivially easy and (b) it works...

    static MediaPlayer withFile(File file) {  // factory method
        // force JFX environment initialisation if necessary...
        // API doc for javafx.embed.swing.JFXPanel constructor says: 
        // Implementation note: when the first JFXPanel object is created, 
        // it implicitly initializes the JavaFX runtime. 
        // This is the preferred way to initialize JavaFX in Swing.
        new javafx.embed.swing.JFXPanel();
        // now we need a string representation of the URI of our media...
        String source = file.toURI().toString();
        // ... to create a Media object and a player to play it
        return new MediaPlayer(new Media(source));
    }

    // Control the MediaPlayer with play(), pause(), stop(), dispose()
    // query media metadata etc - see API doc for MediaPlayer and Media
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The Oracle tutorial had bugs? I doubt it.
What you are trying to do isn't so simple, so you will need to understand everything in that tutorial, no matter how much effort that may take.

Maybe the message that the client sends does not have a newline character at the end?

String[] tokens = "Cow, 1, Moscow".split(","); should give you a three element array {"Cow", " 1", " Moscow"} from which you can pick out the elements, eg
String place = tokens[2].trim();

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You don't need an IDE, but if you are going to use one NetBeans seems to have integrated it better. JavaFX comes with a drag'n'drop GUI builder called SceneBuilder that you can use stand-alone or in your IDE.

Yes, you can (probably should!) add the GUI to the logic layer rather than v.v. However, compared to Swing you have a properties and binding mechanism based on Observables that your logic layer can (should?) implement to provide GUI support, rather than Swing's addListener(...) approach.

I've played with it, no real projects yet, and there's a significant learning "hump" to get over if you're coming from Swing. I'm yet to be convinced that it offers any real advantage over Swing for ordinary business-type GUIs. However, for more graphic animated consumer-oriented work it's miles ahead.

DoogleDude123 has been getting into JavaFX, so I'm sure he can contribute a lot to this discussion.

<M/> commented: banana +10
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Start by defining a Student class that has instance variables for name. marks etc.
Input the raw data, create the instances of Student and add them to a List like JeffGrigg said.

Java has methods to sort a List:
http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#sort%28java.util.List,%20java.util.Comparator%29

you need to create one or more Comparators ( http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html ) that define the order in which you want things sorted.

JeffGrigg commented: Yep; more good advice. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is what i have so far.

Please don't think we are fools. We know where you copied that from, and so will your teacher after 15 seconds with Google.
Copying someone else's answers is likely to get you an automatic fail of your course, and possibly being thrown out (quite rightly!).
The only way to learn is to do it yourself. If you make that effort people here will help you.

JeffGrigg commented: Quite rightly. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Well yes, I guess the exact equivalent would just be

 public class Child extends Parent   {
      public Child(String a, String b) {
          super(c);
      }
}
JeffGrigg commented: Yes; exactly. +6
strRusty_gal commented: thank you!! +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why do you think anything is wrong with it? If you have an error, or incorrect results, then share that info with us, don't expect us to guess!

JeffGrigg commented: Good question. ;-> +6
Wandaga1 commented: yes you are right, but i read that if incase we have problem with code we just need to post´. but seeing the code was enought to analys the problem +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Holding a ref to an object that's in a list won't affect the list's reference count because the object does not have a reference to the list. Either you have a reference to the list itreslf that's still active, or maybe GC just hasn't got round to deleting it yet.

JeffGrigg commented: Yep; that's right. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Since when did I become your servant? Get off your *** and look it up for yourself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

PrintWriter and PrintStream both implement a println method. Read their API doc for details.

ps: Your last three posts are still not "Solved". What's the problem?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How about thy multi-user chat/picture sharing thing? (Client/server, threads etc.) You can build that into something quite large & complex if you keep adding features. Start by designing a generic framework, then implement the specific app by building on that - that's like a lot of well-designed projects.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm no regex expert, but my guess is that you can't, or, if you can, it's ludicrously complex.
The real question is: why? Why not just run two simple replace commands with two simple regexs?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If this was a console app you would have a loop to control that, but for a Swing event-driven app you don't have that loop at all.
Just add the listener(s) to the buttons.
In the actionPerformed you do whatever, and increment the turn.
Then you just do nothing - Swing will call you again when there is an event for you to handle.
The problem here is that you don't have anything (yet?) to generate an event for the odd turns, so you never get to turn 2.
Maybe you can do some trivial place-holder for the odd turns (eg a single button) that will increment the turn counter to the next even number?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, they are package access by default, justlike ordinary methods.

The error message refers to a constructor with a long parameter, but the only constructor takes an int.

Creation or modification of Swing components should normally be done on the Swing thread. Sleeping during a constructor while changing a swing component's visibility, all on the main thread is asking for trouble...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In the API doc look for adddXXXListener methods. Don't forget to check all the methods in the "Methods inherited from class XXX" sections.

eg
JButton has no such methods of it own, but it inherits

addActionListener, addChangeListener, addItemListener from AbstractButton,

addAncestorListener, addVetoableChangeListener from JComponent,

addContainerListener, addPropertyChangeListener from Container,

addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener from Component

.. so that's the definitive list of all the listeners youcan add to a JButton.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's no such thing as a "compile time exception" in Java. There is no instance of that term anywhere in the Java language Specification. The compiler will check that your code handles "checked" exceptions, but all Exceptions are thrown at run time.
Maybe you are reading something written by someone who does not know correct Java terminology.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Everything to do with Swing (eg painting the screen, running actionPerformed methods) happens on a single thread - the "Event Dispatch Thread", or "EDT", or "Swing thread".
That means that once your actionPerformed method starts NOTHING else will happen in Swing, including no screen updates, until your method finishes. You can update stuff and loop and sleep as much as you like, but none of that will affect what's on the screen until your method has terminated.
If you want to do stuff in steps over a period of time, here is the right way:
In your actionPerformed start a javax.swing.Timer (as mKorbel said), and return. When the timer fires you can update whatever needs updating and return. Inbetween the timer firings Swing will be free to update the screen.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The problem is in the sequence of events...
You check the inputs and set the boolean when the user clicks the button, but you check the value as part of your initialisation (line 27), which is before the user could possibly have entered anything or clicked the button.
You will have to do a bit of re-structuring so that the code in your action listener switches to panel 2 when the button is clicked and the inputs are correct.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

pd.getReadMethod() gives you a Method object that represents a "get" method for the Bean. You can call the Method object's invoke method to execute the "get" method it represents and return the result

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Rachelle, welcome to DaniWeb.
Please take a moment to familiarise yourself with the site rules
http://www.daniweb.com/community/rules
in particular, don't hijack old threads - start your own for a new question
and
you must show what you have done so far if you want help with homework.

JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you add the action listener to your radio buttons? I can't see the code for that in what you posted.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Access to a computer and the internet.
Reasonable logical intelligence.
Willingness to work.
Time.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yet another good example of why not to use a null layout manager!
Swing doesn't know how big the panel is because there's no layout manager to set it. If you use setPreferredSize to give the panel a size bigger than the scroll pane's viewport, the scroll buttons will appear.

kishor.m.n commented: thanks a lot ..its working fine.. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This depends on whether the value is a primitive (int etc) or an object. If it's an object then all your variables are pointers (references) anyway.

JeffGrigg commented: Yes; exactly. +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's available from amazon.com at about half price (USD20).

Personally I would avoid books, which are always out of date, and go with online materials.
Oracle's "official" Java tutorials are excellent - not easy, but comprehensive and authoritative, and free. http://docs.oracle.com/javase/tutorial/uiswing/index.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

C++ is a language with a standard librray that covers a decent range of common requirements. You are expected to use it with the native facilities of your OS and whatever other third-party libraries you need to build your application.
Java is a language plus a vast API of over 4,000 public classes that provide standard methods for pretty much everything you can think of, all in a single Windows/Linux/Mac consistent portable package.

Yes, C++ language is technically more capable than Java language, and more dangerous in the wrong hands. But that's only a small part of the whole story...

Java is also still evolving major features - in the last few months we gained multiple inheritance of methods, closures/lambdas, parallel-processing support for functional programming Stream operations, Optional values, a major multi-media library (JavaFX is now integrated and standard)... (see http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html )

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, people here will help you. Explain what you have done so far and exactly what help you need. Remeber that nobody here will do the work for you, but they will help you to learn whatever you need to do it yourself. The more effort you put in, the more people will help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

From the look of it that printSelf method belongs in the Person class, not the Driver, and it should be an instance method, not static. That's because it's obviously intended to print the details of a current Preson instance.

stultuske commented: indeed a better solution +13
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Any reason you have to be on obsolete Java 1.6?
The final security update to 1.6 (the one you have) was over a year ago, and you are now missing literally hundreds of fixes, including many "critical" fixes. For your own protection, and the protection of others sharing your network, you should update immediatly to current Java 1.8 version or (if necessary for some reason) the latest supported release of 1.7

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Ahhh - the old BigInteger trick. What you have found is an over-complicated version. The simplest form is just one short line...

You can use the simpler version of getBytes without any arguments - that just uses the default char set. If you stick to ASCII characters you'll be OK.

Then you can use BigInteger's toString(int radix) method with a radix of 16 to get a hex string, no need for any other formatting.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Every case finishes with a return, so the extra return false will only be executed if none of the cases is true.
Sometimes this happens with the Java compiler. You know that every possible data will lead to one of your retunrs, but the compiler spots a theoretical possibility that it might not, so you have add an extra return to keep it happy.

Have you tried executing it yet? running test cases will tell you everything you need to know.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, but yes, the answer is in the API doc!
Just look for the addXxxListener methods (being alphbetical, they're conveniently near the beginnning of the summary list). Dopn't forget to look at the methods inherited from superclasse as well.

Here's a great tutorial
http://docs.oracle.com/javase/tutorial/uiswing/events/
and this page includes a table of whuch events go with which common classes
http://docs.oracle.com/javase/tutorial/uiswing/events/eventsandcomponents.html

Ps with Java 8 lambdas allow you to define a listener in a single concise expression http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#lambda-expressions-in-gui-applications

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I have no expertise in Hibernate, so I can't answer your latest question, other than to suggest using a List, which will definitely be ordered.

guideseeq commented: This is correct post, problem is something with Hibernate PersistentSet but behavior of another member "jwenting" is cheap, unprofessional a very lowly thoughts as well! +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In the first case all you are asserting about linksSet is that it is a Set. Anyone using linksSet will only be able to use Set's methods. Maybe later you will want to change the implemention eg to a TreeSet for some reason. By defining things that way you can change the implementation without breaking any code that uses linksSet.
(Having said that, in this particular example there aren't significant extra methods in LinkedHashSet that are not in Set. However the general principle applies that you should declare your variables in the least implementation-dependant way you can, to allow for future cdhanges.)

Actually...
If you want to hold a number of items and access them according to their order of insertion maybe you should look at one of the List classes, eg LinkedList or ArrayList

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

literal numbers like that default to int. For bigger numbers append an "L" to indicate that you want a long value.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's not hard to test each char to see if it's a numeric or an operator

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, it's more like (just a sketch)

 while(true){
    Socket clientSocket = serverSocket.accept();
    new ClientThread(clientSocket).start();
 }



 class ClientThread extends Thread {

    ClientThread(Socket clientSocket) {etc

    p v run() {
      PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
      BufferedReader in = new BufferedReader(new             InputStreamReader(clientSocket.getInputStream()));
      System.out.println("waiting");
      input = in.readLine();
      etc