Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Need help with objects that "paint"  (Read 837 times)
0 Members and 1 Guest are viewing this topic.
Offline cbech

Junior Newbie





« Posted 2009-06-19 00:40:06 »

EDIT: I've re-posted the proper code, and made my problem more clear. (I hope) At least now people will be looking at the right thing and not guessing at what they think my true problem is.

Zones extends a JPanel, which is added to a JFrame called Dorothy. When done this way, Zones doesn't work as planned. When I declare it as it's own class (public class Zones extends JFrame) and override it's paint function, it works the way I want. Details below.

What it should be doing:

1. Show user the sequence
2. Allow user to click squares
3. if right, Go to 1.
4. if wrong, show reset button that Goes to 1 on click.

What it does when inside another container:

1. Freeze as the splash screen is hidden, and it is set to visible.
2. unfreezes, allowing the player to interact (no sequence shown)
3. Allow user to click squares
4. if right, Freeze (no sequence shown), go to 2.
5. if wrong, show reset button. When clicked, freezes. Go to 2.

The user needs to see what Simon says to play.  Undecided

Apologies for not providing the code in the post, I was forced to provide a file because I reached the "10000" character limit, despite what Office and 2 online character counters said. (Said I had 9655 Tongue)
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #1 - Posted 2009-06-19 03:28:04 »

Yeah, you don't want to draw stuff directly into a JFrame, you want it to be drawn in a JPanel. What would work would be to just make a private class that's an implementation of JPanel with the paint method overridden. Then add that to the main JFrame as its sole component and it should work right.

See my work:
OTC Software
Offline cbech

Junior Newbie





« Reply #2 - Posted 2009-06-19 09:20:14 »

Edit: Reposted proper code so it's more clear. See Above.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zoto

Senior Member


Medals: 4



« Reply #3 - Posted 2009-06-19 10:27:36 »

You would probably be better off fixing the problems with the JPanel implementation. Both examples you gave are extending JFrame so it's impossible to help with the JPanel problems. To add a working class that extends JPanel to a JFrame you can use this simple code:

1  
2  
3  
4  
5  
6  
7  
static public void main(String[] args){
   JFrame frame = new JFrame();
   frame.add(new MyJPanel());  //Changed to the actual name you use
  frame.pack();
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
}
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

UprightPath (20 views)
2014-09-20 20:14:06

BurntPizza (26 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (70 views)
2014-09-10 13:57:51

TehJavaDev (95 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29

BurntPizza (52 views)
2014-09-07 01:13:42

Longarmx (39 views)
2014-09-07 01:12:14

Longarmx (45 views)
2014-09-07 01:11:22
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!