Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    106
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Java miscompatibility

    I wrote a java program for a random number generator:
    Code:
    import java.io.*;
    import java.util.Scanner;
    import java.util.Random;
    import javax.swing.JOptionPane;
    
    public class Main {
    
    	public static void main(String[] args) throws IOException {
    		Gen();
    		Random dc4 = new Random();
    		int freq[] = new int[5];
    		for(int roll = 0; roll < 1000; roll++){
    			++freq[1+dc4.nextInt(4)];
    		}
    		FileWriter w = new FileWriter(new File("frequencies.rck"));
    		w.write("Num\tFrequency\n");
    		for(int face = 1; face < freq.length; face++){
    			w.append(face + "\t" + freq[face] + "\n");
    		}
    		w.close();
    		int yn = JOptionPane.showConfirmDialog(null, "Done. Show roll stats?", "Done", JOptionPane.YES_NO_OPTION);
    		if (yn == JOptionPane.YES_OPTION){
    			Scanner rraw = new Scanner(new FileInputStream("frequencies.rck"));
    			String r0 = rraw.next();
    			String r1 = rraw.next();
    			String r2 = rraw.next();
    			String r3 = rraw.next();
    			String r4 = rraw.next();
    			String r5 = rraw.next();
    			String r6 = rraw.next();
    			String r7 = rraw.next();
    			String r8 = rraw.next();
    			String r9 = rraw.next();
    			JOptionPane.showMessageDialog(null, r0 + ": " + r1 + "\n" + r2 + ": " + r3 + "\n" + r4 + ": " + r5 + "\n" + r6 + ": " + r7 + "\n" + r8 + ": " + r9, "Frequencies", JOptionPane.PLAIN_MESSAGE);
    		}
    	}
    	public static void Gen(){
    		int count = 0;
    		Random dc4 = new Random();
    		
    		while (count == 0){
    		String xt = JOptionPane.showInputDialog(null, "How many numbers?");
    		
    		int x = Integer.parseInt(xt);
    		for (int ct = 0; ct < x; ct++){
    			int d4raw = dc4.nextInt(4);
    			int d4 = d4raw + 1;
    			String d4o = Integer.toString(d4);
    			JOptionPane.showMessageDialog(null, d4o, "Random Number", JOptionPane.PLAIN_MESSAGE);
    		}
    		int ns = JOptionPane.showConfirmDialog(null, "All done. New set?", "Done!", JOptionPane.YES_NO_OPTION);
    		if (ns == JOptionPane.YES_OPTION){
    			count = 0;
    		}else{
    			count = 1;
    		}
    		
    	}
    	JOptionPane.showMessageDialog(null, " Recording Data;\n Hit \"Okay\" to continue", "Done!", JOptionPane.PLAIN_MESSAGE);
    	}
    
    }
    and then I wrote a .bat file to run it:
    Code:
    @echo off
    copy Main.class C:\Users\Public\Downloads\src
    cd C:\Users\Public\Downloads\src
    set path=%path%;C:\Program Files (x86)\Java\jre7\bin
    java Main
    In theory, both should have worked on any computer that has JRE7. None work on a computer that has not been configured to run Java by me.
    How can I make a universally operable .bat (or if needed .exe; I am learning C++) file to make it go?

    Don't complain about the script. I know it is inefficient (but there is a reason for the Scanner import, I just haven't coded it in yet), and would appreciate it if you could help me make the proof of randomness thing work more efficiently, but it works, so if all you are going to do is complain, don't. No offence to the community, but that's all I have received from people that examine the script.

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,725
    Thanks
    41
    Thanked 191 Times in 190 Posts
    set path=%path%;C:\Program Files (x86)\Java\jre7\bin
    I would guess that is the issue. Try changing that to

    Code:
    C:\Program Files\Java\jre6\bin
    and see what you get.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #3
    Regular Coder
    Join Date
    Oct 2011
    Posts
    106
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Except, then it will fail if they have jre7. Isn't there a try... catch code I can write for all of the versions of JRE or JDK?

  • #4
    Regular Coder
    Join Date
    Oct 2011
    Posts
    106
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Ideally it would be like minecraft, which for those who don't play, uses a .exe file to load several .jar files that make up the game. If you run a java-based server for something, you will also probably notice a .exe file is used to call the .jar file. This will work on any computer. Thoughts or suggestions?

    I'm willing to spend some time on this, as I need to learn C++ anyway and I will be able to edit it for use with most any script I write (correct?).

    Ideally (above the previous "ideally," but to the best of my knowledge impossible) I would be able to find a download of System Development Kit (I clarify because Google uses that interchangeably with SE Development kit) for windows to convert it to a .exe file, instead of being called from one. Am I wrong about this being impossible? If so, can you provide a link?
    Last edited by Scriptr; 12-16-2011 at 03:54 AM.

  • #5
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,725
    Thanks
    41
    Thanked 191 Times in 190 Posts
    what about multiple .bat files and then check for the jre? quick and dirty-

    check for file path (JRE7)-
    if exists Runtime.getRuntime().exec("cmd /c start JRE7.bat");
    else if check for file path (JRE6) Runtime.getRuntime().exec("cmd /c start JRE6.bat");

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #6
    Regular Coder
    Join Date
    Oct 2011
    Posts
    106
    Thanks
    12
    Thanked 0 Times in 0 Posts
    I am looking for something like Executor to turn it into a .exe file. I figure that if I get good, and do enough, that I need custom favicons, I'll be making money off it and be able to justify software that costs money. I can't find a free version of something like Executor, though. Just a trial version of that.

  • #7
    Regular Coder
    Join Date
    Oct 2011
    Posts
    106
    Thanks
    12
    Thanked 0 Times in 0 Posts
    I found a free version of Executor. It took me since I posted that, but I found a "trial version" that only reminds you to register in the cmd window for the output. It basically invokes JRE or JDK for the .jar file that you made with it. In essence, what alykins said, but more user-friendly and less "dirty."

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Does java not create link files to the java executable into the system32 directory? Mine appears to have java, javaw and javaws with the same date and time as the install, so these are either linked or copied. This should simply let you call java.exe on the cli without any worries of its location. You shouldn't explicitly look for a location to execute; you can determine the Java version its running using java.version from System.getproperty. Use this to terminate the application if it doesn't fulfill a requirement.
    Then pack this as a .jar file. .jar is cross platform compatible, so you needn't worry about being stuck on a windows machine with a .bat.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •