Results 1 to 10 of 10
  1. #1
    Unome is offline Member
    Join Date
    Oct 2008
    Posts
    44
    Rep Power
    0

    Default [SOLVED] Resize error? ZombieEscape

    Hey guys, a lot of you have helped me work out the kinks in my bullet man, stick archer, ect... I started from scrap a couple days ago. Took what you taught me, applied it...and? It worked!

    I now have a functioning applet that displays a solider (complete with eye patch, pistol, boots and clothing) The soldier can run forward, back, jump, crouch, fire(in any of those positions) and pause! I'm working on a death screen right now, and I'll be tackling a start menu as well as enemies soon.

    I have a simple but FRUSTRATING problem. When I create this applet.... its sized at 100x100 (nearly the size of my character) I manually resize it everytime. I need to have it automatically be sized at the right size. Now...before you type "N00b setSize(x,y);" Keep in mind... I've already tried taht. I'm using some innerclasses to draw the applet and setSize doesn't work wit hwhat I'm using... Heres some code to show you the part where I draw the applet. I'm trying to display it at 1000x1000.... but so far its not listening.

    PHP Code:
    ...
    	    public static void main(String[] args) 			//sets up applet
    	    {
    	        JApplet applet = new ZombieEscape();			//sets up a possible frame
    	        JFrame f = new JFrame();
    	        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	        f.add(applet);
    	        f.setSize(1000,1000);
    	        f.setLocation(200,200);
    	        applet.init();
    	        f.setVisible(true);
    	    }
    ...
    any tips?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Just curious: why are you placing a JApplet in a JFrame?

  3. #3
    Unome is offline Member
    Join Date
    Oct 2008
    Posts
    44
    Rep Power
    0

    Default

    The code is built so it can be made in either a JFrame or a JApplet. Hardwired helped me sort that out, and this was one of the only ways it would work with keybindings. I speculate you could remove the JFrame altogether, but that eliminates the use of JFrame components. Honestly: I don't know lol. I got help on this part, and the keybindings... I figured out how keybindings worked and made my own... but this is the part I never quite understood. Most everything else was my own idea though... its a 40,000 line project lol

  4. #4
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Probably, just guesssing, calling init() on the applet after calling setSize() on the JFrame ....

    Try this:Converting an Applet to a Standalone Java Application

    I try to keep my classes to 1,000 lines or less, usually most functionality can be packed into 50-500 lines. Where did you get a 40,000 line project?
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  5. #5
    Unome is offline Member
    Join Date
    Oct 2008
    Posts
    44
    Rep Power
    0

    Default

    Where did I get a 40,000 line project? I used about twenty polygons with roughly 10-12 points each to create the Soldier object (thats in a seperate class) and then I have the bullet class, gun class, death screen class. I got an inner class that controls a thread, I got an inner class that controls the applet, and I got a giant keybinding thing that has 8 bindings. My guy can jump, walk left, walk right, crouch, fire in ANY of those positions. I can pause, commit suicide and I've set up a health system that makes him lose health when I want him too.... So thats why I have a 40,000 line project. I got like 5 classes, and its not some simple thing at all....

  6. #6
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Okay, that makes sense. What about the original question? ... any luck with my suggestion?
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  7. #7
    Unome is offline Member
    Join Date
    Oct 2008
    Posts
    44
    Rep Power
    0

    Default

    hmm... not really.... the link you sent didn't work lol... at least for me. I just need to figure out how to setSize with that code I showed above....

  8. #8
    Unome is offline Member
    Join Date
    Oct 2008
    Posts
    44
    Rep Power
    0

    Default

    Got IT! haha... wow

    this is where I was supposed to put it
    PHP Code:
     public void init() 
    	 {
    		 Moveball = new moveball();		//constructs 1st inner class
    		 Moveball.setFocusable(true);		//allows keybindings to work within first inner class
    		 setSize(500,250);
    		 Ballloop = new ballloop(Moveball);	//constructs 2nd inner class
    		 add(Moveball);				
    	     bindKeys();
    	 }

  9. #9
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    message eidt: { crossed the time barrier - I see your reply }

    Okay, maybe incomplete answer but where is the init() on the applet? If one uses a standard applet class that has nothing other than "extends Applet" then we are likely going to get a default value close to 100x100 or at least I would think so as the browser would likely use some minimal setSize(int,int) to avoid help calls from hell on a 4x4 pixel display. Again, we raise the question of why placing Applet in a JFrame ( or the other way around, whichever it is ) ( not to be convulsive on the matter ) Applet has a JPanel by default constructor and one can draw on that or place ( I would think ) a JFrame in the applet. Seems backwards on first glance.

    The link I posted works so basically it is likely to be call init() on Applet before placing in the JFrame. Your setSize(1000,1000); should work. There is also something called Toolkit.getDefaultToolkit.getDesktop() or something like that which will get screen sizes.

    This is a nasty pitfall and recurrent problem so be prepared to sink some resources in getting this working.
    Last edited by Nicholas Jordan; 11-15-2008 at 07:08 PM. Reason: crossed timelines
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  10. #10
    Unome is offline Member
    Join Date
    Oct 2008
    Posts
    44
    Rep Power
    0

    Default

    Yah, that actually was the error. My applet is being run in an inner class... The trick was to set the size in the init() that I called the inner class in... lol... silly but it worked

    Thanks guys!

Similar Threads

  1. Image Resize
    By jithan in forum New To Java
    Replies: 4
    Last Post: 11-07-2008, 10:26 AM
  2. Window resize icon...
    By pele in forum SWT / JFace
    Replies: 3
    Last Post: 06-09-2008, 09:31 AM
  3. resize tabs in jtabbedpane
    By osval in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 04:02 AM
  4. Resize frame
    By lenny in forum AWT / Swing
    Replies: 1
    Last Post: 07-30-2007, 12:18 AM
  5. Help with JTextArea, resize windows
    By paul in forum AWT / Swing
    Replies: 1
    Last Post: 07-16-2007, 05:11 PM

Posting Permissions

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