paintcomponent

How can I rotate an onscreen component in Java?

本秂侑毒 提交于 2021-02-19 06:48:25
问题 import javax.swing.*; import java.awt.*; public class JFrameAnimationTest extends JFrame { public static void main(String[] args) throws Exception{ AnimationPanel animation = new AnimationPanel(); JFrameAnimationTest frame = new JFrameAnimationTest(); frame.setSize(600, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(animation); frame.setVisible(true); for(int i = 0; i < 100; i++) { animation.incX(1); //animation.incY(1); animation

Java how does graphics abstract drawline method really works?

旧时模样 提交于 2021-02-17 02:00:35
问题 I read source code of Java Graphics abstract class, I am curious how does this abstract void drawline method draws lines in JComponent's paint(Graphics g) and paintComponent(Graphics g). I know that abstract methods have no method body. I couldn't find any relevant examples with Google. If possible, can you provide me a link to source code of this method. 回答1: Mad Programmer is right, all of java's graphics and graphics2d methods is directed with native codes. If you're curious about these

Properly drawing over an image

空扰寡人 提交于 2021-02-04 19:49:08
问题 I'm creating a small image editor and right now i'm trying to give the user the chance of drawing over the image by dragging the mouse (like pencil tool in MS Paint does). I'm having some difficulties since, when i move the cursor too fast, the application can't draw all the pixels which should be colored, just a little number is correctly colored. I tried two solutions to add the colored pixels: at first i created a list where i stored all the points added when mouseDragged was called. After

Reference of graphics 2d object doesn't work in orphan Thread

回眸只為那壹抹淺笑 提交于 2021-01-28 06:23:51
问题 I am trying to design a simple game using Graphics2D in a JPanel. I am able to draw normal objects by overriding the paintComponent() method. But when I reference the Graphics2D object inside a orphan Thread, it does not work. Where am I going wrong? public void paintComponent(Graphics g) { super.paintComponent(g); g2d = (Graphics2D) g; g2d.drawString("sample",60,100); //Works fine if(<Certain Condition>){ new Thread(new Runnable(){ //Some Code Here public void run() { try{ g2d.drawString(

Java Game Development: Graphics

こ雲淡風輕ζ 提交于 2021-01-21 10:03:13
问题 i'm new here. Hope you will be able to help. Problem: Problem with displaying Animation on JFrame. Seems I miss/don't understand enough how Java's graphics works. Global idea: Lets say I want make a game/movie/clip. For this I need this (not)simple animation get working. An example for this question: I got class Screen, which has the screen stuff- Declaration of the JFrame, setting up its configuration(size, close operation, etc) and then creating the objects of class Box, to be showed on the

confused with java graphics paint

倾然丶 夕夏残阳落幕 提交于 2020-12-27 06:23:20
问题 i am very bigginer to java .i trying to draw a line in a jpanel (using netbean ide)..i read some articles .but problem is it draw thais line without calling it .i want to draw line by a button click ..and not on main form but in a panel ..how can i modify this code this is my code /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package graphic; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; /** * * @author

Time Delay using Thread.sleep() for paintComponent(Graphics g) not working as expected

情到浓时终转凉″ 提交于 2020-11-29 02:11:12
问题 I am making an Animated ProgressBar, in which i used multiple fillRect() method of class javax.swing.Graphics . To put a delay after each rectangle is painted, I am using Thread.sleep(500) method for making a delay, (Suggested by many Forums, for making a delay). The Problem is, instead of making a delay of 0.5sec after each Rectangle box is displayed, it takes the whole delay required by all the rectangles, in the start, and then displays the final image, thats the Progress Bar. Question 1

Time Delay using Thread.sleep() for paintComponent(Graphics g) not working as expected

故事扮演 提交于 2020-11-29 02:04:17
问题 I am making an Animated ProgressBar, in which i used multiple fillRect() method of class javax.swing.Graphics . To put a delay after each rectangle is painted, I am using Thread.sleep(500) method for making a delay, (Suggested by many Forums, for making a delay). The Problem is, instead of making a delay of 0.5sec after each Rectangle box is displayed, it takes the whole delay required by all the rectangles, in the start, and then displays the final image, thats the Progress Bar. Question 1

Time Delay using Thread.sleep() for paintComponent(Graphics g) not working as expected

这一生的挚爱 提交于 2020-11-29 02:02:03
问题 I am making an Animated ProgressBar, in which i used multiple fillRect() method of class javax.swing.Graphics . To put a delay after each rectangle is painted, I am using Thread.sleep(500) method for making a delay, (Suggested by many Forums, for making a delay). The Problem is, instead of making a delay of 0.5sec after each Rectangle box is displayed, it takes the whole delay required by all the rectangles, in the start, and then displays the final image, thats the Progress Bar. Question 1

How can I make a polygon object in Java pulsate (like the chalice in the Atari game “Adventure”)

无人久伴 提交于 2020-06-26 14:13:51
问题 This is what I have in my paintComponent (most other things omitted, just the stuff that pertains to an Item object called chalice with a polygon field, the explicit parameters of the if statement are not important for this question) Currently, it shows up as solid white because I set the color to all 255, but I want to make it gradually transition to different colors smoothly, not strobing, more like pulsating but I don't really know what that is called. I was thinking about replacing the