Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Creating the game window  (Read 410 times)
0 Members and 1 Guest are viewing this topic.
Offline Coltonater

Junior Newbie





« Posted 2014-01-14 01:04:53 »

So... I don't know why this is a problem for me. But this code doesn't seem to work right... without the paint method everything works fine, but when I just want to draw text onto the screen, it does, it gets rid of the gray background and somehow "copies" the background that is currently behind the window for some reason.

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  
package javagame;
import java.awt.Graphics;
import javax.swing.JFrame;

public class JavaGame extends JFrame
{
    public JavaGame()
    {
        setTitle("Java Game");
        setSize(500, 400);
        setResizable(false);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
   
    public void paint(Graphics g)
    {
        g.drawString("Hello World", 100, 100);
    }
   
    public static void main(String[] args)
    {
        new JavaGame();
    }
}


Below is the game window that is created, with the background instead of being the default grey, it is whatever was behind the window right after compile time.

https://www.dropbox.com/s/2az9coycdqcd93f/problem.PNG

Why is it doing this? Thanks for the help!
Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #1 - Posted 2014-01-14 01:06:55 »

Yeah, that's just a bug with your drivers most likely. Or crappy integrated graphics, I don't know. Windows has always had a hard time with that sort of stuff!

Offline Coltonater

Junior Newbie





« Reply #2 - Posted 2014-01-14 02:10:29 »

Is there anything I can do within the code to fix the problem?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #3 - Posted 2014-01-14 02:47:01 »

No, not really. At least I don't know, maybe someone else could tell you something!

Offline StumpyStrust
« Reply #4 - Posted 2014-01-14 02:48:23 »

By default java does passive rendering. Call repaint and see if it draws your text.

This can happen when any app in windows stops responding. It does not know what content to draw so it just passes what is behind the window through.

Offline philfrei
« Reply #5 - Posted 2014-01-14 04:14:37 »

Try calling clearRect() at the start of the paint method.

http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#clearRect%28int,%20int,%20int,%20int%29


1  
2  
3  
4  
5  
    public void paint(Graphics g)
    {
        g.clearRect(0, 0, 500, 400);
        g.drawString("Hello World", 100, 100);
    }



"It's after the end of the world! Don't you know that yet?"
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (50 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (57 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!