I tried running your code, and it worked fine for me the JFrame was not see through for me. not sure what would cause it to be see through for you. :-\
Please don’t advise people if you don’t know enough about a specific topic
If nothing else, yes, super.paint(g); must be added. Either that, or you must fill the entire area of the component yourself. Failing to do that, will lead to undefined results (like you’re seeing now). The same thing occurs, for example, when you call setOpaque(true) and don’t fully paint the component: it will lead to rendering artifacts, like views of ‘raw’ memory on your CPU/GPU, depending on the implementation.
Further, you are overriding paint(g) on a JFrame, which is not allowed, please only override paintComponent(g). But do you really want to paint over the entire frame, or just between the frame borders and under the caption bar? What you most likely are looking for is this:
JPanel canvas = new JPanel() {
public void paintComponent(Graphics g) {
g.drawString("hello world", 100, 100);
}
}
canvas.setPreferredSize(new Dimension(w, h));
JFrame frame = new JavaGame();
frame.getContentPane().setLayout(BorderLayout.CENTER);
frame.getContentPane().add(canvas);
frame.pack();
frame.setVisible(true);
Before moving to OpenGL, our whole game was Java2D, which I still have.
I have never used Panels or canvas’, always painted directly on a Frame or JFrame
I have always overridden paint never paint components
granted, in real games we used bufferstrategy of course… so you dont even use paint() anymore
[quote]fill the entire area of the component yourself
[/quote]
well, I have always done that without even thinking about it, just to be sure.
I see you’re doing the JavaHub tutorials like I mentioned ;D
I had the exact same problem and sticking super.paint(g) fixes it but the preferred way of doing it I believe is sticking adding a Canvas or JPanel to the JFrame and having your game play in that. Unfortunately, the JavaHub dude doesn’t cover doing that up till as far as I’ve gotten but maybe he’ll do that later on.
Also, I recommend you try making a Pong game before watching that tutorial. You’ve got enough to on from the first 11 videos so it’s very doable but might be difficult.
well, I have always done that without even thinking about it, just to be sure.
[/quote]
Just because it worked for you, doesn’t mean you should. Many previous Java4K entries were not properly making calls to AWT/Swing, and while it worked at the time, current Java runtimes either flicker a lot of render nothing at all. So, if you want reliable results, don’t just look at what works, but read up on how it’s supposed to be done.
yeah im doin the tuts really helpfull though the see through part only happened before i drew anything else like a ball it only happened when the only thing on the frame was text so its kinda fixed now.