JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

cd88's post is, regrettably, partly nonsense and otherwize mostly wrong. His previous posts are about VB, so Java obviously isn't his area of expertise. Best simply to ignore that entire post.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's heading ih the right direction, so here's your next hint!
In the first argument you put all the fixed text, and format instructions for all the variable parts. The remining parameters are then the values for the variable parts. eg - I want a table with vertical bars, and the first col right justified 8 wide, and the second col 10 wide left aligned. My format spec looks like

"|%8s|%-10s|\n"

try running a couple of examples...

System.out.printf("|%8s|%-10s|\n","I","love");
System.out.printf("|%8s|%-10s|\n","Dani","Web");
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

Hve a look at System.out.printf - allows you to specify the format for what you print.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)

... seems to suggest there's something missing in your scenebuilder FXML file?

Update: It seems this can be caused by the FXML file not being where you told the loader it is. In turn, frequently caused by misunderstanding the path where Java looks for files.

Off the top of my head (no access to javadoc right now), MainApp.class.getResource("view/RootLayout.fxml") wants a RootLayout.fxml file inside a view folder inside the folder where MainApp's class file was.
I would normally pass the absolute path, starting from the applications root folder. eg "/slavi/address/view/RootLayout.fxml" (note initial slash)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

IDE screen designers are fine for data entry forms and the like, but hopeless for artistic or visually-excting games. You'll also see alot of advice here saying that it's better to learn how it all works by writing and debugging your own code first. Otherwize the generated code never stops being a mystery

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

That's got too complicated - you seem to have kept code from each approach you have tried, and it's all in there muddled together. It's definitely time to start again with an empty file and just copy over things as you determine that you need them.
Remmeber, just one panel - a JLayeredPane - put the JLabel with the imageicon at the back and the other controls in front of it. Use setBounds to position and size things to overlap properly.
See the Oracle tutorial that explains exactly how to do it, with examples:
http://docs.oracle.com/javase/tutorial/uiswing/components/layeredpane.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 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

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

With overlapping controls JLayeredPane is the way to go. You use just ONE layered pane, put enerything in that and use the depth variables to define which things overlap in front of which.

ps: This sounds like one of those very rare cases where none of the standard layout managers in going to let you position everything just right, so maybe you would be better off using a null layout manager and positioning/sizing everything with setBounds

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Add ActionListeners to the buttons of the second window.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Simply placing components on top of each other in an ordinary JFrame doesn't work. There are (at least) two ways to put controls over a background image:
1. Subclass JPanel and override paintComponent to draw the background image directly into the JPanel
2. USe a JLayeredPane to place your controls explicitly on top of the JLabel that has the background ImageIcon

With either method, if you have a problem with the positioning of the controls, that's to do with your layout manager, not the background image.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This sounds like a cunning re-phrasing of the classic "Travelling Salesman Problem" with its O(n!) time for a brute force solution. There's a vast amount of info on the TSP, including more algorithms than you could shake a stick at. WikiPedia is yopur friend.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I didn't see why that would fail, but have you tried printing ability at each of those stages to see where the null creeps in?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you hover on the red flags you should see a proper error message. Please post the complete exact text of the error messages.

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

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

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

Is this what you mean?

class A {
  public A(int i) { ... // constructor
  ...
}

class B extends A {
  public B(int i) {
     super(i);  // calls superclass's constructor
  }
  ...
}
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

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

I had a quick Google, and it seems there is a way, but it's far beyond my regex skills to understand it. Just search on "regex multiple replacements" or somesuch.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You don't seem to put anything in your scroll pane?

setLocationRelativeTo(null); works OK. If it's centering the TL corner then it sounds like swing thinks your JFrame is empty when you execute that.

Why do you want to set sizes explicitly in pixels? YOur app is going to look pretty silly when someoine runs it on a mchine with a >200 dpi display!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I was thinking of starting with a completely asynchronous application - whatever the users want to do, whenever they want to do it. You can always add constraints later, but the inverse isn't true.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. There's lots of stuff you can incorporate that make it a more advanced project - eg jmDNS to allow the clients to find the server, real-time collaborative drawing on top of a shared image, live screen sharing...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, I think so.

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

OK - you should have posted that with your very first post - it explains everything.
Here's what it means...

Exception... something went wrong
... null pointer ... you tried to use an uninitialised variable
... at Nav2.java:67 ... on line 67 of your program

Line 67 is: p1.add(l4);, so either p1 or l4 has not been initialised. Check your code to see which one you didn't initialise.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I just tried your code and it runs, but throws an exception before it can display anything.
What exactly do you mean by "not running"? Does your command prompt hang? Do you get an error message? Is the command ignored and you just get the command prompt again???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What do you mean by "can't run it"? - YOu don't know how to, you try to run it but nothing happens, you run it and you get an error message (if so- -s aying what?)... ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you have an em-dash then the file is not ASCII encoded!
ASCII is a 7-bit code that includes only the english alphbet, numbers and a handfull of puctuation (not em-dashes), so any other characters will be unreadable when you specify ASCII as the character set.

Simply leaving out the character set will give you the default CharSet for your machine, which will work 95% of the time unless you are importing files from places with a different language.

Otherwize, you could try ISO-8859-1 (ISO Latin 1) or UTF-8

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

What exectly do you mean by " how two exception handle"?
As soon as your code throws an exception, the rest of the block stops executing, so you cannot throw two exceptions at the same time.

ps. Your example code is perfectly legal, but also misleading. It's very odd to throw and catch an exception in the same method. Normally a method throws an exception because it found an error that it cannot handle. It throws the exception back up to the calling method so that can handle it. eg:

public static void main(String s[]){
  Scanner ob=new Scanner(System.in);
  System.out.print("Enter your age = ");
  int a=ob.nextInt();
  try {
     setAge(a);
  } catch(WrongException e) {
     System.out.print("You input was rejected because " +e.getMessage() + "  (details follow...)");
     e.printStackTrace();
  }
}

public static void setAge(int age) throws WrongException {
  if(age<=0)
     throw new WrongException("age cannot be zero or nagetive");
  System.out.print("age = "+age);
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No. Throwing an exception doesn't show any message.
An Exception is an object that contains information about a problem. When you find a problem you create an Exception object to describe it.
You then "throw" that exception object so somebody else can "catch" it and deal with the problem. It's the person who catches it who decides what to print (or show in a GUI dialog box, or log to an error log).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 21 you create an Exception object with that message. There's no printing there.
Line 26 you just print "wrong".
You can change line 26 to print the actual exception, ie
System.out.println(e);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you really mean to add the same JPanel both to another JPanel and an JFrame?

You seem to have a BorderLayout on your frame (see 82) yet I found three places where you add a component to that frame without specifying a location (80, 81, 89 - duplicate). Sticking components on top of each other often doesn't work.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

99% of problems like this come down to Java looking for the file in the wrong place. (or at least not the place you expected). Check out the File API doc for a full description of how partial paths are completed.

The getResource solution is better (if you can make it work) because that will continue to work when you package your code and resources in a jar file.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Don't you have any package specified for your code?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Almost certainly a problem with the path to the jpeg (assuming the jpeg itself is OK). That form of reference works well and requires a "resouces" folder to be in the classpath - best alongside the folder for the outermost package where the class files are stored. Sorry if that's confusing wording.
Eg
your .java file begins

package myApp;

class myClass {
   ...

Your run-time folder structure should look like

<some folder in the classpath>
   myApp
      myClass.class
   resources
      logo.jpg
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The message is not showing because you have not written any code to show it.
In your catch block, instead of printing "wrong" you should print the exception.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I just showed how an IllegalArgumentException is created and thrown.

Because it's an unchecked exception you can handle it (via try/catch or by declaring your method as throws IllegalArgumentException) or you can ignore it and allow your program to crash when it is thrown.

handled/unhandled is not an attribute of the exception, it's an attribute of the code that can cause the execption to be thrown.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Exactly which line does the error message point to?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
void setPrice(double newPrice) throws IllegalArgumentException  {
   if (price < 0.0) 
      throw new IllegalArgumentException("Price must be >= 0.0");
   ...
   ...
}

Now calling setPrice with a negative parameter will result in a IllegalArgumentException being thrown at run time.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That has absolutely NOTHING to do with Exceptions.
The method needs an int parameter, and you passsed a double.

You use an IllegalArgumentException when the parameter is of the right kind (compiles OK) but its value is illegal. eg parameter isDate dateOfBirth, the value passed is a date, but it's a date in the future. Or,the parameter is double price, the value passed is a number, but its <0.0

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Without seeing the program it's impossible to say.
Post the code and the error message

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ArrayStoreException extends RuntimeException, so it's unchecked
IllegalArgumentException extends RuntimeException, so it's unchecked

Simply.... if it extends RuntimeException or Error it's unchecked, otherwize it's checked.

The unchecked exception classes are the run-time exception classes and the error classes.The checked exception classes are all exception classes other than the unchecked exception classes.

Java Language Spec 11.1.1 The Kinds of Exceptions