Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (582)
games submitted by our members
Games in WIP (503)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Problems creating jar files. on: 2012-03-31 04:32:11
Here's what I do when I want to create an executable jar from a new project:

- In the Package Explorer, right click on the project folder.
- Run As -> Run Configurations.
- On the left of the window, right click on Java Application -> New (After this you should have a subset option below Java Application)
- On the right part of the window you should have a 'Search' button next to a 'Main class' label. Click on it and start typing the name of your main class. It should appear in the 'Matching items' list. Click OK.
- Click Apply, and Close.
- Go back to the Package Explorer, right click on the project folder.
- Export -> Java folder -> Runnable JAR file -> next.
- In 'Launch configuration' select the launch configuration you've just created.
- In 'Export destination' choose where you want the JAR file to be saved.
- If you have referenced libraries in your project, click the option "Package required libraries into generated JAR"
- Click Finsh.

Hope this helps!


This has it fixed in eclipse at least. now I just have to figure it out for command as I feel it would be needed.
2  Game Development / Newbie & Debugging Questions / Re: Problems creating jar files. on: 2012-03-30 18:45:26
It looks like you're using the default package.  You need to give Eclipse's jar exporter the full package name of your main class, e.g. com.foo.mygame.Main.  If you're doing it by hand with the jar command, you need to make sure you have a META-INF/MANIFEST.MF file that contains "Main-Class: com.foo.mygame.Main" somewhere in it.

If your Main class, or any other class, is in the default package, then by jove move it the hell out of there.  Don't ever use the default package, it can lead to a lot of subtle weird issues.


I have tried a few variations of that and in every form I've tried it always has the same error.

EDIT:

As a small example to try and figure this out I had this code.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
package com.game.mygame;
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
 
public class Main {
 
   public static void main(String[] args) {
 
       Frame f = new Frame();
       f.addWindowListener
             (new WindowAdapter() {
                 public void windowClosing(WindowEvent e) {
                    System.exit(0);
                    }
                 }
       );  
       f.add(new Label("This JAR file is executable!"));
       f.setSize(500,500);
       f.setVisible(true);
   }
}


I was also using this in my manifest.txt file.
1  
Main-Class: com.game.mygame.Main


I have tried making an executable jar file in command, eclipse, and net beans, none of which seem to be able to find the main class.
3  Game Development / Newbie & Debugging Questions / Problems creating jar files. on: 2012-03-30 18:12:19
I typically use Eclipse to do all my java programming in and when I use it to test my programs it works great. No problems at all with it so far. My problems are coming in when I try to create an executable jar file. It doesn't matter if I use Eclipse to make it or do it through command, I always end up with the same error of "Could not find the main class: Main" I have followed written guides on it and even some YouTube videos for a visual example. Why is it that it's not able to find the main class?
4  Game Development / Newbie & Debugging Questions / Re: Movement Issues on: 2012-03-29 15:53:17
You are saying if x is less than or equal to zero, set it to 0, which means it is going to get caught in a loop and you won't be able to move in the x direction.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
   public void move() {
      x += xDirection;
      y += yDirection;
      if (x <= 0) {   //change to if (x < 0)
        x = 0;
      }
      if (x >= 50) { //change to if (x > 50)
        x = 50;
      }
      if (y <= 0) { // change to if (y < 0)
        y = 0;
      }
      if (y >= 50) { // change to if (y > 50)
        y = 50;
      }
   }


That has it fixed. Thank you very much.
5  Game Development / Newbie & Debugging Questions / Re: Movement Issues on: 2012-03-28 22:44:39
I'm not sure about my frame-rate. I have no code implemented to tell me what it is, nor do I know of any built in function that may exist.
6  Game Development / Newbie & Debugging Questions / Re: Movement Issues on: 2012-03-28 12:42:00
Simply add brackets:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
// handle movement thread.
  public void move() {
      x += xDirection;
      y += yDirection;
      if (x <= 0) {
         x = 0;
      }
      if (x >= 50) {
         x = 50;
      }
      if (y <= 0) {
         y = 0;
      }
      if (y >= 50) {
         y = 50;
      }
   }

that's the thing. I have added brackets already and it had no effect in making the movement less glitchy.
7  Game Development / Newbie & Debugging Questions / Re: Movement Issues on: 2012-03-28 04:30:43
Yeah I'm still fairly new to the Java world so I make simple mistakes sometimes. Cheesy Especially when I'm trying to follow someone who talks and types fairly quickly. The only thing I'm not liking about this so far is the fact that it's fairly glitchy in the movement. Basically when you move in the four general directions of up, down, left, and right, it moves smooth and crisply. When you move in a diagonal direction, it catches for a moment before continuing it's motion. Is there a simple fix to this that anyone can guide me towards or any suggestions to fix it?
8  Game Development / Newbie & Debugging Questions / Re: Movement Issues on: 2012-03-27 01:42:27
You put semi-colons after if statements! You shouldn't do that, as that means that the if statement body is empty Grin

This way, your move method only causes X and Y to be permanently at 50,50 Smiley
Fantastic. That's exactly what it was. After reviewing the tutorial he was doing I saw that he did in fact place the semi-colons there himself, only to remove them later on while his video was paused to correct other code. Thank you for your help. Now I just need to figure out how to make the controls a little less glitchy. Cheesy
9  Game Development / Newbie & Debugging Questions / Movement Issues on: 2012-03-26 23:54:09
I have been following some tutorials, trying to get into programming in Java and so far all has worked well. The problem I have now stumbled upon is, I am not able to move my image around in my window with the arrow keys after proceeding with the tutorials into threads. I have followed the code, in a manner I thought was precise, and yet, my image will not move with the arrow keys being pressed down. Can anyone point out what I'm doing wrong?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
package javagame;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class JavaGame extends JFrame implements Runnable{

   int x, y, xDirection, yDirection;
   private Image dbImage;
   private Graphics dbg;
   Image face;
   
   public void run(){
      try{
         while(true){
            move();
            Thread.sleep(5);
         }
      }
      catch(Exception e){
         System.out.println("error...");
      }
   }
   
   // handle movement thread.
  public void move() {
      x += xDirection;
      y += yDirection;
     
      if (x <= 0);
           x = 0;
      if (x >= 50);
           x = 50;
      if (y <= 0);
           y = 0;
      if (y >= 50);
           y = 50;
   }

   // set up the directional movement variables of the player.
  public void setXDirection(int xdir) {
      xDirection = xdir;
   }
   public void setYDirection(int ydir) {
      yDirection = ydir;
   }

   // handle key input.
  public class AL extends KeyAdapter {
      public void keyPressed(KeyEvent e) {
         int keyCode = e.getKeyCode();
         // handle arrow key movement.
        if (keyCode == e.VK_LEFT) {
            setXDirection(-1);
         }
         if (keyCode == e.VK_RIGHT) {
            setXDirection(+1);
         }
         if (keyCode == e.VK_UP) {
            setYDirection(-1);
         }
         if (keyCode == e.VK_DOWN) {
            setYDirection(+1);
         }

      }

      public void keyReleased(KeyEvent e) {
         int keyCode = e.getKeyCode();
         if (keyCode == e.VK_LEFT) {
            setXDirection(0);
         }
         if (keyCode == e.VK_RIGHT) {
            setXDirection(0);
         }
         if (keyCode == e.VK_UP) {
            setYDirection(0);
         }
         if (keyCode == e.VK_DOWN) {
            setYDirection(0);
         }
      }
   }

   // handle the window class.
  public JavaGame() {
      // load images.
     ImageIcon i = new ImageIcon(
            "C:/Users/Me/workspace/JavaGame/src/javagame/face.png");
      face = i.getImage();
     
      // game properties.
     addKeyListener(new AL());
      setLocation(400, 300);
      setTitle("JavaGame");
      setSize(256, 256);
      setResizable(false);
      setVisible(true);
      setBackground(Color.RED);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      x = 50;
      y = 50;
   }

   // handle graphics input.
  public void paint(Graphics g) {
      dbImage = createImage(getWidth(), getHeight());
      dbg = dbImage.getGraphics();
      paintComponent(dbg);
      g.drawImage(dbImage, 0, 0, this);
   }

   public void paintComponent(Graphics g) {
      // draw and refresh the image.
     g.setColor(Color.RED);
      g.drawImage(face, x, y, this);
      repaint();
   }

   public static void main(String[] args) {
      JavaGame jg = new JavaGame();
      // Threads
     Thread t1 = new Thread(jg);
      t1.start();
   }

}


I was able to move the object earlier using the following code format.
1  
2  
3  
4  
if (x >= 200);
    x = 200;
else
    x += 5;

This, however was not best for the style I wanted to do. Where did I go wrong?
10  Game Development / Newbie & Debugging Questions / Eclipse Compiling Problem on: 2012-03-25 21:57:40
I'm new to the world of java and have been following a few online tutorials to get started. Everything was going great and the programs were compiling perfectly and then all of a sudden, without me seemingly changing anything, as far as preferences directly attributing to Eclipse, it stopped compiling any code at all. Even the simple Hello World code will not compile. All I get in the console line for any code is:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
Usage: javaw [-options] class [args...]
       (to execute a class)
or  javaw [-options] -jar jarfile [args...]
       (to execute a jar file)
where options include:
-d32      use a 32-bit data model if available
-d64      use a 64-bit data model if available
-server   to select the "server" VM
-hotspot      is a synonym for the "server" VM  [deprecated]
              The default VM is server.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
              A ; separated list of directories, JAR archives,
              and ZIP archives to search for class files.
-D<name>=<value>
              set a system property
-verbose[:class|gc|jni]
              enable verbose output
-version      print product version and exit
-version:<value>
              require the specified version to run
-showversion  print product version and continue
-jre-restrict-search | -no-jre-restrict-search
              include/exclude user private JREs in the version search
-? -help      print this help message
-X            print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
              enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
              disable assertions with specified granularity
-esa | -enablesystemassertions
              enable system assertions
-dsa | -disablesystemassertions
              disable system assertions
-agentlib:<libname>[=<options>]
              load native agent library <libname>, e.g. -agentlib:hprof
              see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
              load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
              load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
              show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.


I was able to compile the following code through javac in the command prompt but, all I get is the above for trying to compile while using Eclipse.
1  
2  
3  
4  
5  
public class apples {
   public static void main(String arg[]){
      System.out.print("Hello World");
   }
}


I'm not exactly sure of why it started this after being able to compile other code successfully. How do I go about in fixing the compiler so I can continue to learn?

EDIT: After doing more research into the subject, and a small amount of tinkering of my own, I have found that Eclipse was not pointing to any run time environments or lib files. Sorry for any trouble I may have caused.
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (72 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (79 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (80 views)
2014-04-14 15:48:38

tom_mai78101 (104 views)
2014-04-10 04:04:31

BurntPizza (164 views)
2014-04-08 23:06:04

tom_mai78101 (260 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!