Questions tagged [java-canvas]

A Canvas component represents a blank rectangular area of the screen onto which the application can draw or from which the application can trap input events from the user.

A Canvas component represents a blank rectangular area of the screen onto which the application can draw or from which the application can trap input events from the user.

118 questions
2
votes
2 answers

How to check if Point is on a diagonal line?

I have a canvas with lines. On click I want to check if the click was on my line to highlight it. I also have some rectangles where it's easy by just using start and end point of the square. But for a diagonal line I cannot use the same technique as…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
2
votes
1 answer

Java swt delete/undo for paint commad

Consider - public class MainCanvas extends Canvas {...} And Display display = new Display(); display = new Display(); myShell = new Shell(display); myCanvas = new MainCanvas(myShell, SWT.NO); GC myGC = new GC(myShell); myGC.fillOval(10,20,30,40) ;…
URL87
  • 10,667
  • 35
  • 107
  • 174
2
votes
1 answer

Using a canvas object in a thread to do simple animations - Java

I have an applet that, as written now, should be drawing and bouncing a ball around the top (drawingpanel in the code) after the "Run" button is pressed. Looking at other examples online and using code from a different program that did not use…
zakparks31191
  • 919
  • 2
  • 21
  • 42
1
vote
1 answer

How can I possibly draw a JavaFX video in a JFrame's canvas?

Basically, I want to "add" a JavaFX video to a Java Swing JFrame, but I also want to draw in that canvas, to do other things while playing the video. I use this code to play the video: public class ExtVideoPlayer extends Application implements…
1
vote
3 answers

JavaFX deleting last drawn object from canvas

Introduction: I have created a canvas and my objective is creating circles at the place you click on the canvas. But I also want to be able to delete the circles I have drawn or at least the last drawn one. Redrawing at the same place where the…
Vsky
  • 59
  • 1
  • 9
1
vote
1 answer

Why won't my render method display anything?

I'm making a game for my APCS class in Java. It uses Algebra and Math, but that's not the problem: I have a State class instead of a State Enum because for some reason, Enum doesn't work. public class State { private int option; public int…
user6762036
1
vote
0 answers

How to make image created used in larger canvas

For my code that I am working on. I have made a small design. I was able to, using the code that I had to make the design into an image. But when I try to reuse the image, nothing happens with my code. How do I make it so that my code will take the…
J. Listn
  • 11
  • 2
1
vote
2 answers

Concurrent methods via multithreading

I am trying to make a game in Java and this is my first time dealing with multithreading (well, asides from playing music concurrently via the Clip class.) I have a Canvas class which extends JPanel, but within the Canvas class I also have a…
ADC2000
  • 63
  • 7
1
vote
1 answer

How do you draw a String or Rectangle according to the screens width and Height with a Canvas in Java

I want to know How could I draw a String or Rectangle (the JFrame is in a full screen completely) Heres what in my Main.java class: public static int WIDTH, HEIGHT; private Window window; ... public Main() { window = new Window("2D Shooter",…
1
vote
1 answer

JavaFX and fast update of Canvas

I am trying to create a custom Canvas widget under JavaFX, which gathers information from a lot of unrelated working threads. The "update" events might come in various rates, sometimes too fast and sometimes none at all, meaning that there is a need…
Panayotis
  • 1,792
  • 23
  • 32
1
vote
2 answers

What can I do to reduce lag from large amounts of objects in my game?

To clarify, I know why my game is running slow. I have a lot of different objects in the current area and it has to tick and render all of those objects. I just don't know how to fix the problem without just making less objects. The answer I am…
user4196492
1
vote
1 answer

Mouse click coordinates are always 0

As you can see I added the a mouse listener to the game. import java.awt.Graphics; import java.awt.image.BufferStrategy; public class Game implements Runnable { private Display display; public int width, height; public String title; private…
noobycoder
  • 63
  • 2
  • 13
1
vote
1 answer

Adding image to canvas window

I'm trying to add a .png picture to my canvas window, however I'm having some problems. Let's say that im adding different types of objects to my window. There is class Pacman, which extends class GameObject. However, my pacman is currently a…
Rok Dolinar
  • 976
  • 3
  • 13
  • 29
1
vote
0 answers

BufferStrategy Causing Flickering?

I am new to Java Game Programming and I am having trouble with my game. I am making this for my class in school and for fun so I transfer my code from my computer at school and my computer at home. Recently, when I run my program at home, the…
Patrick
  • 11
  • 2
1
vote
2 answers

Draw a border around shapes in the canvas with JavaFx

I have drawn a straight line in a canvas and filled with a solid color. I want to border this straight line with a black colored border.
Shantanu Chandra
  • 87
  • 1
  • 1
  • 6