java-canvas

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

安稳与你 提交于 2019-12-07 12:19:14
问题 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 should, but nothing shows up. Looking at examples online I didn't see why my drawing/painting code wasn't working as intended. Here's what I have, issues are probably focused about halfway down where the Ball object is. I posted most of the program

Mouse click coordinates are always 0

北城余情 提交于 2019-12-07 03:55:30
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 boolean running = false; private Thread thread; private BufferStrategy bs; private Graphics g; // States public static State gameState; // Input private InputManager inputManager; private MouseHandler mouseHandler; public Game(String title, int width, int height) { this.width = width; this.height = height; this.title = title; inputManager = new InputManager

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

狂风中的少年 提交于 2019-12-06 03:22:20
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 should, but nothing shows up. Looking at examples online I didn't see why my drawing/painting code wasn't working as intended. Here's what I have, issues are probably focused about halfway down where the Ball object is. I posted most of the program as it does compile/run if someone will run it. import java.awt.*; import java.applet.*; import java.awt

Affine transforms for graph, not for text and labels

痞子三分冷 提交于 2019-12-05 01:10:24
问题 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 to do the drawing, so the text is not displayed horizontaly and the font size need to be extremely reduced (1.4). The program is wrote in Java (awt and JavaFX) but the problem is not language or technology relevant, so any suggestion is welcome.

Affine transforms for graph, not for text and labels

旧街凉风 提交于 2019-12-03 16:22:36
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 to do the drawing, so the text is not displayed horizontaly and the font size need to be extremely reduced (1.4). The program is wrote in Java (awt and JavaFX) but the problem is not language or technology relevant, so any suggestion is welcome. Here is the simple program: import javafx.application.Application; import javafx.geometry.VPos; import

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

半城伤御伤魂 提交于 2019-11-29 12:00:38
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 java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import javax.swing.JFrame; public class Game extends Canvas implements Runnable { private static final long serialVerisionUID

Line crosses Rectangle - how to find the cross points?

两盒软妹~` 提交于 2019-11-29 04:39:16
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 edge. How could I do this? Example The rectangle could be defined by 2 points: Pstart(1, 3) , Pend(3, 1) The center point can be computed to : P(2, 2) Now draw the line from P(2, 2) to Q(10, 2) . As I know the width of the rectangle is 2, I could tell the line to start at P(4, 2) instead of P(2, 2) . This gets more complicated when the point is not

how to embed SWT browser in swing jframe

荒凉一梦 提交于 2019-11-27 15:45:26
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? Here is a working example on GIT showing how to embed SWT in a traditional Swing JPanel: https://gist.github.com/caprica/6890618 (Text version: here ) The trick is to create a java.awt.Canvas linked to an SWT shell. This canvas can be added to any tradionnal Swing component. The SWT shell loop is managed by a separate thread. Here is a screenshot on my Windows 7 box with Java 7: 来源: https://stackoverflow.com/questions

How to make canvas with Swing?

自古美人都是妖i 提交于 2019-11-26 20:42:36
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 canvas from AWT. Is there any way to make something similar to canvas with Swing? (for example, JPanel?) I have read that using the class canvas from AWT with a GUI made with swing won't work correctly, is that true? In order to make a custom 'Canvas' in swing you usually write a subclass of a JPanel . Then, you must overwrite the protected

how to embed SWT browser in swing jframe

和自甴很熟 提交于 2019-11-26 17:15:18
问题 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? 回答1: Here is a working example on GIT showing how to embed SWT in a traditional Swing JPanel: https://gist.github.com/caprica/6890618 (Text version: here) The trick is to create a java.awt.Canvas linked to an SWT shell. This canvas can be added to any tradionnal Swing component. The SWT shell loop is managed by a