Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (488)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  Painting problem again  (Read 673 times)
0 Members and 1 Guest are viewing this topic.
Offline Beppe

Junior Member





« Posted 2013-08-25 22:11:55 »

Hi! I don't know if I've some system's problem or other ....
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public GameView(){
    JFrame container= new JFrame("Loderunner");
    JPanel panel= (JPanel) container.getContentPane();
    panel.setPreferredSize(new Dimension(460,460));
    panel.setLayout(null);
    setBounds(0,0,460,460);
    panel.add(this);
    setIgnoreRepaint(true);
    container.pack();
    container.setResizable(false);
    container.setVisible(true);
    container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    requestFocus();
    createBufferStrategy(2);
    strategy=getBufferStrategy();
    loadLevel("level.txt");
}

and this is the game loop
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public void gameLoop(){
    while(true){
        Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
        g.setColor(Color.BLACK);
        g.fillRect(0,0,460,460);
        //draw(g);
       g.dispose();
        strategy.show();
    }
}

http://imageshack.us/photo/my-images/23/rqs3.png/ in this link there is the screenshot of my pc so you can see that java don't paint a  part of window
Offline Several Kilo-Bytes

Senior Member


Medals: 11



« Reply #1 - Posted 2013-08-25 22:44:39 »

Call pack after setResizble. It doesn't make sense (I think it is because resizable and nonresizable frames are subtlely different) but it puts components in the wrong spot if you do not.
Offline Beppe

Junior Member





« Reply #2 - Posted 2013-08-26 08:28:35 »

So, with setResizable(true) actually work , but I don't want that the frame is Resizable ... and I take this code from space invaders 101 by Kevin Glass....How is possible that it is  wrong??
Also here in a jgo tutorial : http://www.java-gaming.org/topics/basic-game/21919/view.html
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Several Kilo-Bytes

Senior Member


Medals: 11



« Reply #3 - Posted 2013-08-26 16:48:44 »

The tutorial is wrong. Simply make container.pack(); the last line before container.setVisible(true); setResizable may change the size of the frame on Windows, so you must call pack again for every time you change the resizable property.

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  
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

public class Test
{
  public static void main(String[] args)  
  {
    final JFrame jf = new JFrame();
    final JPanel jp = new JPanel()
    {
      @Override public void paint(Graphics g)
      {
        g.setColor(Color.black);
        g.drawLine(0, 0, 199, 0);
        g.drawLine(0, 0, 199, 199);
        g.drawLine(0, 199, 199, 0);
        g.drawLine(0, 199, 199, 199);
        g.drawLine(0, 0, 199, 0);
        g.drawLine(0, 0, 0, 199);
        g.drawLine(199, 0, 199, 199);
       
      }
    };
    Dimension d = new Dimension(200, 200);
    jp.setMinimumSize(d);
    jp.setPreferredSize(d);
    jf.add(jp);
    jf.addKeyListener(new KeyAdapter()
    {
      @Override public void keyPressed(KeyEvent e)
      {
        final int k = e.getKeyCode();
        if(k == KeyEvent.VK_1)
        {
          jf.setResizable(!jf.isResizable());
        }
        if(k == KeyEvent.VK_2)
        {
          jf.pack();
        }
      }
     
    });
    jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    jf.pack();
    jf.setVisible(true);
  }
}
Offline Beppe

Junior Member





« Reply #4 - Posted 2013-08-26 17:11:26 »

Thanks for answer , take patience... Now the window have right dimension , but I can resize it , and I don't want this ...
This is my code ...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
JFrame container= new JFrame("Loderunner");
    JPanel panel= (JPanel) container.getContentPane();
    panel.setPreferredSize(new Dimension(460,460));
    panel.setMinimumSize(new Dimension(460,460));
    panel.setLayout(null);
    setBounds(0,0,460,460);
    panel.add(this);
    setIgnoreRepaint(true);
    requestFocus();
    addKeyListener(new KeyHandle());
    container.pack();
    container.setVisible(true);
    container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    createBufferStrategy(2);
    strategy=getBufferStrategy();
    loadLevel("level.txt");
}

What I must do??
P.S. What's is the wrong tutorial ?? because I have other problem with kevin glass' code ...
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #5 - Posted 2013-08-26 17:41:11 »

1  
panel.setResizable(false)

Offline Beppe

Junior Member





« Reply #6 - Posted 2013-08-26 18:06:32 »

According to IDE the method setResizable(false)  dosn't exist for a jpanel...
Offline Several Kilo-Bytes

Senior Member


Medals: 11



« Reply #7 - Posted 2013-08-26 18:11:17 »

1  
jFrame.setResizable(false);


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
    JFrame container= new JFrame("Loderunner");
    JPanel panel= (JPanel) container.getContentPane();
    panel.setPreferredSize(new Dimension(460,460));
    panel.setMinimumSize(new Dimension(460,460));
    panel.setLayout(null);
    setBounds(0,0,460,460);
    panel.add(this);
    setIgnoreRepaint(true);
    requestFocus();
    addKeyListener(new KeyHandle());
    container.setResizable(false); // FIRST!
   container.pack();             // SECOND!
   container.setVisible(true);    // THIRD!
   container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    createBufferStrategy(2);
    strategy=getBufferStrategy();
    loadLevel("level.txt");
}
Offline Beppe

Junior Member





« Reply #8 - Posted 2013-08-26 18:18:29 »

Yeah ! Work ! Thanks  Grin
Offline Beppe

Junior Member





« Reply #9 - Posted 2013-09-02 16:40:55 »

Hi , casually I have find a bug in this code I don't know why but  if I set the a too little size the problem return!
So i post an image for example :
Size 120 , 120  http://imageshack.us/photo/my-images/825/ne6c.png/
Size 100 , 100  http://imageshack.us/photo/my-images/819/1i1o.png/
so smaller size = more large gap
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Several Kilo-Bytes

Senior Member


Medals: 11



« Reply #10 - Posted 2013-09-03 21:55:55 »

Your panel is the correct size. The frame has a minimum size that is system dependent and can differ based on the type of window. If you try to force a very small window, it may be expanded. This best you could do with a view port that small would be to center the box and use a border. Or you could just draw more.
Offline Beppe

Junior Member





« Reply #11 - Posted 2013-09-10 22:03:29 »

Nono , it was just for curiosity , Thanks Several  Grin
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.

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (69 views)
2014-08-11 02:49:23

BurntPizza (46 views)
2014-08-09 21:09:32

BurntPizza (37 views)
2014-08-08 02:01:56
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!