View Single Post
  #1 (permalink)  
Old 03-03-2008, 11:56 PM
Deathmonger Deathmonger is offline
Member
 
Join Date: Feb 2008
Posts: 16
Deathmonger is on a distinguished road
Creating .Jar files
Hi, I know this topic has been created in a thread before, but I still can't seem to be able to create JAR files. If someone can please help me with a step-by-step process, or tell me what I'm doing wrong, that would be great.

I'm creating a simple Slots game, and want to create it as an executable. I have my code in one file "Slots.java" and two classes in this file, "Slots.class" and "Slots$Play.class." The classes are packeged under Package Slots; I also created a manifest file which contains "Main-Class: Slots.Slots." I also added a carriage return after that line. All these files are included in the folder ...bin2/Slots/.

I try to create the jar file through command prompt. After compiling Slots.java and making sure teh program works, I'm not to sure how to create the jar file.

Here is the code that I used for Slots.java:

Code:
package Slots; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; public class Slots { static JFrame frame; static Container container; static JTextField bet; static JLabel winnings; static JLabel balance; static JLabel slot1; static JLabel slot2; static JLabel slot3; static JButton ride; static double userBalance = 50; static double userBet; static String firstSlot; static String secondSlot; static String thirdSlot; static int one; static int two; static int three; static double temp; static class Play implements ActionListener { public void actionPerformed(ActionEvent ae) { userBet = Double.parseDouble(bet.getText()); temp = userBet; RoleSlots(); WinorLose(); slot1.setText(firstSlot); slot2.setText(secondSlot); slot3.setText(thirdSlot); balance.setText("" + userBalance); winnings.setText("" + temp); } public void RoleSlots() { String outcomes[] = {"BAR", "CHERRY", "7", "BELL"}; one = (int)(Math.random() * 3); two = (int)(Math.random() * 3); three = (int)(Math.random() * 3); firstSlot = outcomes[one]; secondSlot = outcomes[two]; thirdSlot = outcomes[three]; } public void WinorLose() { switch(one) { case(0) : switch(two) { case(0) : switch(three) { case(0) : userBalance += userBet * 3; break; } } case(1) : switch(two) { case(1) : switch(three) { case(0) : userBalance += userBet * 0.5; break; case(1) : userBalance += userBet * 1; break; case(2) : userBalance += userBet * 0.5; break; case(3) : userBalance += userBet * 0.5; break; } } case(2) : switch(two) { case(2) : switch(three) { case(2) : userBalance += userBet * 4; break; } } case(3) : switch(two) { case(3) : switch(three) { case(0) : userBalance += userBet * 1; break; case(1) : userBalance += userBet * 1; break; case(2) : userBalance += userBet * 1; break; case(3) : userBalance += userBet * 2; } } default : userBalance -= userBet; } } } public static void main(String[] args) { frame = new JFrame(); container = new Container(); bet = new JTextField(); winnings = new JLabel(); balance = new JLabel("Balance Shown Here"); slot1 = new JLabel(); slot2 = new JLabel(); slot3 = new JLabel(); ride = new JButton("Ride"); Play p = new Play(); ride.addActionListener(p); frame.setSize(500,500); container = frame.getContentPane(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); container.setLayout(new GridLayout(3,3)); container.add(bet); container.add(winnings); container.add(balance); container.add(slot1); container.add(slot2); container.add(slot3); container.add(ride); frame.setVisible(true); } }
Here is the content of mainClass (The manifest file):

Main-Class: Slots.Slots

I've tried using in command prompt "jar cmf mainClass Slots.jar Slots.class Slots

All files are located in ...java/jdk1.6.0_02/bin2/Slots/. I also tried various variations for jar, and I'm still unable to create a working jar file. Someone please help me. Thanks
Reply With Quote
Sponsored Links