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
29
votes
4 answers

How to make canvas with Swing?

I'm trying to make a paint editor with Java in which I have a toolbar with the objects that I would like to paste in the canvas. I'm using Swing components to make the GUI, but when I looked for the way of making the canvas, I only found the class…
mccrank
18
votes
1 answer

JavaFX: how to clear the canvas

Let's say I have drawn a rectangle on my canvas and I want to clean it in order to draw some other figure / polygon / arc .... How can I do it? I have tried it in many ways but none has worked. I think this may work but I'm not…
bog
  • 1,323
  • 5
  • 22
  • 34
8
votes
1 answer

Converting a cell of Ms word table into image using java

I need to Convert each cells of ms word table into images. I have write code for getImage as well getText but I want to merge both of them and convert into single image so I just want to convert the cell into the image. Reference XWPFDocument doc =…
KuldeeP ChoudharY
  • 446
  • 1
  • 6
  • 22
8
votes
3 answers

Battleship game - ships overlapping

I'm writing a simple battleship game in Java using the ACM library. After the game starts, ships are supposed to be put on the canvas at random locations but the problem is that the ships might cover each other and this is not allowed in the game.…
Tsiskreli
  • 103
  • 1
  • 11
8
votes
3 answers

java.awt.image.DataBufferByte cannot be cast to java.awt.image.DataBufferInt

I have some errors atm while im coding with JAVA, I have been trying to fix this for along time, also trying to find oterh ppl who have same problem and fixed it but nothing work... Well.. here is the code package ca.vanzeben.game; import…
filleszq
  • 141
  • 1
  • 1
  • 8
7
votes
3 answers

Line crosses Rectangle - how to find the cross points?

I'm drawing a rectangle onto a canvas and a line from the center of the rectangle to some random point in the coordinate space. Now, I want to truncate the line by the length that is inside the rectangle so that the line starts at the rectangle…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
6
votes
1 answer

how to embed SWT browser in swing jframe

I want to embed my SWT browser in swing jframe. I try sample, but it need to resize the window to load browser window. what can I do to repaint the canvas, with out resizing?
user3813088
  • 85
  • 1
  • 2
  • 7
5
votes
1 answer

Blurry image after canvas rotate, only in Android 6

I've got a custom view with the following code: private final Drawable outerGauge; private final Drawable innerGauge; private float rotateX; private float rotateY; private int rotation = 0; { outerGauge =…
Daniël van den Berg
  • 2,197
  • 1
  • 20
  • 45
5
votes
2 answers

Drawing a bold line with drawLine() when extending Canvas

Given the following : public class NavigationCanvas extends Canvas implements MouseListener,MouseMotionListener,KeyListener { public void paint(Graphics g) { // some code // more // ... …
JAN
  • 21,236
  • 66
  • 181
  • 318
5
votes
2 answers

Inheritance vs Composition for canvas shapes model?

For the following model, would you prefer inheritance or composition: I want to draw objects on a canvas that each represent a data object think of it like a state machine diagram: Ellipses represent States, Lines represent connections/transitions…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
4
votes
1 answer

Java Canvas or JPanel

When making a graphics canvas in Java, which would be better to extend? Should you extend JPanel or Canvas? Are there any performance considerations?
abc123
  • 41
  • 1
  • 2
4
votes
2 answers

Why would you use JNI to paint on AWT's Canvas?

I'm pretty new to the JNI, and I stumbled across this while looking into the JNI: Not only can native code interface with Java, it can also draw on a Java Canvas, which is possible with the Java AWT Native Interface Is there a specific reason why…
Vince
  • 14,470
  • 7
  • 39
  • 84
4
votes
2 answers

Java clears screen when calling paint method - how to avoid that?

I'm trying to draw two lines in a Canvas in Java, calling two methods separately, but when I draw the second line, the first one disapears (Java clears the screen). How can I avoid that? I want to see the two lines. I've seen paint tutorials (how to…
vicaba
  • 2,836
  • 1
  • 27
  • 45
4
votes
2 answers

Affine transforms for graph, not for text and labels

This post is a suite to an answer I made to question: Transforming a shape Here is the image I want: Here is the image a simple program produces, as you can see the text is rotated. I want horizontal text: The canvas is scaled, translated, rotated…
Aubin
  • 14,617
  • 9
  • 61
  • 84
4
votes
2 answers

Can a canvas handle double numbers as points?

Is a canvas capable of handling double numbers like 0.5, 10.4 etc? Or would this be rounded internally to an integer (if yes, how?). I'm asking because I think that elements on a canvas are represented as pixels. And as a pixel is always size 1x1…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
1
2 3 4 5 6 7 8