Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - JL235

Pages: 1 2 3 [4]
46
Computer Programming / Re: Java Panel/Frame has different sizes
« on: September 14, 2011, 10:29:39 pm »
I have added the code I suggested, but for the JPanel, to your original code, and it works fine for me.
Code: [Select]
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class MainFrame extends JPanel implements KeyListener {
  /* Game Panel class containing all functions */

  private JFrame mainFrame;
  private boolean needs_repaint;

  public void paintComponent(Graphics g) {
    /* Draws the elements on the screen */
    super.paintComponent(g);

    System.out.printf("Panel Width: %d\n", this.getWidth());
    System.out.printf("Frame Width: %d\n", this.getParent().getWidth());

    /* Repainting has finished */
    needs_repaint = false;
  }

  public void update() {
    /* Main game loop */
    
    /* Always repaint */
    //this.repaint();
  }

  public void run() {
    /* Displays the frame, start the game */
    mainFrame.setVisible(true);
    this.requestFocus();
  }

  public MainFrame() {
    /* Defines the frame and the game panel */
    this.setFocusable(true);
    this.addKeyListener(this);

    /* Fixed Layout frame */
    Dimension size = new Dimension(850, 600);
    this.setSize(size);
    
    mainFrame = new JFrame("Game");
    mainFrame.setResizable(false);
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.getContentPane().add(this);   // Add game panel to main frame
    mainFrame.pack();

    /* Start timer with main game loop */
    Timer timer = new Timer(25, new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        update();
      }});
    timer.start();
  }

  /* Game Class is not abstract, and these functions are not needed */
  public void keyPressed(KeyEvent key) {}
  public void keyReleased(KeyEvent arg0) {}
  public void keyTyped(KeyEvent arg0) {}
  
  public static void main(String[] args) {
    new MainFrame().run();
  }
}

I had a similar problem to this when I wrote my own graphics engine, but it was around 5 years ago, so the solution is pretty hazy. If I remember correctly, it could be that the width is including other items in the JFrame, such as the surrounding border. However I don't know for sure. For safety I'd concentrate on checking the size of your inner JPanel, as this is the component where the size really matters, and not care what the outer frame is using.

I also added a call to pack, to ensure it's all packed down to the size you want.

47
Other / Re: What computer OS do you use?
« on: September 14, 2011, 10:18:10 pm »
Windows 7. I pretty much stick to Windows as all my favorite tools are on there, I know how to heavily customize it (like getting multiple desktops), and I've always found Linux waaaaaaaaaay too buggy for my liking (multiple monitors are good example).

48
Other / Re: Windows 8 pre-beta released
« on: September 14, 2011, 10:16:25 pm »
Any ability of a duel boot between windows 7 then adding windows 8?
If you partition your hard disk, then I would imagine you can install Windows 8 along side 7. I'll be doing this.

This is the first version of Windows I've ever been looking forward to. I loved Vista, and now 7, but only after upgrading. The new metro theme looks beautiful, and I love how it's so HTML5 oriented. HTML applications should also now use IE 10, meaning it should be easy to build very pretty non-metro HTML5 desktop applications; i.e. something like Steam.

It also seems to be a huge overhaul of the whole OS, even down to the new file system, which is hopefully the result of all their WinFS work.

49
Computer Programming / Re: Java Panel/Frame has different sizes
« on: September 13, 2011, 08:31:10 pm »
I believe the issue is that setting the size only sets the current size; what it is right now. It does not set the size you want it to be, after various calls have been made. Disabling resizing is for preventing the user from resizing the component, it doesn't turn resizing off.

In my own code I do:
Code: [Select]
        Dimension size = new Dimension(width, height);
        setSize(size);
        setMinimumSize(size);
        setMaximumSize(size);
        setPreferredSize(size);

You should also probably call 'pack' on the frame, after setting the size and before you make it visible.

50
Computer Programming / Re: Picture Rotating
« on: September 13, 2011, 06:04:53 pm »
AffineTransform, that's just what I need. Thanks! Also +1 for the detailed answer JL235.
Not a problem. I've used both Java2D and JOGL quite heavily in the past and have a lot of experience with them. Java2D is a very sophisticated graphics library, but these days I personally think it's quite dated. For drawing custom GUI elements, and especially for games, I think there are lots of better alternatives out there. But it ultimately depends on what you do with it.

Just to throw it out there as something you might want to play with, Oracle are currently developing JavaFX 2. It's far better then JavaFX 1, and it's hardware accelerated, but it's only out in beta.

51
Gaming Discussion / Re: Good RPG games for gbc/nds?
« on: September 13, 2011, 11:44:47 am »
I'd recommend Zelda: Links Awakening, which is one of my all time favorite RPGs. It was for the original Game Boy, and was later re-released on the GBC and 3DS.

52
Gaming Discussion / Re: A FREE version of Starcraft II!
« on: September 13, 2011, 12:17:34 am »
I was thinking similar before I got Starcraft 2, that's the three combined make up a lot of money for one game. However after buying Starcraft 2; it's actually around the same size as the original Starcraft. Maybe a tad shorter, but it's certainly not short, and it's missions are much better designed. It is a full game in it's own right, and the next two are expected to be bigger.

But I really didn't like the story, including how it's told. For most of the game, it's conveyed through reports your given from elsewhere in the galaxy. As a result it feels like the main plot is just passing you by, since for most of the game your saving colonists or completing side quests. It's only on the last couple of missions that you really get involved in the main plot.

But it was still easily the best game I played last year, and the missions in the story mode are truly some of the best designed.

53
Computer Programming / Re: Picture Rotating
« on: September 12, 2011, 02:57:49 pm »
I am presuming you are using Java2D for this (the default graphics library which comes with Java). For this when rotating an image, no, you don't need to know trigonometry. Instead you can use the AffineTransform class in the Java API. You create one, set the rotation, and then pass it in to the Graphics2D when you draw an image. There is a tutorial on this here.

Java2D can do rotations in real time, but it's pretty slow. At most, your talking 10s or 100s of rotations, but it depends on the size of the image (and a bunch of other factors, such as JVM version, start up flags, and your OS). You can speed this up by generating a rotated image, and storing it, but this in turn creates a new set of issues. Creating lots of images requires lots of memory, which you can quickly run out of. To fix this you can use HashMaps and WeakReferences to allow you to create as many images as you want, which are automatically removed if you run out of memory. If they are removed then you just remake the image.

For these reasons, performance and memory, is why most Java game developers use hardware accelerated libraries instead. For 2D graphics these include Slick, LWJGL or JOGL. With them you can trivially draw 10,000s to 10 millions of rotated images, at 60 frames per second. From the sounds of your post, you are mostly interested in getting underneath the bonnet, building engines, and working this stuff out. These libraries will hold you hand less often, especially LWJGL and JOGL which are just wrappers for OpenGL. For them you would need to know either how matrix operations work, trigonometry, or both, to do things like rotating an image.

One final thing to note is that with your draw rectangle example, x and y refer to the top left corner. When rotating, you need to work from the centre. This is because a rotation needs a centre of origin, the point it is being rotated around, which will be the centre of the image.

54
You can also try IE Tester on Windows for testing multiple versions of IE. It's very unstable, but damn useful, and free!

IE Tester is Windows-only.
IE Tester is IE-only.

This tests a lot of stuff on any Operating System :D
If your not on Windows, then I guess it's useful, and it's definitely a great idea. But with the lag, and restrictions, it just doesn't compare to being able to run 5 IE's + FireFox + Chrome + Safari + Opera at the same time, locally on your PC.

55
You can also try IE Tester on Windows for testing multiple versions of IE. It's very unstable, but damn useful, and free!

56
Miscellaneous / Re: Gaming at school
« on: September 05, 2011, 03:19:49 am »
Somewhere I worked I was forced to use Dreamweaver; I would describe it as being a bad HTML editor tied to a bad FTP client. It has emphasis on being able to do some project management for you, like a template system, locking files and handling updating local/server files. But for an experienced programmer it can hold you back, so I ended up using my own tools instead.

If your building a static website, it's only maintained by one person, your not experienced with web development, and have no intention to learn, then Dreamweaver works very well. It's once you come out of that box that it quickly becomes a pain.

57
Web Programming and Design / Re: Forum software choice.
« on: September 03, 2011, 11:13:44 pm »
Personally I don't like phpBB or SMF. The default themes are either generic, or ugly, and I think they produce forums which are far too big for most sites.

So I also prefer to build my own. It's more work, but you also end up with a forum that integrates better with your site.

Pages: 1 2 3 [4]