Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (756)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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 1286 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 Devvie

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:

static public void main(String[] args){
   JFrame frame = new JFrame();
   frame.add(new MyJPanel());  //Changed to the actual name you use
Pages: [1]
  ignore  |  Print  

DesertCoockie (56 views)
2018-05-13 18:23:11

nelsongames (88 views)
2018-04-24 18:15:36

nelsongames (78 views)
2018-04-24 18:14:32

ivj94 (763 views)
2018-03-24 14:47:39

ivj94 (95 views)
2018-03-24 14:46:31

ivj94 (647 views)
2018-03-24 14:43:53

Solater (108 views)
2018-03-17 05:04:08

nelsongames (189 views)
2018-03-05 17:56:34

Gornova (430 views)
2018-03-02 22:15:33

buddyBro (1090 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!