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
0
votes
0 answers

java sudoku board placing numbers

I have been trying to draw a board using java but every time it runs I get an error and the code stops running. It's the very last line of code causing the problem but i am unable to see why. protected void onDraw(Canvas canvas) { //Draw the…
0
votes
0 answers

Java Canvas err focus or action listener in second window

I create 2 Frames: in 1st - I make a Button which move me to 2nd Frame created by class which extends after Canvas and after the move from 1st Frame to 2nd I lose the action listener or focus 1st window here : public class Credits extends JFrame…
PDS
  • 562
  • 3
  • 13
  • 27
0
votes
3 answers

addMouseListener to the canvas in Rubber Banding

I'm trying to solve Rubber Banding problem of Stanford CS106A. As per Java Doc on addMouseListener() one needs a listener to use it. As per the solution to this problem no listener is used but when I use it without any listener I get the following…
0
votes
1 answer

canvas is null when using "canvas = Holder.lockCanvas();", Android Java

I am just now getting back into android java, and was making a quick game by following the template of one I had made before (successfully). When trying to define my "canvas" the Holder.lockCanvas(); is returning a "null" value (I think the command…
Colin
  • 491
  • 1
  • 5
  • 13
0
votes
1 answer

How to represent each element off array as a line

This application sorts one array . Want to represent the current item changed by a line equal value. I do not know where I would put the paint method (or draw) to draw my current item for the method "run ()" can not. class sortareBubbleSort extends…
0
votes
1 answer

Clear and reuse a Canvas, or create new object?

My setup: I have a GWT Canvas that displays some grafics that rely on heavy algorithms. The objects are dragable, and therefore on drag I save everything beside the dragged object on a temporary canvas and reuse this as an image behind the dragging…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
0
votes
1 answer

Clicking out of a Canvas

I am making a Pong program, and I have a start button that begins to draw everything, and quite literally to get the ball rolling (you're welcome for the pun). Anyways, when I hit the start button, a Key Listener to move the paddles won't work…
Chris
  • 3
  • 3
0
votes
1 answer

How to truncate a line between 2 points?

I want to draw a line on a canvas. Therefore I use two clicks from the user to define start point S and end point E. ctx.moveTo(sx, sy); ctx.lineTo(ex, ey); I further want to substract a static offset on both sides of the line, eg static int offset…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
0
votes
1 answer

How to construct my graphic structure in Java using Swing?

I was wondering if you could help me out with the structure of my program. I'm making a game with Java and I have 2 classes. 1 class is a graphics class that extends JFrame with a paint method: Graphics Class paint() and calls various objects that…
andor kesselman
  • 1,089
  • 2
  • 15
  • 26
0
votes
1 answer

Draw array to canvas

I'm trying to draw objects onto a canvas from an array, but the thing is, I have no clue how to? This must include the position and sizes of the shapes, and there will be more than one type of shape. The code I've got so far(It's inefficient/bad…
YepNepDep
  • 67
  • 1
  • 1
  • 8
0
votes
2 answers

Importing A Sprite from a sprite sheet

Well i have been watching a couple of videos of youtube on how take sprites from a spritesheet (8x8) and i really liked the tutorial by DesignsByZepher. However the method he uses results in him importing a sorite sheet and then changing the colors…
Exikle
  • 1,155
  • 2
  • 18
  • 42
0
votes
1 answer

Java Challenge on Creating a Canvas

This is probably an elementary question. However, I have completed reading the 9th Chapter of Java Programming for the Absolute Beginner and have approached the Challenges section. I cannot quite understand the question. The question asks: "Create…
user1604490
0
votes
1 answer

Canvas Appears only after resizing JFrame

I have the following JPanel: import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.JPanel; public class Watcher extends JPanel { private static final long serialVersionUID = 1L; final CardLoader canvas; private…
user547654
0
votes
2 answers

Selective menu detection within a Composite

I want to add some objects into an Composite object. Objects can have different shapes (rectangle, circle, ellipse or even weird shape (represented by a polygon). So I defined classes like this: public class Circle extends Canvas { } public class…
Hieu Nguyen
  • 382
  • 2
  • 15
0
votes
1 answer

How to add EventListener to a gwt canvas drawing?

If I draw a shape on a GWT canvas (rectangle, circle, whatever), how can I add a EventListener like MouseClick, MouseOver etc to that drawing? Canvas canvas = Canvas.createIfSupported(); Context2d context = canvas.getContext2d(); …
membersound
  • 81,582
  • 193
  • 585
  • 1,120