bufferstrategy

Component must have a valid peer - BufferStrategy

Deadly 提交于 2020-06-17 06:05:14
问题 First off all, I know questiones like this has been asked before, but no answers seem to fix my problem. I am working on a little game, and for some reason java returns an IllegalStateException whenever I try to create a new bufferstrategy. I am adding the game to a JFrame, but the exception is still thrown, here is the code for adding to the JFrame: JFrame frame; public Window(int x, int y, int width, int height, String title, boolean focus, Main game) throws IOException { frame = new JFrame

BufferStrategy drawing and updating the screen

流过昼夜 提交于 2019-12-25 04:24:20
问题 I am trying to draw individual rectangles(non filled) side by side to make a floor and then moving the whole floor left at a constant speed. My issue here is that when they move left the screen doesn't refresh or delete the previous screen therefore after a few seconds the set of Rectangles is a solid color. here is my code. I would like to find out how to load the screen, then update values, delete old screen and display the new screen? FRAME CLASS: package Main; import java.awt.Dimension;

triple buffer heavy flickering

拟墨画扇 提交于 2019-12-21 23:12:08
问题 Shouldn't triple buffering and Canvas be an optimal solution for passive rendering? I've just wrote this java code that displays a circle. If I leave bufferstrategy to 3, it flickers so much. If I turn it down to 2 or 1 it's ok. Maybe I'm doing something wrong? public void run(){ while (running){ update(); draw(); } } public void update(){ } public void draw(){ BufferStrategy bs = getBufferStrategy(); if (bs==null){ createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); g

java - BufferStrategy is not creating stategy? (nullpointerexception)

谁说胖子不能爱 提交于 2019-12-13 04:37:57
问题 I decided to start understanding BufferStrategy for my graphics. I'm not sure if using my jframe in a static form is what's cause this, but it looks alright to me. What am I missing? Main.java package Main; import java.awt.Toolkit; public class Main implements Runnable { private Thread gameThread; private Game game; private boolean running = false; public static ClientFrame frame; public static Toolkit kit; public static int WIDTH = 300, HEIGHT = WIDTH*16/9, SCALE = 3; public Main() { game =

Adding textfield to Graphics in java

瘦欲@ 提交于 2019-12-10 03:29:09
问题 Does anyone know how to add JTextField into Graphics name bufferstrategy.getDrawGraphics ? Tryed to pain it into graphics, something like this: private JTextField Input = new JTextField(); BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3); return; } final Graphics gCommands = bs.getDrawGraphics(); Graphics gCC = bs.getDrawGraphics(); Input.requestFocus(); Input.paint(gCC); Input.setBounds(800,250, 350,20); Input.setBorder(BorderFactory.createLineBorder(Color

Adding textfield to Graphics in java

强颜欢笑 提交于 2019-12-05 03:50:54
Does anyone know how to add JTextField into Graphics name bufferstrategy.getDrawGraphics ? Tryed to pain it into graphics, something like this: private JTextField Input = new JTextField(); BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3); return; } final Graphics gCommands = bs.getDrawGraphics(); Graphics gCC = bs.getDrawGraphics(); Input.requestFocus(); Input.paint(gCC); Input.setBounds(800,250, 350,20); Input.setBorder(BorderFactory.createLineBorder(Color.BLACK, 0)); Input.setEditable(true); Input.setBackground(getBackground()); Input.setForeground

triple buffer heavy flickering

穿精又带淫゛_ 提交于 2019-12-04 18:34:44
Shouldn't triple buffering and Canvas be an optimal solution for passive rendering? I've just wrote this java code that displays a circle. If I leave bufferstrategy to 3, it flickers so much. If I turn it down to 2 or 1 it's ok. Maybe I'm doing something wrong? public void run(){ while (running){ update(); draw(); } } public void update(){ } public void draw(){ BufferStrategy bs = getBufferStrategy(); if (bs==null){ createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); g.setColor(Color.BLACK); g.fillOval(30, 30, 20, 20); g.dispose(); bs.show(); } and this is the JFrame class

When using createBufferStrategy() in java, does it help to have more than 2 buffers? Is there a downside?

大憨熊 提交于 2019-12-02 04:28:42
问题 It seems like most people recommend just using 2 or 3. Is that just because more than 3 takes up too much processing power or something (forgive me I'm kind of new to this)? In what kind of programs would you use more than 3 buffers? 2 or 3 works fine for my program, I'm just curious. 回答1: Actually its pretty easy to understand once you know the benefits of buffer strategies. Let's take a brief look at what happens in all three cases. In single buffering you have only one display to write

How to draw images on transparent window?

主宰稳场 提交于 2019-11-28 12:46:44
I'm trying to draw Images with Graphics2D on JFrame. But this code only displays blank background. How to do that? Java Version: SE-1.6 IDE: Eclipse My code looks like this: import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferStrategy; import java.awt.geom.Line2D; import java.util.TimerTask; import javax.swing.JFrame; public class GraphicTest extends JFrame{ public static void main(String[] args) { GraphicTest gt = new GraphicTest(); gt.start(); } JFrame frame; BufferStrategy strategy; GraphicTest(){ int width = 320; int height = 240;

What is the correct way to use createBufferStrategy()?

喜夏-厌秋 提交于 2019-11-28 12:22:21
问题 Even after using Java Swing for over a year, it still seems like magic to me. How do I correctly use a BufferStrategy, in particular, the method createBufferSrategy() ? I would like to have a JFrame and a Canvas that gets added to it and then painted. I would also like to be able to resize ( setSize() ) the Canvas. Every time I resize the Canvas it seems my BufferStrategy gets trashed or rather, turns useless, since using show() on the BufferStrategy does not actually do anything. Also,