paint

Regarding Android Paint drawing color

一世执手 提交于 2019-11-28 11:27:41
DrawView.java public class DrawView extends View implements OnTouchListener { private Canvas mCanvas; private Path mPath; public Paint mPaint; ArrayList<Path> paths = new ArrayList<Path>(); private ArrayList<Path> undonePaths = new ArrayList<Path>(); private MaskFilter mEmboss; private MaskFilter mBlur; private Bitmap im; public DrawView(Context context) { super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); paths.clear(); undonePaths.clear(); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(Color.BLUE);

How do I stop my paint method form repeating twice?

江枫思渺然 提交于 2019-11-28 10:22:11
问题 Here is the code for a dice game that I am working on that outputs the results to a window. The paint method repeats twice, which is not good for me because I want the dice to roll once and then move on to the next frame. Please someone help me with this problem. Thank you in advance. import java.awt.*; import java.util.Random; import javax.swing.*; public class Dice extends JApplet { public static int pause(int n) { try { Thread.sleep(n); } catch(InterruptedException e) { } return n; }

Drawing line less than one pixel thick requires anti-aliasing in Android 4.2

僤鯓⒐⒋嵵緔 提交于 2019-11-28 10:04:32
问题 I'm trying to draw a very thin line (less than one pixel thick) in android. I'm using Paint blackThin = new Paint(); blackThin.setStrokeWidth(0.1f); blackThin.setColor(Color.BLACK); to initialize the paint object. This works fine in Android 2.2, but when I try it in 4.2 (also 4.1, I think - I tested that one briefly - I haven't tested any other versions other that 2.2, 4.1.2 and 4.2) the lines won't show up when I draw them. To make them show up in 4.2, it seems like I have to set the anti

Creating a draw rectangle (filled with black color) function in Java for a grid

北城以北 提交于 2019-11-28 09:18:00
I have created a grid in my program. Below is the code used to create the grid. import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JFrame; class Grid extends JComponent { public void paint(Graphics g) { g.drawRect (10, 10, 800, 500); for (int i = 10; i <= 800; i+= 10) g.drawLine (i, 10, i, 510); for (int i = 10; i <= 500; i+= 10) g.drawLine (10, i, 810, i); } } public class CoreControl { public static void main(String[] a) { JFrame window = new JFrame(); window.setSize(840,560); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.getContentPane().add(new Grid

Creating a Java Timer and a TimerTask?

六月ゝ 毕业季﹏ 提交于 2019-11-28 08:57:13
问题 I'm new to Java and I'm trying to set a simple timer, I'm familiar with set_interval , because of experience with JavaScript and ActionScript, I'm not so familiar with classes yet so I get confused easily, I understand that I need to set a new Timer , and then set a TimerTask , but I don't get how exactly to do it even though I'm looking at the documentation right now.. So I created an Applet, and that's my init method: public void init() { TimerTask myTask; Timer myTimer; myTimer.schedule

Android Paint stroke width positioning

僤鯓⒐⒋嵵緔 提交于 2019-11-28 07:17:31
Given this code to draw a line: Paint p; p = new Paint(Paint.ANTI_ALIAS_FLAG); p.setColor(android.graphics.Color.WHITE); p.setStyle(Paint.Style.FILL); p.setStrokeWidth(21); canvas.drawLine(0,50,100,50,p); there are 3 possible stroke-drawing strategies: Inside: The line is painted in the rectangle (0,50,100,70) Center: The line is painted in the rectangle (0,40,100,60) Outside: The line is painted in the rectangle (0,30,100,50) In practice it appears that default behavior follows the Center strategy. Is it possible to modify a paint to produce results corresponding to one of the other

Drawing a filled rectangle with a border in android

↘锁芯ラ 提交于 2019-11-28 07:09:29
Is there any way in Android to draw a filled rectangle with say a black border. My problem is that the canvas.draw() takes one paint object, and to my knowledge the paint object can't have a different color for the fill and the stroke. Is there a way around this? You draw a rectangle with the color of the border and the size of the rectangle plus the border, you change the color of the paint and draw again the rectangle with the normal size. Try paint. setStyle (Paint.Style. FILL ) and paint. setStyle (Paint.Style. STROKE ). Paint paint = new Paint(); Rect r = new Rect(10, 10, 200, 100);

JLabel won't display image - NullPointerException

╄→尐↘猪︶ㄣ 提交于 2019-11-28 06:55:14
问题 this is my first Java GUI program, and really only my second java program, so take it easy on me :) My program is a result of a lot of googling and reading java docs. My problem is that I have a sprite sheet of 52 cards, and am attempting to save these cards individually to a Buffered Image array using subImage, and just for testing purposes, display all 52 in a window. The File is in the correct directory I made sure of that. I believe that my problem lies with my use of Jlabels, or simply a

Java - Calling paint method from different class?

我的梦境 提交于 2019-11-28 06:15:46
问题 I have a class which extends JFrame and creates a window and it needs to call the paint() method which is in a different class. I understand that if they were in the same class, the setVisible(true) would call the paint method, but since they are in different classes, it does not. I have created objects of the Die class (the one painting), but I don't know how to use them to call the paint method. This is the class which creates the window: public class Game extends Frame { public void window

Force immediate layout and paint in Swing

感情迁移 提交于 2019-11-28 04:04:14
问题 I cannot seem to force a layout in Swing. I have a JComponent added to a JLayeredPane and I set a border on the JComponent . Then, I want to immediately re-draw everything - not in the sense of "please do this asap" like invalidate() , but synchronously and immediately. Any help? I cannot seem to find the right method of doing this, and all my reading about invalidate(), validate(), repaint(), doLayout(), etc is just confusing me more! 回答1: According to this (see the section titled