paint

Why not to draw directly inside JFrame [duplicate]

99封情书 提交于 2019-11-27 15:58:22
This question already has an answer here: Difference between paint() and paintcomponent()? 2 answers Can anyone explain me why shouldn't i use paint method to draw directly inside a JFrame window, and i should use paintComponent method with a JPanel inside the JFrame ? Thanks in advance. MadProgrammer Three main reasons... Top level containers aren't double buffered, which cause flickering when the frame is repainted, yes, you can implement you're own double buffering, but... Painting inside a frame does not take into consideration the frames borders, meaning that it's possible to paint under

How can I tell if a Delphi control is currently visible?

早过忘川 提交于 2019-11-27 15:18:17
问题 I need a way to for a custom control (descended from TCustomControl) to tell if it is currently visible. I'm not talking about the .Visible property; I mean whether or not it's actually being displayed on-screen at the moment. Does anyone know how to do this? 回答1: A few years back I had the same kind of problem for a Form: I was looking for a way to determine if a Form is actually visible (even only partially) to the user. In particular when it was supposed to be visible and Showing was True

Android: How to fill color to the specific part of the Image only? [duplicate]

不想你离开。 提交于 2019-11-27 15:15:55
问题 This question already has answers here : how to fill color in image in particular area? (4 answers) Closed 2 years ago . I have Image Like this: Now, i want to fill the color to the Specific part of that image. as like If i select color blue and if i touch on Cap then the cap should be fill with the color Blue. Same thing should be also happen with the other part like nose, Mouth, Eyes etc So, How it is possible using android ? Can any budy help me please. Updated I have try with the

Why is paint()/paintComponent() never called?

為{幸葍}努か 提交于 2019-11-27 15:11:38
For the last two days I have tried to understand how Java handles graphics, but have failed miserably at just that. My main problem is understanding exactly how and when paint() (or the newer paintComponent() ) is/should be called. In the following code I made to see when things are created, the paintComponent() is never called, unless I manually add a call to it myself or calls to JFrame.paintAll()/JFrame.paintComponents(). I renamed the paint() method to paintComponent() in hoping that would fix my problem of it never being called (even at repaint()), but no luck. package jpanelpaint; import

paint() and repaint() in Java

a 夏天 提交于 2019-11-27 13:59:46
I've spent maybe the last two hours browsing and reading up on these methods and the Graphics class, and maybe I'm stupid, haha, but I'm just not understanding them. What are they for? I understand that they're supposed redraw or update components on the screen, but I have never understood why this is required (I'm new to this). For example, if I'm moving a JLabel around the screen, a call to setLocation() moves it just fine. Is that a scenario in which repaint() isn't required? In which scenarios is it useful, and why? Apologies if you feel that this is a question that could be solved using

Android: measureText() Return Pixels Based on Scaled Pixels

坚强是说给别人听的谎言 提交于 2019-11-27 13:14:58
So I use Paint's measureText() method to measure the width of a segment of text, but I wanted to measure text based on a certain text size. Say I wanted to get the width of a text segment that will be 20 scaled pixels when it occupies a certain TextView. I tried the following: Paint paint = new Paint(); paint.setTextSize(20); paint.measureText("sample text"); However, it does not seem to be working. I believe it is returning a width with respect to a smaller text size. I feel like I'm missing something that will make me slap myself in the face and yell herp derp. You need to get the

Android color picker to be included in the activity

岁酱吖の 提交于 2019-11-27 12:57:20
I would like to include a color picker in my paint program. So anyone here has already done something like this please give me some tutorials or piece of code to get me started. I really need to get the whole idea of adding this. I already have set up the canvas for the drawing so I'd like to add the color picker to it. Any ideas are welcome. Thanks. Your class should implement ColorPickerDialog.OnColorChangedListener public class MainActivity implements ColorPickerDialog.OnColorChangedListener { private Paint mPaint; mPaint = new Paint(); // on button click new ColorPickerDialog(this, this,

How to create MS Paint clone with Python and pygame

与世无争的帅哥 提交于 2019-11-27 11:34:21
问题 As I see it, there are two ways to handle mouse events to draw a picture. The first is to detect when the mouse moves and draw a line to where the mouse is, shown here. However, the problem with this is that with a large brush size, many gaps appear between each "line" that is not straight since it is using the line's stroke size to create thick lines. The other way is to draw circles when the mouse moves as is shown here. The problem with this is that gaps appear between each circle if the

Android Edit Bitmap Channels

╄→尐↘猪︶ㄣ 提交于 2019-11-27 09:42:14
问题 It's possible to access the alpha channel of a given bitmap with extractAlpha() , but I haven't been able to find any way to actually set the alpha channel of a bitmap. How can multiple greyscale images be recombined as channels into a Bitmap with Android? 回答1: It is quite possible to re-combine separate channels back into an ARGB image. You just need the grayscale channel images and an image with the alpha channel you want - note that this is not an opaque grayscale image, but an image with

How do I make a rectangle move across the screen with key bindings?

你离开我真会死。 提交于 2019-11-27 09:38:37
The game I'm trying to create is snake and so far I've figured out how to use paint(Graphics g) a bit of JPanel , mouse listener and now I'm trying to create a rectangle that will move across the screen and use key bindings or key listener, but I have no idea how I should go about this. Here's my code so far, it has 2 parts. The first part is called snake2 because if I don't know what I'm doing I make the same program with different things. Snake used frame, but Snake2 uses JPanel (looks better…) import java.awt.*; //required for MouseListener import java.awt.event.*; //requied for Graohics