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
1
vote
1 answer

Load a canvas from a main class - Java

I have a MyCanvas class that extends JComponent. On this canvas I have drawn a couple of things and has its own main method. public static void main(String args[]) { JFrame mainFrame = new JFrame("Graphics demo"); …
marcoamorales
  • 625
  • 2
  • 10
  • 13
1
vote
1 answer

Java: Removing Runnable Canvas Component

I have been working on this game for a while now, which actually has different game modes built into it. At first, I have been handling the execution by just exiting the program after the user has lost, or wants to exit. Since not only is it…
CoderMusgrove
  • 604
  • 8
  • 18
1
vote
1 answer

Capture Control + Space keyboard event

I want leftCanvas to capture all keyboard events, including Control + Space. How can I achieve that since it is triggering the native InputMethod? class leftCanvas extends Canvas implements KeyListener { leftCanvas() { …
chaoys
  • 21
  • 3
1
vote
3 answers

How can I draw a semi transparent coloured mask over an already drawn to SWT canvas?

so I'd like to draw a coloured (red) area over the top of an existing canvas drawing, like a red tinted lens being placed over it, so the original image is still visible underneath. The problem is that I am extending a canvas that draws it's own…
Link19
  • 586
  • 1
  • 18
  • 47
1
vote
2 answers

KeyListener doesn't work

I'm programing a game Bomberman-like, and I have a problem with my KeyListener. The thing is, when the game is running, the KeyListener doesn't respond, but when it's not running, it does what I tell him to. Here is my code public class direction…
1
vote
2 answers

How to check if point is inside the rectangle around a diagonal line?

First of all: I know I can calc the distance from a point to a line to check if the point was on the line. This is what I do for detecting clicks (with an offset) on a line. But before that, I want to apply a general check around the diagonal…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
1
vote
1 answer

Line clipping algorithm for lines and rectangles in inverted coordinate system?

I'm trying to make use of the following algorithm: http://www.skytopia.com/project/articles/compsci/clipping.html But for my special case, I don't have a line that crosses the rectangle 2 times, but it starts in the center of the rectangle and only…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
1
vote
1 answer

Why this Java code by clicking on button NUM0-9 doesn't print out the character?

Why this Java code by clicking on button NUM0-9 doesn't print out the character? Code: switch(this.getGameAction(keyCode)){ case Canvas.KEY_NUM2: System.out.println('A'); break; case…
1
vote
1 answer

Mouse events in SWT

I defined a Node class extends Canvas class and handle the mouse event. public class Node extends Canvas { String name; public String getName() { return name; } public Node(Composite parent, int style, String name) { super(parent, style); …
Hieu Nguyen
  • 382
  • 2
  • 15
1
vote
1 answer

Hit detection for GWT canvas - which strategy for drawings?

I'm creating some kind of drawings/flowchart/UML-diagram like tool with GWT Canvas (Java). For hit-detection of my drawings I could imagine 3 different strategies, but I do not know which would work best for my goal. Just keep track of all Shape…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
1
vote
1 answer

sub Window panel into canvas scene with javafx

With other engineer, we create a software (www.openmole.org) to create and run complex workflow on a computer grid. With the gui, you can create and modify some complex drag and drop workflow like this : You can also see a video here :…
reyman64
  • 523
  • 4
  • 34
  • 73
1
vote
1 answer

Why does Canvas as contentPane not paint opaque components that are added to the JFrame glasspane

Okay I have a Canvas (I am using this because it can implement BufferedStrategy). I add my Canvas to my JFrame contentPane and than add HUDPanel ( which is a JPanel consisting of 2 other JPanels - with JProgressBars and JLabels - to show health and…
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
1
vote
0 answers

Java Canvas Zooming in Flickering

I'm working on a project that requires me to be able to zoom in and out on a Canvas. I'm using the method: setSize(new Dimension(WIDTH * scale, HEIGHT * scale)); and from there just modifying the scale variable. This works, except most of the time…
Treesin
  • 73
  • 1
  • 7
1
vote
1 answer

how to get the image of a Swing widget?

Possible Duplicate: Java Swing : Obtain Image of JFrame I am working on a little drag-and-drop Java GUI builder. It works so far, but the widgets I'm dragging and dropping are just rectangles I'm dynamically drawing on a canvas. If I have a…
user550738
0
votes
1 answer

Java AWT Canvas - Multiple colors in one window

I was trying to make rectangles that have multiple colors with Java AWT, but whenever I use the setForeground(color) method, it changes the color of all objects in the window. Is there a way to change the color without that happening? The code that…
new here
  • 3
  • 2