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
3
votes
1 answer

Drawing a moving ball with Canvas using JavaFX

I am programming a simple game in which the ball should bounce when it hits the wall. I used JavaFX for the GUI, Canvas and GraphicsContext for drawing. My code for drawing the Ball: public void moving(){ gc.setFill(Color.BLACK); …
Tuấn Phạm
  • 688
  • 6
  • 20
3
votes
1 answer

Java Canvas - Rectangle2D Scales when Moving

I am drawing a series of rectangles on a Canvas. The rectangles are supposed to move on an angle. For some reason, when they move, they scale up: xPos += xSpeed; yPos += ySpeed; updateBounds(xPos, yPos, width, height); My UpdateBounds…
user3011902
3
votes
1 answer

Java "zooming" Canvas?

I have a java.awt.canvas object and I draw stuff with the Graphics2D (which I get from the bufferStrategy) and I'd like to "zoom" in and out. So if I zoom in (scaling it up by a factor of 1) such that a line I draw from (0,0) to (10,10) Would be in…
Petter Thowsen
  • 1,697
  • 1
  • 19
  • 24
3
votes
1 answer

Java drag and drop custom cursor

I have defined a custom canvas style component, using JPanel, that will support the dragging of objects onto the canvas. What I can't seem to figure out is how to change the drag and drop (DnD) cursor to a custom one, using a TransferHandler. For…
shinds
  • 756
  • 7
  • 13
3
votes
3 answers

Canvas object is not displaying, but location is updating correctly in Java Applet

My basic bouncing ball Applet should have a ball moving around according to the values in loc variable, but nothing shows up. Printing out loc shows that the numbers/math behind moving it around and bouncing off boundaries is indeed working as it…
zakparks31191
  • 919
  • 2
  • 21
  • 42
3
votes
2 answers

How can I achieve this in Java?

I'm trying to get the XY coordinates of the pixels in a string in Java, but I can't figure out how. I'll try to explain more clearly. Let's say I want to do something like this: paint.setTextSize(40); canvas.drawText("hello", 100, 100, paint); But…
Suffick
  • 641
  • 1
  • 6
  • 15
2
votes
1 answer

Java bufferstrategy, graphics error: : Buffers have not been created

So I have been making a small game lately and I have a weird problem. Altough the game runs just perfectly when I don't use game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); but the stop() method to close it I get an error and I don't…
2
votes
0 answers

JavaFX: Mapping pixels on screen to a 2D matrix

I'm making an animation in which I need to keep track of explored/unexplored pixels on the screen.Initially the screen is black colored,then as the node(a circle) moves(over defined path) the explored pixels are set to white.For doing this…
Nikhil1895
  • 21
  • 2
2
votes
3 answers

How to add context menu to a canvas element?

Problem : It is not possible to simply 'add' ContextMenu to a Canvas or Pane element via addContextMenu(menu), which works only with javafx.scene.control elements (and neither Canvas or Panel extends this class). Question : Is there any 'clean' way…
baka1408
  • 433
  • 4
  • 21
2
votes
0 answers

Add scrollable Canvas to JFrame

I would like to add a scrollable Canvas to a JFrame, some research on the web led me to a solution with a scrollable Canvas as a Java Applet. I tried to apply this onto a JFrame, which resulted in: import java.awt.BorderLayout; import…
Zi1mann
  • 334
  • 1
  • 2
  • 15
2
votes
1 answer

Java Canvas write animation text

I'm making a fighting game and before the game start, I want to add an introduction story, i want the story to show 1 by 1 letter, here's my code : public class Story { public int index; public int delay; public int x; public int y; public…
Shasapo
  • 183
  • 2
  • 15
2
votes
1 answer

How to draw efficiently arrows on a canvas with JavaFX 8?

I am looking for a very simple and efficient way to draw arrows in JavaFX 8, what is the best way to achieve that (performance-wise if let's say I'm willing to draw hundreds or thousands of them)? I've heard using a Canvas to draw on it is quite…
Natalie Perret
  • 8,013
  • 12
  • 66
  • 129
2
votes
1 answer

Graphics G in another method

I have a canvas and I want to draw a rectangle based on a JButton click. So in other words private void jb_drawActionPerformed(ActionEvent evt) { // draw a rectangle method } Basically, how do I…
Killerpixler
  • 4,200
  • 11
  • 42
  • 82
2
votes
1 answer

Resize the video using vlcj

I am creating a desktop application that plays a video using vlcj. The video plays fine when added with the Jframe. But i have to play two more videos in the same frame.So i added the video player to canvas and then canvas to Jframe.The video plays…
santhosh
  • 1,191
  • 4
  • 14
  • 28
2
votes
1 answer

How to design many-to-many relationships on deletion?

I'm creating a canvas drawing with 2 objects: Rectangles, and Lines connecting the Rectangles. Each Line should be aware of the 2 Rectangles it connects. Every Rectangle can have multiple lines that connect it to other Rectangles. class Rectangle { …
membersound
  • 81,582
  • 193
  • 585
  • 1,120