How can I do a simple line break?

Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.

There is a point in the game where I'd like to have it say:

Game
Over

rather than:

Game Over

How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
«13

Comments

  • : Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.
    :
    : There is a point in the game where I'd like to have it say:
    :
    : Game
    : Over
    :
    : rather than:
    :
    : Game Over
    :
    : How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
    :
    You can do the same in Java, although the problem is that the various OSes have different line endings. You can get the line ending using this code:
    [code]
    lineSeparator = (String) java.security.AccessController.doPrivileged(
    new sun.security.action.GetPropertyAction("line.separator"));
    [/code]
  • : : Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.
    : :
    : : There is a point in the game where I'd like to have it say:
    : :
    : : Game
    : : Over
    : :
    : : rather than:
    : :
    : : Game Over
    : :
    : : How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
    : :
    : You can do the same in Java, although the problem is that the various OSes have different line endings. You can get the line ending using this code:
    : [code]
    : lineSeparator = (String) java.security.AccessController.doPrivileged(
    : new sun.security.action.GetPropertyAction("line.separator"));
    : [/code]
    :


    Wow, where or how would I implement that?
  • [b][red]This message was edited by zibadian at 2007-4-13 2:18:39[/red][/b][hr]
    : : : Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.
    : : :
    : : : There is a point in the game where I'd like to have it say:
    : : :
    : : : Game
    : : : Over
    : : :
    : : : rather than:
    : : :
    : : : Game Over
    : : :
    : : : How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
    : : :
    : : You can do the same in Java, although the problem is that the various OSes have different line endings. You can get the line ending using this code:
    : : [code]
    : : lineSeparator = (String) java.security.AccessController.doPrivileged(
    : : new sun.security.action.GetPropertyAction("line.separator"));
    : : [/code]
    : :
    :
    :
    : Wow, where or how would I implement that?
    :
    Here's a small code based on an applet:
    [code]
    public void init() {
    String lineSeparator = ....
    JLabel label = new JLabel("Hello"+lineSeparator+"world");
    add(label);
    }
    [/code]
    I've omitted the full line for getting the lineSeparator for readability.
    You might want to make a utility class with a static method to get the line separator.


  • : [b][red]This message was edited by zibadian at 2007-4-13 2:18:39[/red][/b][hr]
    : : : : Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.
    : : : :
    : : : : There is a point in the game where I'd like to have it say:
    : : : :
    : : : : Game
    : : : : Over
    : : : :
    : : : : rather than:
    : : : :
    : : : : Game Over
    : : : :
    : : : : How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
    : : : :
    : : : You can do the same in Java, although the problem is that the various OSes have different line endings. You can get the line ending using this code:
    : : : [code]
    : : : lineSeparator = (String) java.security.AccessController.doPrivileged(
    : : : new sun.security.action.GetPropertyAction("line.separator"));
    : : : [/code]
    : : :
    : :
    : :
    : : Wow, where or how would I implement that?
    : :
    : Here's a small code based on an applet:
    : [code]
    : public void init() {
    : String lineSeparator = ....
    : JLabel label = new JLabel("Hello"+lineSeparator+"world");
    : add(label);
    : }
    : [/code]
    : I've omitted the full line for getting the lineSeparator for readability.
    : You might want to make a utility class with a static method to get the line separator.
    :
    :
    :


    I appreciate the help...I really do. However I said I was a beginner and assuming I know things like making a utility class still keeps me in the dark :).
  • : : [b][red]This message was edited by zibadian at 2007-4-13 2:18:39[/red][/b][hr]
    : : : : : Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.
    : : : : :
    : : : : : There is a point in the game where I'd like to have it say:
    : : : : :
    : : : : : Game
    : : : : : Over
    : : : : :
    : : : : : rather than:
    : : : : :
    : : : : : Game Over
    : : : : :
    : : : : : How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
    : : : : :
    : : : : You can do the same in Java, although the problem is that the various OSes have different line endings. You can get the line ending using this code:
    : : : : [code]
    : : : : lineSeparator = (String) java.security.AccessController.doPrivileged(
    : : : : new sun.security.action.GetPropertyAction("line.separator"));
    : : : : [/code]
    : : : :
    : : :
    : : :
    : : : Wow, where or how would I implement that?
    : : :
    : : Here's a small code based on an applet:
    : : [code]
    : : public void init() {
    : : String lineSeparator = ....
    : : JLabel label = new JLabel("Hello"+lineSeparator+"world");
    : : add(label);
    : : }
    : : [/code]
    : : I've omitted the full line for getting the lineSeparator for readability.
    : : You might want to make a utility class with a static method to get the line separator.
    : :
    : :
    : :
    :
    :
    : I appreciate the help...I really do. However I said I was a beginner and assuming I know things like making a utility class still keeps me in the dark :).
    :
    Simply make a class, which you set aside from this project, but use in this project. In the next project you can then also use this class and its methods. The methods should be general enough to be useful in any project. For example:
    [code]
    public final class UsefulStrings {

    private static String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));

    public static String getLineSeparator() {
    return lineSeparator;
    }

    public static String getFilePathSeparator() {
    return filePathSeparator;
    // Returns backslash on windows, slash on linux, etc.
    }

    public static String nextIntegerValueAsString(int value) {
    return Integer.toString(value+1);
    // Example of a general task, if you need that in a lot of projects.
    }
    }
    [/code]
    This way you only need to call:
    [code]
    JLabel l = new JLabel("hello"+UsefulStrings.getLineSeparator()+"world");
    [/code]
    to make a multiline label.
  • : : : [b][red]This message was edited by zibadian at 2007-4-13 2:18:39[/red][/b][hr]
    : : : : : : Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.
    : : : : : :
    : : : : : : There is a point in the game where I'd like to have it say:
    : : : : : :
    : : : : : : Game
    : : : : : : Over
    : : : : : :
    : : : : : : rather than:
    : : : : : :
    : : : : : : Game Over
    : : : : : :
    : : : : : : How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
    : : : : : :
    : : : : : You can do the same in Java, although the problem is that the various OSes have different line endings. You can get the line ending using this code:
    : : : : : [code]
    : : : : : lineSeparator = (String) java.security.AccessController.doPrivileged(
    : : : : : new sun.security.action.GetPropertyAction("line.separator"));
    : : : : : [/code]
    : : : : :
    : : : :
    : : : :
    : : : : Wow, where or how would I implement that?
    : : : :
    : : : Here's a small code based on an applet:
    : : : [code]
    : : : public void init() {
    : : : String lineSeparator = ....
    : : : JLabel label = new JLabel("Hello"+lineSeparator+"world");
    : : : add(label);
    : : : }
    : : : [/code]
    : : : I've omitted the full line for getting the lineSeparator for readability.
    : : : You might want to make a utility class with a static method to get the line separator.
    : : :
    : : :
    : : :
    : :
    : :
    : : I appreciate the help...I really do. However I said I was a beginner and assuming I know things like making a utility class still keeps me in the dark :).
    : :
    : Simply make a class, which you set aside from this project, but use in this project. In the next project you can then also use this class and its methods. The methods should be general enough to be useful in any project. For example:
    : [code]
    : public final class UsefulStrings {
    :
    : private static String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));
    :
    : public static String getLineSeparator() {
    : return lineSeparator;
    : }
    :
    : public static String getFilePathSeparator() {
    : return filePathSeparator;
    : // Returns backslash on windows, slash on linux, etc.
    : }
    :
    : public static String nextIntegerValueAsString(int value) {
    : return Integer.toString(value+1);
    : // Example of a general task, if you need that in a lot of projects.
    : }
    : }
    : [/code]
    : This way you only need to call:
    : [code]
    : JLabel l = new JLabel("hello"+UsefulStrings.getLineSeparator()+"world");
    : [/code]
    : to make a multiline label.
    :


    Ok, by making a class, is that an individual file all by itself which can be called upon ever time I need the line separator or would the code you put above need to be included in the file that I need the lines separated? If so, where in the file should it go? And if it is a separate file, what should it be called?

    Thanks for replying to me :).
  • : : : : [b][red]This message was edited by zibadian at 2007-4-13 2:18:39[/red][/b][hr]
    : : : : : : : Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.
    : : : : : : :
    : : : : : : : There is a point in the game where I'd like to have it say:
    : : : : : : :
    : : : : : : : Game
    : : : : : : : Over
    : : : : : : :
    : : : : : : : rather than:
    : : : : : : :
    : : : : : : : Game Over
    : : : : : : :
    : : : : : : : How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
    : : : : : : :
    : : : : : : You can do the same in Java, although the problem is that the various OSes have different line endings. You can get the line ending using this code:
    : : : : : : [code]
    : : : : : : lineSeparator = (String) java.security.AccessController.doPrivileged(
    : : : : : : new sun.security.action.GetPropertyAction("line.separator"));
    : : : : : : [/code]
    : : : : : :
    : : : : :
    : : : : :
    : : : : : Wow, where or how would I implement that?
    : : : : :
    : : : : Here's a small code based on an applet:
    : : : : [code]
    : : : : public void init() {
    : : : : String lineSeparator = ....
    : : : : JLabel label = new JLabel("Hello"+lineSeparator+"world");
    : : : : add(label);
    : : : : }
    : : : : [/code]
    : : : : I've omitted the full line for getting the lineSeparator for readability.
    : : : : You might want to make a utility class with a static method to get the line separator.
    : : : :
    : : : :
    : : : :
    : : :
    : : :
    : : : I appreciate the help...I really do. However I said I was a beginner and assuming I know things like making a utility class still keeps me in the dark :).
    : : :
    : : Simply make a class, which you set aside from this project, but use in this project. In the next project you can then also use this class and its methods. The methods should be general enough to be useful in any project. For example:
    : : [code]
    : : public final class UsefulStrings {
    : :
    : : private static String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));
    : :
    : : public static String getLineSeparator() {
    : : return lineSeparator;
    : : }
    : :
    : : public static String getFilePathSeparator() {
    : : return filePathSeparator;
    : : // Returns backslash on windows, slash on linux, etc.
    : : }
    : :
    : : public static String nextIntegerValueAsString(int value) {
    : : return Integer.toString(value+1);
    : : // Example of a general task, if you need that in a lot of projects.
    : : }
    : : }
    : : [/code]
    : : This way you only need to call:
    : : [code]
    : : JLabel l = new JLabel("hello"+UsefulStrings.getLineSeparator()+"world");
    : : [/code]
    : : to make a multiline label.
    : :
    :
    :
    : Ok, by making a class, is that an individual file all by itself which can be called upon ever time I need the line separator or would the code you put above need to be included in the file that I need the lines separated? If so, where in the file should it go? And if it is a separate file, what should it be called?
    :
    : Thanks for replying to me :).
    :


    Did a little playing around and I think I see what you're getting at. But what if I wanted to just include it in the file where it was needed? Could I use a snippet of code from the example you gave in the file I need?
  • : : : : : [b][red]This message was edited by zibadian at 2007-4-13 2:18:39[/red][/b][hr]
    : : : : : : : : Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.
    : : : : : : : :
    : : : : : : : : There is a point in the game where I'd like to have it say:
    : : : : : : : :
    : : : : : : : : Game
    : : : : : : : : Over
    : : : : : : : :
    : : : : : : : : rather than:
    : : : : : : : :
    : : : : : : : : Game Over
    : : : : : : : :
    : : : : : : : : How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
    : : : : : : : :
    : : : : : : : You can do the same in Java, although the problem is that the various OSes have different line endings. You can get the line ending using this code:
    : : : : : : : [code]
    : : : : : : : lineSeparator = (String) java.security.AccessController.doPrivileged(
    : : : : : : : new sun.security.action.GetPropertyAction("line.separator"));
    : : : : : : : [/code]
    : : : : : : :
    : : : : : :
    : : : : : :
    : : : : : : Wow, where or how would I implement that?
    : : : : : :
    : : : : : Here's a small code based on an applet:
    : : : : : [code]
    : : : : : public void init() {
    : : : : : String lineSeparator = ....
    : : : : : JLabel label = new JLabel("Hello"+lineSeparator+"world");
    : : : : : add(label);
    : : : : : }
    : : : : : [/code]
    : : : : : I've omitted the full line for getting the lineSeparator for readability.
    : : : : : You might want to make a utility class with a static method to get the line separator.
    : : : : :
    : : : : :
    : : : : :
    : : : :
    : : : :
    : : : : I appreciate the help...I really do. However I said I was a beginner and assuming I know things like making a utility class still keeps me in the dark :).
    : : : :
    : : : Simply make a class, which you set aside from this project, but use in this project. In the next project you can then also use this class and its methods. The methods should be general enough to be useful in any project. For example:
    : : : [code]
    : : : public final class UsefulStrings {
    : : :
    : : : private static String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));
    : : :
    : : : public static String getLineSeparator() {
    : : : return lineSeparator;
    : : : }
    : : :
    : : : public static String getFilePathSeparator() {
    : : : return filePathSeparator;
    : : : // Returns backslash on windows, slash on linux, etc.
    : : : }
    : : :
    : : : public static String nextIntegerValueAsString(int value) {
    : : : return Integer.toString(value+1);
    : : : // Example of a general task, if you need that in a lot of projects.
    : : : }
    : : : }
    : : : [/code]
    : : : This way you only need to call:
    : : : [code]
    : : : JLabel l = new JLabel("hello"+UsefulStrings.getLineSeparator()+"world");
    : : : [/code]
    : : : to make a multiline label.
    : : :
    : :
    : :
    : : Ok, by making a class, is that an individual file all by itself which can be called upon ever time I need the line separator or would the code you put above need to be included in the file that I need the lines separated? If so, where in the file should it go? And if it is a separate file, what should it be called?
    : :
    : : Thanks for replying to me :).
    : :
    :
    :
    : Did a little playing around and I think I see what you're getting at. But what if I wanted to just include it in the file where it was needed? Could I use a snippet of code from the example you gave in the file I need?
    :
    You can import the class and then call all of its methods, without needing to copy-paste anything. Just like the example in my last code.
  • : : : : : : [b][red]This message was edited by zibadian at 2007-4-13 2:18:39[/red][/b][hr]
    : : : : : : : : : Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.
    : : : : : : : : :
    : : : : : : : : : There is a point in the game where I'd like to have it say:
    : : : : : : : : :
    : : : : : : : : : Game
    : : : : : : : : : Over
    : : : : : : : : :
    : : : : : : : : : rather than:
    : : : : : : : : :
    : : : : : : : : : Game Over
    : : : : : : : : :
    : : : : : : : : : How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
    : : : : : : : : :
    : : : : : : : : You can do the same in Java, although the problem is that the various OSes have different line endings. You can get the line ending using this code:
    : : : : : : : : [code]
    : : : : : : : : lineSeparator = (String) java.security.AccessController.doPrivileged(
    : : : : : : : : new sun.security.action.GetPropertyAction("line.separator"));
    : : : : : : : : [/code]
    : : : : : : : :
    : : : : : : :
    : : : : : : :
    : : : : : : : Wow, where or how would I implement that?
    : : : : : : :
    : : : : : : Here's a small code based on an applet:
    : : : : : : [code]
    : : : : : : public void init() {
    : : : : : : String lineSeparator = ....
    : : : : : : JLabel label = new JLabel("Hello"+lineSeparator+"world");
    : : : : : : add(label);
    : : : : : : }
    : : : : : : [/code]
    : : : : : : I've omitted the full line for getting the lineSeparator for readability.
    : : : : : : You might want to make a utility class with a static method to get the line separator.
    : : : : : :
    : : : : : :
    : : : : : :
    : : : : :
    : : : : :
    : : : : : I appreciate the help...I really do. However I said I was a beginner and assuming I know things like making a utility class still keeps me in the dark :).
    : : : : :
    : : : : Simply make a class, which you set aside from this project, but use in this project. In the next project you can then also use this class and its methods. The methods should be general enough to be useful in any project. For example:
    : : : : [code]
    : : : : public final class UsefulStrings {
    : : : :
    : : : : private static String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));
    : : : :
    : : : : public static String getLineSeparator() {
    : : : : return lineSeparator;
    : : : : }
    : : : :
    : : : : public static String getFilePathSeparator() {
    : : : : return filePathSeparator;
    : : : : // Returns backslash on windows, slash on linux, etc.
    : : : : }
    : : : :
    : : : : public static String nextIntegerValueAsString(int value) {
    : : : : return Integer.toString(value+1);
    : : : : // Example of a general task, if you need that in a lot of projects.
    : : : : }
    : : : : }
    : : : : [/code]
    : : : : This way you only need to call:
    : : : : [code]
    : : : : JLabel l = new JLabel("hello"+UsefulStrings.getLineSeparator()+"world");
    : : : : [/code]
    : : : : to make a multiline label.
    : : : :
    : : :
    : : :
    : : : Ok, by making a class, is that an individual file all by itself which can be called upon ever time I need the line separator or would the code you put above need to be included in the file that I need the lines separated? If so, where in the file should it go? And if it is a separate file, what should it be called?
    : : :
    : : : Thanks for replying to me :).
    : : :
    : :
    : :
    : : Did a little playing around and I think I see what you're getting at. But what if I wanted to just include it in the file where it was needed? Could I use a snippet of code from the example you gave in the file I need?
    : :
    : You can import the class and then call all of its methods, without needing to copy-paste anything. Just like the example in my last code.
    :


    I tried that. I tried to create an entire new class with the code you gave and I kept getting an error on the line:

    return filePathSeparator;

    Still, could I use a bit of the code in the file where I need the line break as needed? If so, how can I do this? I'm trying to learn this and I'd like to see what my options are, what else will work, etc.
  • : : : : : : : [b][red]This message was edited by zibadian at 2007-4-13 2:18:39[/red][/b][hr]
    : : : : : : : : : : Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.
    : : : : : : : : : :
    : : : : : : : : : : There is a point in the game where I'd like to have it say:
    : : : : : : : : : :
    : : : : : : : : : : Game
    : : : : : : : : : : Over
    : : : : : : : : : :
    : : : : : : : : : : rather than:
    : : : : : : : : : :
    : : : : : : : : : : Game Over
    : : : : : : : : : :
    : : : : : : : : : : How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
    : : : : : : : : : :
    : : : : : : : : : You can do the same in Java, although the problem is that the various OSes have different line endings. You can get the line ending using this code:
    : : : : : : : : : [code]
    : : : : : : : : : lineSeparator = (String) java.security.AccessController.doPrivileged(
    : : : : : : : : : new sun.security.action.GetPropertyAction("line.separator"));
    : : : : : : : : : [/code]
    : : : : : : : : :
    : : : : : : : :
    : : : : : : : :
    : : : : : : : : Wow, where or how would I implement that?
    : : : : : : : :
    : : : : : : : Here's a small code based on an applet:
    : : : : : : : [code]
    : : : : : : : public void init() {
    : : : : : : : String lineSeparator = ....
    : : : : : : : JLabel label = new JLabel("Hello"+lineSeparator+"world");
    : : : : : : : add(label);
    : : : : : : : }
    : : : : : : : [/code]
    : : : : : : : I've omitted the full line for getting the lineSeparator for readability.
    : : : : : : : You might want to make a utility class with a static method to get the line separator.
    : : : : : : :
    : : : : : : :
    : : : : : : :
    : : : : : :
    : : : : : :
    : : : : : : I appreciate the help...I really do. However I said I was a beginner and assuming I know things like making a utility class still keeps me in the dark :).
    : : : : : :
    : : : : : Simply make a class, which you set aside from this project, but use in this project. In the next project you can then also use this class and its methods. The methods should be general enough to be useful in any project. For example:
    : : : : : [code]
    : : : : : public final class UsefulStrings {
    : : : : :
    : : : : : private static String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));
    : : : : :
    : : : : : public static String getLineSeparator() {
    : : : : : return lineSeparator;
    : : : : : }
    : : : : :
    : : : : : public static String getFilePathSeparator() {
    : : : : : return filePathSeparator;
    : : : : : // Returns backslash on windows, slash on linux, etc.
    : : : : : }
    : : : : :
    : : : : : public static String nextIntegerValueAsString(int value) {
    : : : : : return Integer.toString(value+1);
    : : : : : // Example of a general task, if you need that in a lot of projects.
    : : : : : }
    : : : : : }
    : : : : : [/code]
    : : : : : This way you only need to call:
    : : : : : [code]
    : : : : : JLabel l = new JLabel("hello"+UsefulStrings.getLineSeparator()+"world");
    : : : : : [/code]
    : : : : : to make a multiline label.
    : : : : :
    : : : :
    : : : :
    : : : : Ok, by making a class, is that an individual file all by itself which can be called upon ever time I need the line separator or would the code you put above need to be included in the file that I need the lines separated? If so, where in the file should it go? And if it is a separate file, what should it be called?
    : : : :
    : : : : Thanks for replying to me :).
    : : : :
    : : :
    : : :
    : : : Did a little playing around and I think I see what you're getting at. But what if I wanted to just include it in the file where it was needed? Could I use a snippet of code from the example you gave in the file I need?
    : : :
    : : You can import the class and then call all of its methods, without needing to copy-paste anything. Just like the example in my last code.
    : :
    :
    :
    : I tried that. I tried to create an entire new class with the code you gave and I kept getting an error on the line:
    :
    : return filePathSeparator;
    :
    : Still, could I use a bit of the code in the file where I need the line break as needed? If so, how can I do this? I'm trying to learn this and I'd like to see what my options are, what else will work, etc.
    :
    I'm guessing the gravitational constant is wrong at the location of your computer, so moving your computer to a different room might solve the problem. Or if I'm wrong then it might not. Anyways reading the error should explain what you're doing wrong, and what a solution might be.
    Note: I'm not psychic or a hacker, so I don't know the error unless you tell me.
  • : : : : : : : [b][red]This message was edited by zibadian at 2007-4-13 2:18:39[/red][/b][hr]
    : : : : : : : : : : Sounds simple enough but for the life of me I can't find anything to show me how to do this no matter how much I search. I mentioned in another thread that I am a beginning Java programmer and I am picking apart simple open source games (in this case, Tetris) to see how they work.
    : : : : : : : : : :
    : : : : : : : : : : There is a point in the game where I'd like to have it say:
    : : : : : : : : : :
    : : : : : : : : : : Game
    : : : : : : : : : : Over
    : : : : : : : : : :
    : : : : : : : : : : rather than:
    : : : : : : : : : :
    : : : : : : : : : : Game Over
    : : : : : : : : : :
    : : : : : : : : : : How can I do this? I believe C++ has something to the effect of "/n" to accomplish this.
    : : : : : : : : : :
    : : : : : : : : : You can do the same in Java, although the problem is that the various OSes have different line endings. You can get the line ending using this code:
    : : : : : : : : : [code]
    : : : : : : : : : lineSeparator = (String) java.security.AccessController.doPrivileged(
    : : : : : : : : : new sun.security.action.GetPropertyAction("line.separator"));
    : : : : : : : : : [/code]
    : : : : : : : : :
    : : : : : : : :
    : : : : : : : :
    : : : : : : : : Wow, where or how would I implement that?
    : : : : : : : :
    : : : : : : : Here's a small code based on an applet:
    : : : : : : : [code]
    : : : : : : : public void init() {
    : : : : : : : String lineSeparator = ....
    : : : : : : : JLabel label = new JLabel("Hello"+lineSeparator+"world");
    : : : : : : : add(label);
    : : : : : : : }
    : : : : : : : [/code]
    : : : : : : : I've omitted the full line for getting the lineSeparator for readability.
    : : : : : : : You might want to make a utility class with a static method to get the line separator.
    : : : : : : :
    : : : : : : :
    : : : : : : :
    : : : : : :
    : : : : : :
    : : : : : : I appreciate the help...I really do. However I said I was a beginner and assuming I know things like making a utility class still keeps me in the dark :).
    : : : : : :
    : : : : : Simply make a class, which you set aside from this project, but use in this project. In the next project you can then also use this class and its methods. The methods should be general enough to be useful in any project. For example:
    : : : : : [code]
    : : : : : public final class UsefulStrings {
    : : : : :
    : : : : : private static String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));
    : : : : :
    : : : : : public static String getLineSeparator() {
    : : : : : return lineSeparator;
    : : : : : }
    : : : : :
    : : : : : public static String getFilePathSeparator() {
    : : : : : return filePathSeparator;
    : : : : : // Returns backslash on windows, slash on linux, etc.
    : : : : : }
    : : : : :
    : : : : : public static String nextIntegerValueAsString(int value) {
    : : : : : return Integer.toString(value+1);
    : : : : : // Example of a general task, if you need that in a lot of projects.
    : : : : : }
    : : : : : }
    : : : : : [/code]
    : : : : : This way you only need to call:
    : : : : : [code]
    : : : : : JLabel l = new JLabel("hello"+UsefulStrings.getLineSeparator()+"world");
    : : : : : [/code]
    : : : : : to make a multiline label.
    : : : : :
    : : : :
    : : : :
    : : : : Ok, by making a class, is that an individual file all by itself which can be called upon ever time I need the line separator or would the code you put above need to be included in the file that I need the lines separated? If so, where in the file should it go? And if it is a separate file, what should it be called?
    : : : :
    : : : : Thanks for replying to me :).
    : : : :
    : : :
    : : :
    : : : Did a little playing around and I think I see what you're getting at. But what if I wanted to just include it in the file where it was needed? Could I use a snippet of code from the example you gave in the file I need?
    : : :
    : : You can import the class and then call all of its methods, without needing to copy-paste anything. Just like the example in my last code.
    : :
    :
    :
    : I tried that. I tried to create an entire new class with the code you gave and I kept getting an error on the line:
    :
    : return filePathSeparator;
    :
    : Still, could I use a bit of the code in the file where I need the line break as needed? If so, how can I do this? I'm trying to learn this and I'd like to see what my options are, what else will work, etc.
    :


    Wouldn't let me reply to the last one so I replied to this one:

    The Netbeans IDE is underlining the line red and giving me an "x" beside the line. I very much appreciate the help but the sarcasm isn't helping.
  • : Wouldn't let me reply to the last one so I replied to this one:

    : The Netbeans IDE is underlining the line red and giving me an "x" beside : the line. I very much appreciate the help but the sarcasm isn't helping.

    Sorry, but at least once a week someone tells me he gets an error, but don't tell me what that error is or show any code. Here are the possible errors I can think of (for real this time):
    - "Type mismatch: cannot convert from ... to ..."
    - "Cannot make a static reference to the non-static field ..."
    - "... cannot be resolved"
    - "Void methods cannot return a value"

    There might be more. And telling me how the error appears on screen doesn't help: all errors appear like that. It also helps to show the entire method code and all relevant field definitions, since I don't know how you have coded this.
  • : : Wouldn't let me reply to the last one so I replied to this one:
    :
    : : The Netbeans IDE is underlining the line red and giving me an "x" beside : the line. I very much appreciate the help but the sarcasm isn't helping.
    :
    : Sorry, but at least once a week someone tells me he gets an error, but don't tell me what that error is or show any code. Here are the possible errors I can think of (for real this time):
    : - "Type mismatch: cannot convert from ... to ..."
    : - "Cannot make a static reference to the non-static field ..."
    : - "... cannot be resolved"
    : - "Void methods cannot return a value"
    :
    : There might be more. And telling me how the error appears on screen doesn't help: all errors appear like that. It also helps to show the entire method code and all relevant field definitions, since I don't know how you have coded this.
    :


    Could we continue this via email? I can send you the free open source Tetris game I am working with (zip file) so you'll know exactly what am looking at. We can continue it here if you like...that is no problem. Just thought it may be easier through email. Still, here is what I did:

    I made a separate .java file called "UsefulStrings.java". I went through the File, New File, Java Class route in the NetBeans IDE to create a file and cut/pasted in the code you presented. Then I went to the file I wanted to put the line break in like you did in your example and here is the error I got in NetBeans when I tried to run the project:

    [code]init:
    deps-jar:
    Compiling 7 source files to D:JavaTest ProgramsTetrisuildclasses
    D:Java etris-1.2-srcsrc
    etpercederberg etrisGame.java:142: cannot find symbol
    symbol : variable UsefulStrings
    location: class net.percederberg.tetris.Game
    board.setMessage("Hasonvsda"+UsefulStrings.getLineSeparator()+"Ahnigisdisgi");
    D:Java etris-1.2-srcsrc
    etpercederberg etrisUsefulStrings.java:10: cannot find symbol
    symbol : variable filePathSeparator
    location: class UsefulStrings
    return filePathSeparator;
    Note: D:Java etris-1.2-srcsrc
    etpercederberg etrisMain.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    2 errors
    BUILD FAILED (total time: 2 seconds)
    [/code]

    I hope this is what you need. I understand being frustrated at people not giving you specifics but to be honest I didn't know exactly what info you needed. I hope I got it all here for you.
  • : : : Wouldn't let me reply to the last one so I replied to this one:
    : :
    : : : The Netbeans IDE is underlining the line red and giving me an "x" beside : the line. I very much appreciate the help but the sarcasm isn't helping.
    : :
    : : Sorry, but at least once a week someone tells me he gets an error, but don't tell me what that error is or show any code. Here are the possible errors I can think of (for real this time):
    : : - "Type mismatch: cannot convert from ... to ..."
    : : - "Cannot make a static reference to the non-static field ..."
    : : - "... cannot be resolved"
    : : - "Void methods cannot return a value"
    : :
    : : There might be more. And telling me how the error appears on screen doesn't help: all errors appear like that. It also helps to show the entire method code and all relevant field definitions, since I don't know how you have coded this.
    : :
    :
    :
    : Could we continue this via email? I can send you the free open source Tetris game I am working with (zip file) so you'll know exactly what am looking at. We can continue it here if you like...that is no problem. Just thought it may be easier through email. Still, here is what I did:
    :
    : I made a separate .java file called "UsefulStrings.java". I went through the File, New File, Java Class route in the NetBeans IDE to create a file and cut/pasted in the code you presented. Then I went to the file I wanted to put the line break in like you did in your example and here is the error I got in NetBeans when I tried to run the project:
    :
    : [code]init:
    : deps-jar:
    : Compiling 7 source files to D:JavaTest ProgramsTetrisuildclasses
    : D:Java etris-1.2-srcsrc
    etpercederberg etrisGame.java:142: cannot find symbol
    : symbol : variable UsefulStrings
    : location: class net.percederberg.tetris.Game
    : board.setMessage("Hasonvsda"+UsefulStrings.getLineSeparator()+"Ahnigisdisgi");
    : D:Java etris-1.2-srcsrc
    etpercederberg etrisUsefulStrings.java:10: cannot find symbol
    : symbol : variable filePathSeparator
    : location: class UsefulStrings
    : return filePathSeparator;
    : Note: D:Java etris-1.2-srcsrc
    etpercederberg etrisMain.java uses or overrides a deprecated API.
    : Note: Recompile with -Xlint:deprecation for details.
    : Note: Some input files use unchecked or unsafe operations.
    : Note: Recompile with -Xlint:unchecked for details.
    : 2 errors
    : BUILD FAILED (total time: 2 seconds)
    : [/code]
    :
    : I hope this is what you need. I understand being frustrated at people not giving you specifics but to be honest I didn't know exactly what info you needed. I hope I got it all here for you.
    :
    This explains what's wrong: "cannot find symbol: variable filePathSeparator"
    From that you can see that you forgot to add either "this." to the return-statement or that the variable is missing in the class. If you have copied the code I gave you earlier into a separate file, you need to add the "this.".
    As for the first error: make sure the UsefulStrings.java is located in the same folder as your other java file, or import the package in which you have placed the file.
  • : : : : Wouldn't let me reply to the last one so I replied to this one:
    : : :
    : : : : The Netbeans IDE is underlining the line red and giving me an "x" beside : the line. I very much appreciate the help but the sarcasm isn't helping.
    : : :
    : : : Sorry, but at least once a week someone tells me he gets an error, but don't tell me what that error is or show any code. Here are the possible errors I can think of (for real this time):
    : : : - "Type mismatch: cannot convert from ... to ..."
    : : : - "Cannot make a static reference to the non-static field ..."
    : : : - "... cannot be resolved"
    : : : - "Void methods cannot return a value"
    : : :
    : : : There might be more. And telling me how the error appears on screen doesn't help: all errors appear like that. It also helps to show the entire method code and all relevant field definitions, since I don't know how you have coded this.
    : : :
    : :
    : :
    : : Could we continue this via email? I can send you the free open source Tetris game I am working with (zip file) so you'll know exactly what am looking at. We can continue it here if you like...that is no problem. Just thought it may be easier through email. Still, here is what I did:
    : :
    : : I made a separate .java file called "UsefulStrings.java". I went through the File, New File, Java Class route in the NetBeans IDE to create a file and cut/pasted in the code you presented. Then I went to the file I wanted to put the line break in like you did in your example and here is the error I got in NetBeans when I tried to run the project:
    : :
    : : [code]init:
    : : deps-jar:
    : : Compiling 7 source files to D:JavaTest ProgramsTetrisuildclasses
    : : D:Java etris-1.2-srcsrc
    etpercederberg etrisGame.java:142: cannot find symbol
    : : symbol : variable UsefulStrings
    : : location: class net.percederberg.tetris.Game
    : : board.setMessage("Hasonvsda"+UsefulStrings.getLineSeparator()+"Ahnigisdisgi");
    : : D:Java etris-1.2-srcsrc
    etpercederberg etrisUsefulStrings.java:10: cannot find symbol
    : : symbol : variable filePathSeparator
    : : location: class UsefulStrings
    : : return filePathSeparator;
    : : Note: D:Java etris-1.2-srcsrc
    etpercederberg etrisMain.java uses or overrides a deprecated API.
    : : Note: Recompile with -Xlint:deprecation for details.
    : : Note: Some input files use unchecked or unsafe operations.
    : : Note: Recompile with -Xlint:unchecked for details.
    : : 2 errors
    : : BUILD FAILED (total time: 2 seconds)
    : : [/code]
    : :
    : : I hope this is what you need. I understand being frustrated at people not giving you specifics but to be honest I didn't know exactly what info you needed. I hope I got it all here for you.
    : :
    : This explains what's wrong: "cannot find symbol: variable filePathSeparator"
    : From that you can see that you forgot to add either "this." to the return-statement or that the variable is missing in the class. If you have copied the code I gave you earlier into a separate file, you need to add the "this.".
    : As for the first error: make sure the UsefulStrings.java is located in the same folder as your other java file, or import the package in which you have placed the file.
    :


    Where would "this" go then? Also, the UsefulStrings.java is located in the same folder as the rest of the program .java files.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories