Results 1 to 13 of 13
  1. #1
    flamelord786 is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Unhappy jar file does not run

    I am trying to convert one of my programs from a .java file to a .jar file. It is a small game I intend to give to my mom as a present.
    I used the JCreator jar tool to make the file. However, when I double-click the file, nothing happens. The cursor shows that something is computing then it stops and nothing happens.
    I made a manifest, and I don't get any errors. Please note that these two classes are not in the same .java file.
    This is my first post so I apologize if I made a mistake
    Anyone know what I am doing wrong?

    Here is a copy of the code I am trying to convert.
    Main Class:
    Java Code:
    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    import java.text.*;
    
    public class PipesSt extends java.applet.Applet {
    
    
    	Grid grid;
    	Rectangle[][] clicked;
    	Rectangle startRect, floodRect, resetRect;
    	boolean start, flood, go, reset;
    	int blankRow, blankCol;
    	int appletWidth;
    	int appletHeight;
    	Image virtualMem;
    	Graphics g2;
    	private int min, sec, moves, ms;
    	AudioClip flushSE;
    	AudioClip slideSE;
    	NumberFormat time;
    	Timer clock;
    	long tm,count;
    
    	public void init()
    	{
    		flushSE = getAudioClip(getCodeBase(), "flushSE.wav");
    		slideSE = getAudioClip(getCodeBase(), "slide.wav");
    
    		count=0;
    		tm=1000000000;
    		go=true;
    		reset=false;
    		min=2;
    		sec=00;
    		ms=0;
    		moves=100;
    		startRect = new Rectangle(750,100,200,100);
    		floodRect = new Rectangle(750,300,200,100);
    		resetRect = new Rectangle(750,500,200,100);
    		start = false;
    		flood = false;
    		appletWidth = size().width;
    		appletHeight = size().height;
    		virtualMem = createImage(appletWidth,appletHeight);
    		g2 = virtualMem.getGraphics();
    		grid = new Grid();
    		clicked = grid.getClicked();
    		blankRow = 0;
    		blankCol = 0;
    	}
    
    
    	public void paint(Graphics g)
    	{
    		grid.drawGrid(g2);
    		grid.drawPipes(g2);
    		g.drawImage(virtualMem,0,0,this);
    		if(start)
    		{
    			g.setFont(new Font("Arial",Font.BOLD,20));
    			g.drawString("GO. You have two minutes to finish", 250, 50);
    			updateTimer(g);
    			g.drawString(""+min+":"+sec,350, 75);
    			count++;
    			repaint();
    		}
    		if (flood)
    		{
    			start=false;
    			g.setFont(new Font("Arial",Font.BOLD,20));
    			g.drawString("GO. You have two minutes to finish", 250, 50);
    			updateTimer(g);
    			g.drawString(""+min+":"+sec,350, 75);
    			flushSE.play();
    			grid.floodPipes(g);
    			if(grid.win)
    			{
    				g.setColor(Color.black);
    				g.setFont(new Font("Arial",Font.BOLD,50));
    				g.drawString("You Win", 350,350);
    			}
    			else
    			{
    				g.setColor(Color.black);
    				g.setFont(new Font("Arial",Font.BOLD,50));
    				g.drawString("You Lose", 350,350);
    				g.drawString("GAME OVER", 325,400);
    			}
    		}
    		if(reset)
    		{
    			blankRow = 0;
    			blankCol = 0;
    			grid.newGrid(g2);
    			grid.drawGrid(g2);
    			grid.drawPipes(g2);
    			reset=false;
    			repaint();
    		}
    	}
    
    
    	public boolean mouseDown(Event e, int x, int y)
    	{
    		if (startRect.inside(x,y) && !flood && go)
    		{
    			start = true;
    			reset=false;
    		}
    		else if (floodRect.inside(x,y)&& !flood && go)
    		{
    			start=false;
    			go=false;
    			flood = true;
    		}
    		else if (resetRect.inside(x,y))
    		{
    			reset=true;
    			start = false;
    			flood = false;
    			moves=100;
    			min=2;
    			sec=0;
    			go=true;
    
    		}
    		else if (start && !flood && go)
    		{
    			for (int row = 0; row < 6; row++)
    				for (int col = 0; col < 6; col++)
    				{
    					if (clicked[row][col].inside(x,y) && okSquare(row,col))
    					{
    						swap(row,col);
    					}
    				}
    		}
    		if(go)
    			repaint();
    		return true;
    	}
    
    
    	public boolean okSquare(int row, int col)
    	{
    		if(reset)
    			return false;
    		boolean temp = false;
    		if (row-1 >= 0 && grid.getValue(row-1,col) == 0)
    			temp = true;
    		else if (row+1 < 6 && grid.getValue(row+1,col) == 0)
    			temp = true;
    		else if (col-1 >= 0 && grid.getValue(row,col-1) == 0)
    			temp = true;
    		else if (col+1 < 6 && grid.getValue(row,col+1) == 0)
    			temp = true;
    		return temp;
    	}
    
    
    	public void swap(int row, int col)
    	{
    		int temp = grid.getValue(row,col);
    		grid.setValue(row,col,0);
    		grid.setValue(blankRow,blankCol,temp);
    		blankRow = row;
    		blankCol = col;
    		slideSE.play();
    		flushSE.play();
    	}
    
    
    	public void update(Graphics g)
    	{
    		if(min==0 && sec==0)
    		{
    			start=false;
    			go=false;
    			flood = true;
    		}
    
    		paint(g);
    	}
    
    	public void updateTimer(Graphics g)
    	{
    		if(!decimal((15*count)/100))
    		{
    			if(ms==0)
    			{
    				ms=130;
    				if(sec==0)
    				{
    					sec=59;
    					min--;
    				}
    				else
    					sec--;
    			}
    			else
    				ms--;
    		}
    	}
    
    	public boolean decimal(long n)
    	{
    		if(n-Math.ceil(n)==0)
    			return false;
    		else
    			return true;
    	}
    }
    Grid Class used
    Java Code:
    import java.awt.*;
    import java.applet.*;
    import java.util.Random;
    
    public class Grid
    {
    
    	private int[][] cells;
    	public boolean[][][] filled;
    	private Rectangle[][] clicked;
    	public boolean win;
    
    	public Grid()
    	{
    		Random rnd = new Random();
    		cells = new int[6][6];
    		filled=new boolean[6][6][2];
    		clicked = new Rectangle[6][6];
    		win=false;
    
    		for (int row = 0; row < 6; row++)
    			for (int col = 0; col < 6; col++)
    			{
    				filled[row][col][0]=false;//horizontal
    				filled[row][col][1]=false;//verticle
    			}
    		for (int row = 0; row < 6; row++)
    			for (int col = 0; col < 6; col++)
    				cells[row][col] = rnd.nextInt(5) + 1;
    		cells[0][0] = 0;
    		for (int row = 0; row < 6; row++)
    			for (int col = 0; col < 6; col++)
    				clicked[row][col] = new Rectangle(100+col*100,100+row*100,100,100);
    	}
    
    
    	public void drawGrid(Graphics g2)
    	{
    		g2.setColor(new Color(215,215,215));
    		g2.fillRect(0,0,1000,750);
    
    		g2.setColor(Color.lightGray);
    		g2.fillRect(100,100,600,600);
    
    		g2.setColor(Color.black);
    		g2.drawRect(100,100,600,600);
    		for (int row = 200; row <= 600; row += 100)
    			g2.drawLine(100,row,700,row);
    		for (int col = 200; col <= 600; col += 100)
    			g2.drawLine(col,100,col,700);
    
    		g2.setColor(Color.red);
    		g2.fillRect(750,100,200,100);
    		g2.fillRect(750,300,200,100);
    		g2.fillRect(750,500,200,100);
    		g2.setColor(Color.black);
    		g2.setFont(new Font("Arial",Font.BOLD,50));
    		g2.drawString("START",760,180);
    		g2.drawString("FLOOD",760,380);
    		g2.drawString("RESET",760,580);
    	}
    
    
    	public void drawPipes(Graphics g2)
    	{
    		for (int row = 0; row < 6; row++)
    		{
    			for (int col = 0; col < 6; col++)
    			{
    				int pipeNumber = cells[row][col];
    				switch (pipeNumber)
    				{
    					case 0:	pipe0(g2,100+row*100,100+col*100);  break;
    					case 1: pipe1(g2,100+row*100,100+col*100);  break;
    					case 2: pipe2(g2,100+row*100,100+col*100);  break;
    					case 3: pipe3(g2,100+row*100,100+col*100);  break;
    					case 4: pipe4(g2,100+row*100,100+col*100);  break;
    					case 5: pipe5(g2,100+row*100,100+col*100);  break;
    				}
    			}
    		}
    	}
    
    
    	public void floodPipes(Graphics g)
    	{
    		g.setColor(Color.green);
    		for (int y = 0; y <=100; y++)
    		{
    			g.drawLine(135,y,165,y);
    			delay(5);
    		}
    		for (int row = 0; row < 6; row++)
    		{
    			for (int col = 0; col < 6; col++)
    			{
    				int pipeNumber = cells[row][col];
    				switch (pipeNumber)
    				{
    					case 1: flood1(g,100+row*100,100+col*100);  break;
    					case 2: flood2(g,100+row*100,100+col*100);  break;
    					case 3: flood3(g,100+row*100,100+col*100);  break;
    					case 4: flood4(g,100+row*100,100+col*100);  break;
    					case 5: flood5(g,100+row*100,100+col*100,'H'); flood5(g,100+row*100,100+col*100,'V'); break;
    				}
    			}
    		}
    
    		g.setColor(Color.green);
    		if(filled[5][5][1])
    		{
    			for (int y = 700; y <=800; y++)
    			{
    				g.drawLine(635,y,665,y);
    				delay(5);
    			}
    			win=true;
    		}
    	}
    
    	public Rectangle[][] getClicked()
    	{
    		return clicked;
    	}
    
    
    	public int getValue(int row, int col)
    	{
    		return cells[row][col];
    	}
    
    
    	public void setValue(int row, int col, int value)
    	{
    		cells[row][col] = value;
    	}
    
    
    	public String toString()
    	{
    		String temp = "";
    		for (int row = 0; row < 6; row++)
    		{
    			for (int col = 0; col < 6; col++)
    				temp = temp + cells[row][col] + "  ";
    			temp = temp + "\n\n";
    		}
    		return temp;
    	}
    
    
    	public void pipe0(Graphics g2, int row , int col)
    	{
    		// Empty cell
    		g2.setColor(Color.white);
    		g2.fillRect(col,row,100,100);
    		g2.setColor(Color.black);
    		g2.drawRect(col,row,100,100);
    	}
    
    
    	public void pipe1(Graphics g2, int row , int col)
    	{
    		// Horizontal pipe
    		g2.setColor(Color.white);
    		g2.fillRect(col,row+35,100,30);
    		g2.setColor(Color.black);
    		g2.drawRect(col,row,100,100);
    	}
    
    	public void flood1(Graphics g, int row , int col)
    	{
    		g.setColor(Color.green);
    		int rowG=(row-100)/100;
    		int colG=(col-100)/100;
    
    		if((col-100)/100!=0)
    		{
    			if((cells[rowG][colG-1]==1|| cells[rowG][colG-1]==3 || cells[rowG][colG-1]==5) && filled[rowG][colG-1][0]==true)
    			{
    				filled[rowG][colG][0]=true;
    				for (int x = col; x <= col+100; x++)
    				{
    					g.drawLine(x,row+35,x,row+65);
    					delay(5);
    				}
    			}
    		}
    	}
    
    
    	public void pipe2(Graphics g2, int row , int col)
    	{
    		// Vertical pipe
    		g2.setColor(Color.white);
    		g2.fillRect(col+35,row,30,100);
    		g2.setColor(Color.black);
    		g2.drawRect(col,row,100,100);
    	}
    
    
    	public void flood2(Graphics g, int row , int col)
    	{
    		g.setColor(Color.green);
    
    		int rowG=(row-100)/100;
    		int colG=(col-100)/100;
    		if(rowG==0 && colG==0)
    		{
    			filled[rowG][colG][1]=true;
    			for (int y = row; y <= row+100; y++)
    			{
    				g.drawLine(col+35,y,col+65,y);
    				delay(5);
    			}
    		}
    		else if(rowG!=0)
    		{
    			if((cells[rowG-1][colG]==2 || cells[rowG-1][colG]==4 || cells[rowG-1][colG]==5 ) && filled[rowG-1][colG][1]==true)
    			{
    				filled[rowG][colG][1]=true;
    				for (int y = row; y <= row+100; y++)
    				{
    					g.drawLine(col+35,y,col+65,y);
    					delay(5);
    				}
    			}
    		}
    	}
    
    	public void pipe3(Graphics g2, int row , int col)
    	{
    		// Angle pipe from vertical to horizontal
    		g2.setColor(Color.white);
    		g2.fillRect(col+35,row,30,65);
    		g2.fillRect(col+35,row+35,65,30);
    		g2.setColor(Color.black);
    		g2.drawRect(col,row,100,100);
    	}
    
    
    	public void flood3(Graphics g, int row , int col)
    	{
    		g.setColor(Color.green);
    
    		int rowG=(row-100)/100;
    		int colG=(col-100)/100;
    		if(rowG==0 && colG==0)
    		{
    			filled[rowG][colG][0]=true;
    			for (int y = row; y <= row+65; y++)
    			{
    				g.drawLine(col+35,y,col+65,y);
    				delay(5);
    			}
    			for (int x = col+35; x <= col+100; x++)
    			{
    				g.drawLine(x,row+35,x,row+65);
    				delay(5);
    			}
    		}
    		else if(rowG!=0)
    		{
    			if((cells[rowG-1][colG]==2 || cells[rowG-1][colG]==4 || cells[rowG-1][colG]==5 ) && filled[rowG-1][colG][1]==true)
    			{
    				filled[rowG][colG][0]=true;
    				for (int y = row; y <= row+65; y++)
    				{
    					g.drawLine(col+35,y,col+65,y);
    					delay(5);
    				}
    
    				for (int x = col+35; x <= col+100; x++)
    				{
    					g.drawLine(x,row+35,x,row+65);
    					delay(5);
    				}
    			}
    		}
    	}
    
    
    	public void pipe4(Graphics g2, int row , int col)
    	{
    		// Angle pipe from horizontal to vertical
    		g2.setColor(Color.white);
    		g2.fillRect(col,row+35,65,30);
    		g2.fillRect(col+35,row+35,30,65);
    		g2.setColor(Color.black);
    		g2.drawRect(col,row,100,100);
    	}
    
    
    	public void flood4(Graphics g, int row , int col)
    	{
    		g.setColor(Color.green);
    		int rowG=(row-100)/100;
    		int colG=(col-100)/100;
    
    		if((col-100)/100!=0)
    		{
    			if((cells[rowG][colG-1]==1|| cells[rowG][colG-1]==3 || cells[rowG][colG-1]==5) && filled[rowG][colG-1][0]==true)
    			{
    				filled[rowG][colG][1]=true;
    				for (int x = col; x <= col+65; x++)
    				{
    					g.drawLine(x,row+35,x,row+65);
    					delay(5);
    				}
    				for (int y = row+35; y <= row+100; y++)
    				{
    					g.drawLine(col+35,y,col+65,y);
    					delay(5);
    				}
    			}
    		}
    	}
    
    
    	public void pipe5(Graphics g2, int row , int col)
    	{
    		// Bridge pipe intersection
    		g2.setColor(Color.white);
    		g2.fillRect(col+35,row,30,100);
    		g2.fillRect(col,row+35,100,30);
    		g2.setColor(Color.black);
    		g2.drawRect(col,row+35,100,30);
    		g2.drawRect(col,row,100,100);
    	}
    
    	public void flood5(Graphics g, int row , int col, char direction)
    	{
    		g.setColor(Color.green);
    		int rowG=(row-100)/100;
    		int colG=(col-100)/100;
    		switch (direction)
    		{
    			case 'H':
    				if((col-100)/100!=0)
    				{
    					if((cells[rowG][colG-1]==1|| cells[rowG][colG-1]==3 || cells[rowG][colG-1]==5) && filled[rowG][colG-1][0]==true)
    					{
    						filled[rowG][colG][0]=true;
    						for (int x = col; x <= col+100; x++)
    						{
    							g.drawLine(x,row+35,x,row+65);
    							delay(5);
    						}
    					}
    				}
    				break;
    			case 'V':
    				if(rowG==0 && colG==0)
    				{
    					filled[rowG][colG][1]=true;
    					for (int y = row; y <= row+35; y++)
    					{
    						g.drawLine(col+35,y,col+65,y);
    						delay(5);
    					}
    					for (int y = row+65; y <= row+100; y++)
    					{
    						g.drawLine(col+35,y,col+65,y);
    						delay(5);
    					}
    				}
    				else if(rowG!=0)
    				{
    					if((cells[rowG-1][colG]==2 || cells[rowG-1][colG]==4 || cells[rowG-1][colG]==5 ) && filled[rowG-1][colG][1]==true)
    					{
    						filled[rowG][colG][1]=true;
    						for (int y = row; y <= row+35; y++)
    						{
    							g.drawLine(col+35,y,col+65,y);
    							delay(5);
    						}
    						for (int y = row+65; y <= row+100; y++)
    						{
    							g.drawLine(col+35,y,col+65,y);
    							delay(5);
    						}
    					}
    				}
    				break;
    		}
    	}
    
    	public void newGrid(Graphics g2)
    	{
    		//reset values
    		Random rnd = new Random();
    		cells = new int[6][6];
    		filled=new boolean[6][6][2];
    		clicked = new Rectangle[6][6];
    		win=false;
    
    		for (int row = 0; row < 6; row++)
    			for (int col = 0; col < 6; col++)
    			{
    				filled[row][col][0]=false;//horizontal
    				filled[row][col][1]=false;//verticle
    			}
    		for (int row = 0; row < 6; row++)
    			for (int col = 0; col < 6; col++)
    				cells[row][col] = rnd.nextInt(5) + 1;
    		cells[0][0] = 0;
    		for (int row = 0; row < 6; row++)
    			for (int col = 0; col < 6; col++)
    				clicked[row][col] = new Rectangle(100+col*100,100+row*100,100,100);
    
    	}
    
    	private void delay(long n)
    	{
    		n = n * 1000000;
    		long startDelay = System.nanoTime();
    		long endDelay = 0;
    		while (endDelay - startDelay < n)
    			endDelay = System.nanoTime();
    	}
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: jar file does not run

    when I double-click the file, nothing happens. The cursor shows that something is computing then it stops and nothing happens.
    Try debugging the code by adding printlns to show where the execution flow is going and how the variables values change.
    Execute the program from the command prompt so the output will be shown and you will be able to copy it and paste it here.
    Open an command prompt, change to the folder with the jar file and enter:
    java -jar <YOURJARFILENAME>.jar
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: jar file does not run

    Your posted code does not have a main() method. There is no way to execute the code without a class with a main method.

  4. #4
    flamelord786 is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: jar file does not run

    How do I open a Command Prompt window?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: jar file does not run

    What OS are you on?
    On Windows there is a place somewhere in the Start menus that will open a command prompt.
    On XP its in Accessories.

  6. #6
    flamelord786 is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: jar file does not run

    Quote Originally Posted by Norm View Post
    Your posted code does not have a main() method. There is no way to execute the code without a class with a main method.
    It runs in an applet.
    I forgot to include the HTML file. sorry.
    here it is:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <APPLET
    CODE = "PipesSt.class"
    WIDTH = 1000
    HEIGHT = 750>
    </APPLET>

  7. #7
    flamelord786 is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: jar file does not run

    Quote Originally Posted by Norm View Post
    What OS are you on?
    On Windows there is a place somewhere in the Start menus that will open a command prompt.
    On XP its in Accessories.
    Windows 7

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: jar file does not run

    MIssed that it was an applet. Then forget about the command prompt.
    Look in the browser's java console for any error messages when you execute the program.
    Last edited by Norm; 12-16-2011 at 05:50 PM.

  9. #9
    flamelord786 is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: jar file does not run

    I get no errors executing the program. It runs fine. The only problem is the jar file.

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: jar file does not run

    The only problem is the jar file.
    Please explain.
    Where are you using a jar file?
    The html doesn't use it. It uses the class file.

  11. #11
    flamelord786 is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: jar file does not run

    I converted these .java files to a .jar file using the convert tool on JCreator. This created a single 193kb .jar file which does nothing. This is the problem. There is nothing wrong with the code, I just need some help with turning it into an executable .jar file. Sorry for the confusion.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: jar file does not run

    I converted these .java files to a .jar file
    That's not what happens. The java files are compiled to create class files which are put into a jar file(a jar file is like a zip file)

    To create an executeable jar file you need a class with a main method.
    Applets require a browser and html to execute.

    You will need to rewrite your program to use a JFrame to contain the GUI that is now being shown in the applet.

  13. #13
    flamelord786 is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 07-28-2011, 07:50 PM
  2. Replies: 1
    Last Post: 08-04-2010, 03:24 PM
  3. Replies: 8
    Last Post: 02-18-2010, 12:54 PM
  4. Replies: 0
    Last Post: 02-11-2009, 09:53 AM
  5. Replies: 7
    Last Post: 05-23-2008, 03:46 AM

Posting Permissions

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