0 registered members (),
1,094
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Basic Java Question
#285440
08/18/09 14:40
08/18/09 14:40
|
Joined: May 2004
Posts: 1,510 Denmark
Claus_N
OP
Serious User
|
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 A code sample would be very nice! 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
TheThinker
Member
|
Member
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.
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
OP
Serious User
|
OP
Serious User
Joined: May 2004
Posts: 1,510
Denmark
|
Thanks for the reply 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 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
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
TheThinker
Member
|
Member
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.
|
|
|
|