paint

Java: Moving second rectangle using different keys with KeyListener

落爺英雄遲暮 提交于 2019-12-12 04:26:58
问题 I am making a little program where two rectangles drive around a race car track. When I run the program everything goes as planned and I can move the black rectangle around the track using the arrow keys. If I want to move the red rectangle using W,A,S,D, what should I do? import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; public class first extends JLabel implements ActionListener, KeyListener { Timer t = new Timer(5, this); double x = 0, y = 25, velx =

How to animate jLabel from one side to another side of Jframe using netbeans

巧了我就是萌 提交于 2019-12-12 04:16:06
问题 I want to create a small application.In my application I have jLabel1 and Jbutton1 . I want to animate jLabel1 from one side to another side using jButton click. I don't know how to call it in the jButton1ActionPerformed to create the animation of jLabel1 . I have done a paint application code which is giving as following. Here is my code: public void paint(Graphics g) { super.paint(g); Graphics2D g2=(Graphics2D)g; g2.drawString("ancd", x, y); try { Thread.sleep(10000); } catch (Exception e)

Using threads on animations in Java

☆樱花仙子☆ 提交于 2019-12-12 03:56:50
问题 I have created a class whit two shapes namely two ovals. Here I draw them. import ...; public class Drawings extends JPanel{ public double degrees = 0; public void paintComponent(Graphics g){ super.paintComponent(g); int xcen = getWidth() / 2; int ycen = getHeight()/ 2; int radius = 10; degrees++; double radians = Math.toRadians(degrees); int posx = (int)(100.getDistance() * Math.cos(radians)); int posy = (int)(100.getDistance() * Math.sin(radians)); g.setColor(Color.BLUE); g.FillOval(xcen +

draw square 3x3 cm in Android

℡╲_俬逩灬. 提交于 2019-12-12 03:43:55
问题 I need to draw an exact square 3x3 cm on the screen, you need the exact dimensions in any type of screen as design work. The result in a Samsung Ace is 2.8 cm, the result is not exact. Java... DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); float ld = 30 * metrics.densityDpi * (metrics.density/25.4f); bitmap = Bitmap.createBitmap((int) ld, (int) ld, Bitmap.Config.ARGB_8888); canvas = new Canvas(bitmap); paint = new Paint(); paint

Keeping graphics unaltered when TabPage changes

人走茶凉 提交于 2019-12-12 03:33:24
问题 I have a form that displays a set of graphics using a Paint event on a Panel that is docked inside a particular TabPage of a TabControl . The problem is the following: When the user switches to a different TabPage and then decides to go back to the TabPage where the graphics were originally displayed, those graphics are invalidated by default so the Panel appears blank. I would like those graphics to stay unaltered and totally independent from the user's action when switching between

java JFrame scaled UI display with virtual drawing space

情到浓时终转凉″ 提交于 2019-12-12 02:28:43
问题 i have an application that has graphics which are thought to be displayed at 1024x768. I want to make the application flexible in size without rewriting all drawing code, position calculation etc.. To achieve that my attempt was overriding the paint method of the JFrame container in the following way: @Override public void paint(Graphics g) { BufferedImage img = new BufferedImage(this.desiredWidth, this.desiredHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D gi = (Graphics2D) img.getGraphics(

How to repaint over images in Java game

好久不见. 提交于 2019-12-12 01:55:37
问题 Hello everyone I am having trouble with painting over coins that the user intersects with. What I want this code to do is when the user sprite intersects with any of the ten coin images it paints over the coin so that it no longer appears on the screen (also need to add in some kind of counter so that when the user collects all ten coins it will stop the thread, and say "You Win!"). My question is how would I go about doing this because I have tried using repaint() in the if statements, and

Android canvas / Paint - Changing brush size of Android canvas brush

无人久伴 提交于 2019-12-12 01:02:38
问题 In my Draw Activity class when an item from the spinner is selected, my brush size changes. However it also changes the size of the previously drawed path. I tried to create a new paint object for every selection from the spinner, but still doesn't work. Here tv is an instance of the eventTouchView class which has the draw method. Not sure what is wrong: In my Draw Activity class : @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto

Clear previously drawn string over an image

北城余情 提交于 2019-12-12 00:27:27
问题 I am wondering how I can clear a previously drawn string before drawing a new one over an image, if I do not clear the strings overlap. I have tried graphics#drawRect and overriding paintComponent(Graphics), still no eval. Here is my code: paintComponent(Graphics) public class SplashScreen extends JLabel { private static final long serialVersionUID = 5515310205953670741L; private static final String ROOT = "./assets/img/"; private static final SplashScreen INSTANCE = new SplashScreen( get(

How to delete an JPanel Object?

随声附和 提交于 2019-12-12 00:24:54
问题 Im on to create a little "game", something like an 2d AirForce Shooter. So, i have a problem with deleting unused enemys. An Enemy is an simple JPanel, which is saved in the main logic as an array List. public static ArrayList<Enemy> enemys = new ArrayList<Enemy>(); The Enemy run logic does the following: while(!destroyed){ if(Game.running){ x--; if(getBounds().intersects(Field.player.getBounding())){ Player.death = true; } if(x < 0){ Field.deleteEnemy(this); } setBounds((int) x, (int) y, 100