Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,103 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Basic Java Question #285440
08/18/09 14:40
08/18/09 14:40
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Hi,

I am currently learning Java, and I wondered how I can draw to a JFrame using a backbuffer?

At first I thought that I could just create a new instance from "Image", but that's an abstract class. Searching the web only gave me some code samples which were using some "createImage"-function to create an image for the backbuffer, but I can't seem to find that function anywhere frown

A code sample would be very nice! smile I already know C# quite well, so the Java syntax itself isn't a problem.

Re: Basic Java Question [Re: Claus_N] #285460
08/18/09 16:28
08/18/09 16:28
Joined: Jun 2006
Posts: 214
Germany, NRW
T
TheThinker Offline
Member
TheThinker  Offline
Member
T

Joined: Jun 2006
Posts: 214
Germany, NRW
You don't need a backbuffer with a JFRame. If you say "setDoubleBuffered(true)" ist will be doublebuffered.
If you want to paint onto the JFrame, take another component like JComponent extend it and override the "public void paintComponent(Graphcis g)" method.
If you want to add components to a JFrame, use the ContentPane of the JFrame to add. like "getContentPane().add()"
The JComponents are mostly buffered.

Code:
class MyFrame extends JFrame {

public static void main(String[] args){
  new MyFrame();
}

public MyFrame(){
  setSize(800, 600);
  setDefaultClosingOperation(true)
  //setDoublebuffered(true);
  setVisible(true);
}

}



I hope you are using eclipse. Try to goole about "Java Swing".

Last edited by TheThinker; 08/18/09 16:29.
Re: Basic Java Question [Re: TheThinker] #285484
08/18/09 18:08
08/18/09 18:08
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Thanks for the reply smile

Somehow my form (derived from JFrame) does not contain a method called 'setDoublebuffered', I don't really know why - it does contain a 'isDoublebuffered'-method, but I see no way to change it frown

I'm using NetBeans, not Eclipse, and it seems I'm using Java version 1.6.0_16

Edit:
What is 'rootPane'? I randomly noticed that a 'this.rootPane.setDoublebuffered'-method does exist. It doesn't solve the problem though frown

Last edited by Claus_N; 08/18/09 18:13.
Re: Basic Java Question [Re: Claus_N] #285499
08/18/09 19:37
08/18/09 19:37
Joined: Jun 2006
Posts: 214
Germany, NRW
T
TheThinker Offline
Member
TheThinker  Offline
Member
T

Joined: Jun 2006
Posts: 214
Germany, NRW
Ok,

The JFrame:

-Is always doublebuffered (as far as i know)
-consist of several container 1. the Frame, 2. the rootPane, 3. the glas Pane, 4. the contentPane
- There are other window container types like JDialog or JWindow with special functions
-Always add other components to the contentPane. If you don't want to write frame.getContentPane().add(...) everytime do this:
"Container c = frame.getContentPane(); c.add ..."
-Don't use a visual swing gui editor, most of them are crap
-Don't forget the layouts. A JFrame's contentPane always has the BorderLayout aplied as standard. If you add a component do this c.add(myPanel, BorderLayout.CENTER) (or NORTH, SOUTH, WEST, EAST)
-Google for Layouts and JFrame or Swing. There are tons of tutorials about Java outside
-Java is the best language to do quick prototypes or toolsets. It comes with all structures like Lists or Hashmaps, all important Math functions and since 1.6 with a very improved rendering system (improved awt)
- btw. since 1.6 the awt (Component manager) supports transparent windows or perpixel masks

Last edited by TheThinker; 08/18/09 19:39.
Re: Basic Java Question [Re: TheThinker] #285506
08/18/09 20:03
08/18/09 20:03
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Thanks a lot for the info & tips laugh

I checked my JFrame (this.isDoubleBuffered() in the class which inherits JFrame), and it returned false, so I might not be the case it seems frown

Re: Basic Java Question [Re: Claus_N] #285512
08/18/09 20:16
08/18/09 20:16
Joined: Jun 2006
Posts: 214
Germany, NRW
T
TheThinker Offline
Member
TheThinker  Offline
Member
T

Joined: Jun 2006
Posts: 214
Germany, NRW
But, you don't need a dubblebufferred Frame, because, if you want to draw own Graphics you should use a class that extends JComponent or simply extend the JPanel. This components can be set to doubblebuffered.
Because of the multiplatform thing of the awt, the JFrame must follow some rules and there is simply no need to doublebuffer the Frame.
(If I remember correctly the basic Frame of the awt was also not doublebuffered. If you wanted to paint buffered Graphics on it you had to write an own Graphics buffer and flip it by yourselfs onto the screen.)

Re: Basic Java Question [Re: TheThinker] #285520
08/18/09 20:49
08/18/09 20:49
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Hmm okay, I'm just used to do the rendering (either GDI+ or MDX) from the paint event of the form in C#, but I'll try making a new class extending JComponent or JPanel as you suggest laugh

Well, I'm gonna try it tomorrow, it's getting too late for today smile

Re: Basic Java Question [Re: Claus_N] #285662
08/19/09 15:03
08/19/09 15:03
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline OP
Serious User
Claus_N  Offline OP
Serious User

Joined: May 2004
Posts: 1,510
Denmark
I finally got it working! Thanks a lot! laugh

Here's the code I used for testing (IRenderable is just an interface I made) smile
Code:
import java.awt.*;
import javax.swing.*;
import java.util.ArrayList;

public class GraphicArea extends JComponent
{
    private ArrayList<IRenderable> objectList;
    private float deltaTime;

    public GraphicArea()
    {
        this.objectList = new ArrayList();
        this.deltaTime = 0.0f;
        this.setDoubleBuffered(true);
    }

    public void add(IRenderable _object)
    {
        this.objectList.add(_object);
    }

    
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);

        this.deltaTime += 0.1f;
        for(int i = 0;i < this.objectList.size();i++)
        {
            this.objectList.get(i).Render(g,this.deltaTime);
        }
    }
}




Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1