Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
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  
  Swing menus and the old heavy and light problem  (Read 1256 times)
0 Members and 1 Guest are viewing this topic.
Offline Browndog

Senior Newbie





« Posted 2006-05-15 04:18:31 »

Hi,

I've made a 3d game in java that uses what seems to be heayweight, it runs inside a full screen swing window. My current idea is to use swing to create a menu system for the game. I really wanted to use swing because of Synth and making really good looking menus seems fairly straight forward. I had the idea that I would be able to to put swing buttons and so forth over my game as it ran, but after doing a lot of reading this does not seem possible because of the lightwieght nature of swing and the heavyweight nature of my game.

I dont really have much experience in this area and was wondering if anyone had some ideas of way around my problem?

Thanks   
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #1 - Posted 2006-05-16 02:44:10 »

As long as you put your Swing controls inside a heavyweight that will appear on top of the 3d heavyweight you should be OK.

For menus you can do the usual thing to make Swing use heavyweight pop-ups.  If you can get away with making the Swing button areas rectangular then you should be OK for that too, just put a Swing widget inside a heavyweight Panel to make sure it draws on top of the other heavyweight.    Hmm.. there may be some issues with z-order...  I would try to write up a quick test app.

Offline CommanderKeith
« Reply #2 - Posted 2006-05-16 04:07:46 »

I know nothing about Java3D, but won't you run into threading issues with Swing's Event Dispatch Thread (EDT) if you try to include Swing menus?

Or is the Java3D rendering thread somehow coordinated with the EDT?

I am interested because I have had to jump through hoops to get Swing working in my direct-rendering 2D game without deadlock.

Thanks  Smiley
Keith

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Browndog

Senior Newbie





« Reply #3 - Posted 2006-05-17 00:49:31 »

Thanks swpalmer if you could whip somthing up and let me know how its goes, I'm curretly a little stumped by the whole thing.
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #4 - Posted 2006-05-18 06:11:43 »

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  
/*
 * Main.java
 *
 * Created on May 17, 2006, 11:32 PM
 */


package heavyswing;

import java.awt.Canvas;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Panel;
import java.awt.Window;
import javax.swing.JButton;

/**
 *
 * @author Scott Palmer
 */

public class Main
{
   
   /** Creates a new instance of Main */
   public Main()
   {
   }
   
   /**
    * @param args the command line arguments
    */

   public static void main(String[] args) throws InterruptedException
   {
      Window window = new Window(null);
      window.setLayout(null);
      window.setBounds(10,10,220,200);

      JButton swingButton = new JButton("I'm Swing!");
      window.add(swingButton);
      swingButton.setLocation(10,10);
      swingButton.setSize(swingButton.getPreferredSize());
     
      JButton swingButton2 = new JButton("I'm Swing on a Heavyweight!");
      Panel heavyPanel = new Panel(null);
      heavyPanel.add(swingButton2);
      swingButton2.setLocation(0,0);
      swingButton2.setSize(swingButton2.getPreferredSize());

      window.add(heavyPanel);
      heavyPanel.setLocation(10,40);
      heavyPanel.setSize(swingButton2.getPreferredSize());

      // Add a heavyweight canvas
     Canvas canvas = new FancyCanvas();
      // comment out the next line to see the other Swing button
     window.add(canvas);
      canvas.setLocation(0,0);
      canvas.setSize(220,200);
     
      // It seems that the components are drawn in the reverse order in
     // which they were added. But is it always so?
     
      window.setVisible(true);
     
      Thread.sleep(10000);
      window.setVisible(false);
      window.dispose();
   }
}

// This could be a 3D canvas
class FancyCanvas extends Canvas
{
   @Override
   public void paint(Graphics g)
   {
      g.drawLine(0,0,getWidth(),getHeight());
      g.drawLine(0,getHeight(),getWidth(),0);
   }
}

Offline Browndog

Senior Newbie





« Reply #5 - Posted 2006-05-19 01:13:11 »

Thanks for your help! I have a problem though,  when I use the panel the panel gets drawn the but  not the button Sad. I'm going to have a play with it and see if I can fix it. If you have any ideas let me know.

Also I was thinking is it possible to draw the button maually? I was thinking of calling draw each loop of my 3d app.
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.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!