Graphics Are Flickering
Feb 2, 2014
I attempted to make my square move in the screen and i set up collision with another object, however the graphics are flickering, really flickering, here's the code:
Java Code:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class NewEmpty extends JFrame {
double p1speed =5, p2speed =5;
[code]....
View Replies
ADVERTISEMENT
Jan 12, 2011
I need to create a program that draws a graph, but for now, all I have done is two lines: the X and Y axis. The program is designed in a way as to automatically resize the graph when the window is resized.
Is this code in some way extremely inefficient? I get TERRIBLE flickering when I resize the window. Is there something that will at least reduce the flickering?
mainApp.java:
import java.awt.*;
import javax.swing.*;
public class mainApp {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(300,300);
frame.setVisible(true);
[Code] ....
I have added a screenshot that shows the window flickering.
View Replies
View Related
Jul 28, 2014
I am trying to call another swing frame from my current frame. And after calling second frame i dispose the current frame.
But while second frame coming on the screen, current frame gets dispose and second frame takes some seconds to appear on screen.
So its creating a bad flickering effect on screen and its not suitable for my application.
I want that first frame will call sencond frame and it will not look like second frame is called. I just want to cancel flickering effect.
Here is my source code.
1st Frame:
public class Welcome extends JFrame {
JFrame f;
JTextArea nameField,nameField1;
JLabel lable;
[Code] .....
View Replies
View Related
Mar 12, 2014
i'm currently doing my system now and my problem is about inserting an image to my jframe form with thread because if i insert image and when i run it it blinks too slow comparing if i use simple oval it doesnt blink.
why is it that if i wrote the code like this.
public void DrawSnake(Graphics g) throws IOException {
Image image = ImageIO.read(this.getClass().getResource("body1.jpg"));
Image image1 = ImageIO.read(this.getClass().getResource("body.jpg"));
Image headr = ImageIO.read(this.getClass().getResource("headr.jpg"));
Image headl = ImageIO.read(this.getClass().getResource("headl.jpg"));
[Code] .....
View Replies
View Related
Mar 2, 2014
I have been stuck on this now for almost a week, the problem is that the textfield keeps flickering. I have read that swing does not work well with fullscreen exclusive mode, but I'm not sure what else to do other than create my own class similar to a textfield and detect every single key press which doesn't seem the right thing to do.
- If this line is uncommented "TextFieldTest.this.tfChatField.paint(g);" then it will display the textfield at the top of the screen, and a flickering textfield at the bottom(which is where it's meant to be)
Java Code:
package textfieldtest;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Graphics;
import java.awt.Graphics2D;
[Code] ....
View Replies
View Related
Aug 29, 2014
I'm trying to set up a splash screen where a native splash screen is shown initially and then replaced with the stage from my preloader. This is fairly simple to do. I use the below code to get everything lined up properly.
private void alignStage(Stage stage) {
SplashScreen splashScreen = SplashScreen.getSplashScreen();
if (splashScreen != null) {
// Align the stage based on the current splash location
Rectangle bounds = splashScreen.getBounds();
stage.setX(bounds.getX());
stage.setY(bounds.getY());
[Code] ....
The problem I'm having is that my Stage isn't actually shown by the time the commented event gets fired. The API for onShown says:
Called just after the Window is shown.
My guess is the window has transitioned to being shown, but there's a slight delay until it gets rendered on screen. If that's a decent assumption, is there a reliable way I can make sure my preloader stage is visible on screen before I hide the native splash?
The best option I can think of so far is to delay hiding the native splash until the preloader gets the BEFORE_START notification. This works (no flicker), but, since both splash screens are actually visible for a while, using a transparent splash doesn't work very well (which actually isn't too big of a deal).
View Replies
View Related
Jan 5, 2014
He said that if you need something that Swing can't provide, like a bar graph, you build it. Now, being used to just writing a method that will open up a JFrame, how you would actually build graphics on your own. How in the world would that work? How would one write their own methods to make a window or to build a graph?
View Replies
View Related
Dec 31, 2014
I am attempting to create a n-body simulation using orbital dynamics and Java in school.
I am only in high-school, but I have some programming experience. The logic of this program comes quite easily. My problem is the graphical part, so I was just looking for quick methods to implement graphics.
What I am looking to do, is display objects onto the screen and manipulate their respective x and y coordinates as time pass. I have tried to use BufferedImages and an array of every pixel on the screen, but it quickly becomes extremely hard to draw circles etc. I have also tried the Graphics class and using g.fillOval() etc, but this can also get tedious.
Are there any more efficient methods, libraries etc? And also, how should I use the time variable, a variable that updates everytime the program updates?
View Replies
View Related
Nov 24, 2014
I wanted to create a interface with buttons ofshapes and type of transformation where user first select a shape, the shape will appear and user will have to click on the buttons on resize, reflect, rotate or skew to transform to shape. How can i do the coding? such as adding listeners to the shapes?
View Replies
View Related
Jul 30, 2014
What I am trying to do is save the the content drawn to my screen as an image. The following code is my render method and although I know how to use it, I don't fully understand the classes and how they work with is making this difficult.
public void render() {
BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
[code]....
View Replies
View Related
May 28, 2014
I have to write a program for class that basically uses Paint Component to draw a bunch of rectangles to look like a building then have them change color randomly. I am stuck I can't figure out how to make it draw the rectangles in rows and columns to look like the building i can make it display multiple squares randomly however but thats not the assignment.. here is my code
package labBuilding;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class Building extends JPanel {
[code]....
View Replies
View Related
Feb 3, 2014
How to rotate a shape in Swing? The only thing I found was something involving this, but I have not seen something like this before:
Java Code : Graphics2D g2d = (Graphics2D)g; mh_sh_highlight_all('java');
I see this is an object reference, but what is on the right side? Does not seem like a method, as it would not equal a method nor would the parentheses be on the left. Why are parentheses there? Disregarding the above code, I would like to know how to rotate without Graphics 2d
Also, with G2D you it will not allow for setting x coords
View Replies
View Related
Feb 12, 2014
So I'm doing a project for my CS class where we have to create a snowman doing something. My picture is of Vince Young in the 2005 Rose Bowl. I'm trying to make the actual video clip from Youtube (do I need to download it? If so I can do that) appear on the scoreboard, but how.
import java.awt.*;
import java.awt.event.*;
import java.awt.Font.*;
class snowBackground
{
public static void drawField(Graphics g, Color field)
[code]....
There are 3 other files that make the actual Snowmen.Also, would I need to download the mp3 sound file seperately and play that, or will inserting the video do both?
View Replies
View Related
Aug 13, 2014
I used to think that it is simplly a tool to use to change colors and draw to specific container(ie JFrame, JPanel). However, I've been studying buffering (triple, double, flipping...etc) and how it works for 3 days now, and my confusion has only increased. for instance, why when we need to draw to the buffer(ie BufferStrategy, BufferedImage) we get its own graphics object to draw to it and then we project it to the screen? does the Graphics Object represent the drawing surface (ie the JPanel it self if we're using one to draw custom painting via JPanel#paintComponent(Graphics g)) ? so generally speaking if we are using a JPanel and we say bufferedImage#createGraphics and use that graphics object to draw to, we would not be drawing to the JPanel but to the BufferedImage correct?
View Replies
View Related
Aug 13, 2014
what is A Graphics object for a while now, I used to think that it is simply a tool to use to change colors and draw to specific container(ie JFrame, JPanel). However, I've been studying buffering(triple, double, flipping...etc) and how it works for 3 days now, and my confusion has only increased. for instance, why when we need to draw to the buffer(ie BufferStrategy, BufferedImage) we get its own graphics object to draw to it and then we project it to the screen? does the Graphics Object represent the drawing surface (ie the JPanel it self if we're using one to draw custom painting via JPanel# paint Component(Graphics g) and so when we're getting the graphics object of a buffer, do we actually get its drawing surface to paint on? so generally speaking if we if we are using a JPanel and we say BufferedImage#createGraphics and use that graphics object to draw to, we would not be drawing to the JPanel but to the BufferedImage correct?
View Replies
View Related
May 25, 2014
Page flipping is used in full screen games which entails drawing an imagine off screen then swap with on screen image after drawing has completed.
Is it possible to write a block of code to actually see this happen? Like use this technique on a window that is in windowed mode. Would it draw an image off somewhere by the desktop or would it have to be on the window?
View Replies
View Related
Mar 25, 2014
I have a .java file which has been built into a .class file, and now I want this to be called on the click of a button on the HTML page. Is 'applet' the answer to this ? I searched around this question on the internet prior to posting but every applet tutorial I see is related to graphics and drawing blocks etc. my java file does not have any graphics, it's just a simple stand-alone code which opens a file and displays it's contents on the terminal. Would like to now see the output on the browser.
View Replies
View Related
Mar 25, 2014
I am trying to implement a game using the ACM graphics. For the game, I am trying to make the main frame a Grid of Cells.I made a Grid class which extends GCanvas:
import acm.graphics.GCanvas;
public class Grid extends GCanvas{
private final static int WIDTH = 300;
private final static int HEIGHT = 300;
private final int DIMENSION = 5;
Cell[][] grid;
[code]....
View Replies
View Related
Jan 3, 2015
I am currently drawing graphics onto a JPanel, by overriding the standard paintComponent method.
Is it possible to call a method to draw some predefined shapes, instead of filling this method with all the stuff I need drawn, and if so, how do I do that?
View Replies
View Related
Apr 15, 2014
I'm creating a game called Mouse Trap and I'm having an issue with a graphic drawn using AWT. Basically, when the mouse collides with the cheese, I want the cheese to disappear, or call (cheese[i].hide()). However, the cheese does not appear. hide() works for all other objects that inherit from PFigure, but the cheese will not. It's created a major issue in my game, and basically the only task left to accomplish.I believe my problem lies within Cheese.java, method draw(). For example, if I replace it with an example drawing, this problem goes away!:
public void draw() {
Graphics g = panel.getGraphics();
g.setColor(Color.blue);
g.drawOval(x + width / 4 , y + 1, width / 2, height / 2);
[Code] ....
I have three classes below that most likely involve the problem, feel free to ask if you need the others.PFigure.java (This class cannot be changed as a requirement to my project)
import java.awt.*;
public abstract class PFigure implements Comparable {
protected int x, y; // Current position of the figure
protected int width, height; // Drawn (displayed) this size
protected int priority; // Can use to determine "winner"
protected Panel panel; // Panel the figure lives on
[code]....
View Replies
View Related
Mar 30, 2014
I know there are Java graphics classes, and how to use them to draw images in a window, but how do those classes interact with the screen to create the image? At the very base of it all, what is the code that is passing the computer the data to display on its screen? I'm asking because I've seen several ways to do Graphics/GUIS, a lot of them involve the Graphics class, but what is it inside all of that that that makes it work? Also, is everything else involving graphics (any other graphics libraries people write) pretty much "on top" of the Graphics class or is there something else within it more basic that is being used?
View Replies
View Related
Feb 12, 2014
So I'm doing a project for my CS class where we have to create a snowman doing something. My picture is of Vince Young in the 2005 Rose Bowl. I'm trying to make the actual video clip from Youtube (do I need to download it? If so I can do that) appear on the scoreboard. As of right now, this is my background file:
import java.awt.*;
import java.awt.event.*;
import java.awt.Font.*;
class snowBackground {
public static void drawField(Graphics g, Color field) {
Color sky = new Color(95,166,243);
[Code]...
and this is the Driver file (not sure if this is necessary):
import java.awt.*;
import java.awt.event.*;
import java.awt.Font.*;
public class SnowDriverWSB {
public static void main(String args[]) {
GfxApp gfx = new GfxApp();
gfx.setSize(1000,650);
[Code]...
There are 3 other files that make the actual Snowmen. To do this, I need VERY basic steps, as I'm extremely confused and new to Java. Also, would I need to download the mp3 sound file seperately and play that, or will inserting the video do both?
View Replies
View Related
Apr 28, 2015
I want to know know to copy a rectangle on my jframe and paste it in another location on the same jframe.
View Replies
View Related
Oct 5, 2014
Basically I am making a paddleball game, like i'm sure everyone does in learning Java. I'm supposed to use different classes for each component, i.e. one for the ball, one for the paddle, and one for the display, then finally one as a 'controller' to implement mouselistener and stuff.
However, I can't quite grasp how to implement the paintComponent method. I know I can only have it in one class extended from JPanel, and I have the syntax for creating an object which I understand is something like this:
public void paintComponent(Graphics g){ //this is the rectangle my game will be played on,
super.paintComponent(g); //a gray background to define boundaries for the ball
g.setColor(Color.GRAY);
g.drawRect(0, 0, Frame.getHeight(), Frame.getWidth());
However what I don't understand is, how do I then pass this graphics object to the ball and paddle to let them draw themselves? I found something that described it like this here
class GamePanel extends JPanel {
Entity e=new Entity;
@Override
protected paintComponent(Graphics g) {
super.paintComponent(g);
[Code] .....
What I don't get is, if I use this, where would I put the drawRect and stuff to make the other shapes I need? in their class, under the entity.Draw(g) method? or in the display class where it calls the graphic object in the first place?
Last, how can I have my controller class refresh the displays of each of these with the timer I have implemented? Is there a simple way to call one refresh command and have it refresh the drawing of both the paddle and ball simultaneously, or would I need to call a separate refresh command for each object?
View Replies
View Related
Apr 8, 2014
I use Canvas, Graphics & JFrame, but not JPanel, how do I add an Image? To see my code: [Java] package pack.script.game; import java.awt. BorderLayout; import java.awt.Canv - Pastebin.com
What do I need to add, or where can I find information on how to add an image? Can I add an image using Graphics? I will import any utils, swings or awts needed. But I don't want to change my code too much.
View Replies
View Related
Jul 15, 2014
I'm going to make tiles for my RPG game, instead of drawing each shape of the tile, I will just draw the full tile in a spritesheet. I will create a sprite sheet of shapes that I want to clip somehow or use to cut the original full image into the shape I want. How can I, take a Buffered Image, cut it's shape and perhaps add something, giving me a Buffered Image of a cut tile with possibly added features that I can then draw with Graphics?
View Replies
View Related