Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 3 of 3 FirstFirst 123
Results 51 to 63 of 63

Thread: Writing Path name to configure Java

  1. #51
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Here is an updated code:
    import java.io.Console;
    import java.io.*;
    import java.lang.Math;
    import java.lang.Boolean;
    import ptolemy.plot.*;
     
    public class Edisc1 {
    	public static void main (String args[]) {
     
    	Console myConsole = System.console();
     
    	Plot disc = new Plot();
    	disc.setTitle("Graph of the axial E field from a charged disc");
    	disc.setXLabel("distance along z");
    	disc.setYLabel("E field");
     
    	PlotFrame myFrame = new PlotFrame("E vs z", disc);
    	myFrame.setSize(10,20);
     
    	int dataSet = 0;
     
    	double q = 6.0e-6;
    	double R  = 10;
    	double eps = 8.85e-12;
     
     
     
    	int points = 500;
     
    	double E[] = new double[points];
    	double z[] = new double[points];
     
    	for(int i = 0; i < (points-1); i++) {
    	z[i] = (100*(int)i/points); 
     
    	double Eqn = (q/((2*(Math.PI)*eps*(Math.pow(R,2))))*(1 - (z[i]/(Math.sqrt((Math.pow(R,2)) + (Math.pow(z[i],2)))))));
     
    	disc.addPoint(dataSet, z[i], Eqn, true);
     
     
    	}
    	System.out.println("Graph created");
     
    	myFrame.setVisible(true);
     
    	System.exit(0);
     
    } 
     
    }

    When I run, the graph still instantaneously appears and then disappears. Why would this happen?

  2. #52
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by CAF View Post
    When I run, the graph still instantaneously appears and then disappears. Why would this happen?
    Nothing in the posted code suggests that would happen. I can only guess something in one of the missing classes is causing that to happen when adding a new point.
    Post a SSCCE, the posted code can not be compiled for testing because of missing class definitions. Alternatively you could comment out the disc.addPoint line and see if the window stops disappearing and appearing.

  3. #53
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by jps View Post
    Nothing in the posted code suggests that would happen. I can only guess something in one of the missing classes is causing that to happen when adding a new point.
    When I don't put system.exit in, I get the graph but lose access of the terminal. When I put it in the loop, I don't get the graph and I get points number of 'Graph created' messages (which completely does not make sense). When I put in system.exit outside the loop, I get 1 'Graph created'and no graph. So the problem is this system.exit I feel at the moment. Maybe?
    you could comment out the disc.addPoint line and see if the window stops disappearing and appearing.
    No difference.

  4. #54
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by CAF View Post
    No difference.
    Running out of suggestions (or should I say guesses).
    Looks like it is time to post the SSCCE

  5. #55
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by jps View Post
    Running out of suggestions (or should I say guesses).
    Looks like it is time to post the SSCCE
    I'll post an SSCCE tomorrow (although by reading your attached link, I am not sure I fully understand what it actually is) since it is getting quite late here. Could you explain why the setVisible goes outside the loop though?

    --- Update ---

    I was thinking: Could it be possible that the program actually creates the graph but when it 'gets' to 'System.exit(0)' it then exits the program, including the graph?

  6. #56
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Writing Path name to configure Java

    SSCCE in a nutshell just means provide something we can compile and run to see the problem.
    I can't get a frozen console window, or see the printlns, because there are missing class definitions. So I have nothing to really look at to see where the problem is. The portion of code shown here does not seem to be the problem...

    As far as setVisible outside the loop, There is no reason to set a frame visible 500 times, unless you set it invisible 500 times and wanted to see it disappear and reappear for a while. Since you are listing this as a problem I assume you do not want such behavior. So there is no reason to have that inside the loop where it runs 500 times. Just once after the loop should be enough (possibly before the loop...? really up to you when you want it to be seen)
    Also on that note nothing in the posted code would make the window disappear over and over. So something not shown here is the cause of that.

    System.exit would close the program, including the graph yes. Here again, nothing within the posted code looks to be a problem with the console. The fact that the System.exit line is being reached (and the println just above it) proves the loop is exiting (eventually).

  7. #57
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by jps View Post
    As far as setVisible outside the loop, There is no reason to set a frame visible 500 times, unless you set it invisible 500 times and wanted to see it disappear and reappear for a while. Since you are listing this as a problem I assume you do not want such behavior.
    Where about in the code am I setting the frame visible 500 times? I thought that the statement 'int points = 500;' was only an indication of the number of points that I want plotted on the graph?
    System.exit would close the program, including the graph yes.
    Is that not my problem then? I tried a couple more things and found that with the System.exit, I get no graph but access to the terminal. With no system.exit, I get a graph but no terminal access.

  8. #58
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by CAF View Post
    Where about in the code am I setting the frame visible 500 times?
    That was when the setVisible line was inside the loop.

    Quote Originally Posted by CAF View Post
    Is that not my problem then? I tried a couple more things and found that with the System.exit, I get no graph but access to the terminal. With no system.exit, I get a graph but no terminal access
    The real problem is the terminal freezing. Without seeing the missing code who can guess? Same goes for the frame going invisible over and over, where is the missing code?

  9. #59
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by jps View Post
    That was when the setVisible line was inside the loop.
    But why would it run 500 times even when setVisible was within the loop - I thought the 500 only gave the number of points to be plotted?

    The real problem is the terminal freezing. Without seeing the missing code who can guess? Same goes for the frame going invisible over and over, where is the missing code?
    Missing code? Here is exactly what I am working with:
    import java.io.Console;
    import java.io.*;
    import java.lang.Math;
    import java.lang.Boolean;
    import ptolemy.plot.*;
     
    public class Edisc1 {
    	public static void main (String args[]) {
     
    	Console myConsole = System.console();
     
    	Plot disc = new Plot();
    	disc.setTitle("Graph of the axial E field from a charged disc");
    	disc.setXLabel("distance along z");
    	disc.setYLabel("E field");
     
    	PlotFrame myFrame = new PlotFrame("E vs z", disc);
    	myFrame.setSize(10,20);
     
    	int dataSet = 0;
     
    	double q = 6.0e-6;
    	double R  = 10;
    	double eps = 8.85e-12;
     
     
     
    	int points = 500;
     
    	double E[] = new double[points];
    	double z[] = new double[points];
     
    	for(int i = 0; i < (points-1); i++) {
    	z[i] = (100*(int)i/points); 
     
    	double Eqn = (q/((2*(Math.PI)*eps*(Math.pow(R,2))))*(1 - (z[i]/(Math.sqrt((Math.pow(R,2)) + (Math.pow(z[i],2)))))));
     
    	disc.addPoint(dataSet, z[i], Eqn, true);
     
     
    	}
    	System.out.println("Graph created");
    	myFrame.setVisible(true);
     
    	System.exit(0); //With this, I get no graph but access to terminal.  Without, I get graph, but no access.
     
    	} 
     
    }

    Many thanks

    EDIT: Just to clarify, when I run with the System.exit in place, the graph instantaneously appears then just disappears - it doesn't keep appearing, disappearing then reappearing.

  10. #60
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by CAF View Post
    But why would it run 500 times even when setVisible was within the loop - I thought the 500 only gave the number of points to be plotted?
    Call it what ever you want to call it, the end result is it is the number of times the loop runs. All of the code in the body of the loop is executed. The setVisible statement was inside the loop until it was moved. That is when it was running 500 times.



    Quote Originally Posted by CAF View Post
    Missing code? Here is exactly what I am working with:
    Not exactly.. The Plot class and PlotFrame class definitions are not present. Without those we can not compile and test your code, we can only guess what they do.
    System.exit(0); //With this, I get no graph but access to terminal.  Without, I get graph, but no access.
    The freezing terminal is the problem. System.exit is closing the program before the problem code freezes the console (I think)
    Quote Originally Posted by CAF View Post
    EDIT: Just to clarify, when I run with the System.exit in place, the graph instantaneously appears then just disappears - it doesn't keep appearing, disappearing then reappearing.
    I was under the impression it was still doing that. You will need to post a SSCCE, there is not much else that can be said without seeing the real cause of the problem

  11. #61
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by jps View Post
    Not exactly.. The Plot class and PlotFrame class definitions are not present. Without those we can not compile and test your code, we can only guess what they do.
    What do you mean by the Plot class and PlotFrame class defintions? I am able to run the code by referencing the plot.jar and plotapplication.jar in the classpath when compiling. Is there something else required?

  12. #62
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Writing Path name to configure Java

    If I was to copy paste your code into my IDE, it would tell me I do not have the Plot and PlotFrame class.
    Therefore I can not run your code to produce the results you claim to get.
    Without running the code (or at least looking at it) I have no more suggestions on what to try.

    "I am able to run the code ".... yes, YOU can... we can not, and there seems to be nothing wrong with what is posted on the forum. (At least not as far as the problems described)

  13. #63
    Member
    Join Date
    Jun 2013
    Posts
    33
    My Mood
    Fine
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Path name to configure Java

    Quote Originally Posted by jps View Post
    If I was to copy paste your code into my IDE, it would tell me I do not have the Plot and PlotFrame class.
    Therefore I can not run your code to produce the results you claim to get.
    Without running the code (or at least looking at it) I have no more suggestions on what to try.

    "I am able to run the code ".... yes, YOU can... we can not, and there seems to be nothing wrong with what is posted on the forum. (At least not as far as the problems described)
    What do you mean by the Plot and PlotFrame class definitions?

Page 3 of 3 FirstFirst 123

Similar Threads

  1. How to configure context.xml in netbeans IDE?
    By tangara in forum Java IDEs
    Replies: 1
    Last Post: January 5th, 2012, 10:18 PM
  2. How to convert local path drive to UNC path
    By krisswift in forum Object Oriented Programming
    Replies: 2
    Last Post: November 17th, 2011, 07:40 AM
  3. Relative path issue with Context path struts
    By chinnu in forum Web Frameworks
    Replies: 1
    Last Post: March 31st, 2011, 10:17 AM
  4. TOMCAT CONFIGURE
    By jugalrockz in forum Java Servlet
    Replies: 1
    Last Post: January 5th, 2011, 06:09 PM
  5. how to get full path name from realtive path
    By priyanka3006 in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: August 10th, 2009, 04:28 AM