paint

how to paint images on clicking button in frame?

試著忘記壹切 提交于 2020-01-05 12:32:09
问题 I've made two buttons in frame .I want to know how to display different images on clicking different buttons? is there another way out or i have to make panel?I am at beginner stage package prac; import java.awt.*; import java.awt.event.*; public class b extends Frame implements ActionListener{ String msg; Button one,two; b() { setSize(1000,500); setVisible(true); setLayout(new FlowLayout(FlowLayout.LEFT)); one=new Button("1"); two=new Button("2"); add(one); add(two); one.addActionListener

Key listeners/key bindings in Java

99封情书 提交于 2020-01-05 09:02:43
问题 How do I code an event that starts when a key (specifically the space bar) is pressed, continues running when the key is held , and only stops when the key is released? I'm trying to simulate a wheeled object that moves across a rough surface. I've tried using the original KeyListener methods but the problem is, when I hold the space bar the object I'm simulating repeatedly stops and starts. I've heard a possible solution is key bindings but I still don't understand them even after reading

Key listeners/key bindings in Java

半腔热情 提交于 2020-01-05 09:02:12
问题 How do I code an event that starts when a key (specifically the space bar) is pressed, continues running when the key is held , and only stops when the key is released? I'm trying to simulate a wheeled object that moves across a rough surface. I've tried using the original KeyListener methods but the problem is, when I hold the space bar the object I'm simulating repeatedly stops and starts. I've heard a possible solution is key bindings but I still don't understand them even after reading

Implement paintSection for QHeaderView delivered class

十年热恋 提交于 2020-01-05 00:48:20
问题 protected: virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const { QHeaderView::paintSection(painter, rect, logicalIndex); painter->drawRect(2, 2, 10, 10); } Rectangle is not painting. But when paintSection removed it is painting. I need to draw rectangle after call base paintSection. 回答1: As it was answered in this your question, rect is an area your should paint at. If you paint outside of this area your drawings might be erased by painting of other cells.

A glitch with Edge label offset

雨燕双飞 提交于 2020-01-04 10:38:11
问题 I have peculiar problem when I tried to offset the edge label in my Jung2 network. As shown in figure below the label causes the self loop difficult to see. So I decided to offset the label: vv.getRenderContext().setLabelOffset(20); And the Effect: Offset is effective for all the edges except for the edge that I need: the self loop. Anyone has a solution or a workaround ? EDIT: Does anyone know what the EdgeLabelClosenessTransformer does? And how to use it? This may solve my problem. vv

Java More Resourceful Collision Detection

纵饮孤独 提交于 2020-01-04 02:52:07
问题 I am making a game in java which involves characters moving around a map and having some solid collision objects (i.e. buildings) placed around the map by reading certain data from a text file. There will be multiple maps where these objects' locations will change. My question is would painting a rectangle in a certain color that indicates collision behind such structures or would reading mouse coordinates and searching an array of these structures to see if that point lies on a building,

Android ShapeDrawable set Background and Border programmatically

一笑奈何 提交于 2020-01-03 16:57:05
问题 I have a ShapeDrawable : final ShapeDrawable drawable = new ShapeDrawable(shape); drawable.getPaint().setStyle(Paint.Style.FILL); drawable.getPaint().setColor(0xFFffffff); I want to set border(stroke) color and width for this drawable. I try setStyle(Paint.Style.FILL_AND_STROKE) but it set background and border with same color 回答1: Use drawable.getPaint().setStyle(Paint.Style.STROKE); drawable.getPaint().setStrokeWidth(2); // in pixel 来源: https://stackoverflow.com/questions/31103974/android

Drawing line to link treeview node of one treeview to treeview node of another treeview

一笑奈何 提交于 2020-01-03 06:41:10
问题 How is it possible to draw a line to link treeview node to another treeview node link should be shown in from 回答1: In WinForms TreeViews are special. For one they don't have a Paint event, so it is not possible to draw on them. (You can subclass them though, see the update below..!) Secondly you can't nest a transparent control in them. You can nest it but it won't be transparent..) So drawing onto the TreeView seems to be imposible. But maybe it is not what you want anyway..? Let's instead

Undo in painting apps like Penultimate and iDraft

谁说我不能喝 提交于 2020-01-03 04:45:27
问题 In apps like iDraft and Penultimate, they perform undos and redos very well without any delay. I tried many approaches. Currently, my testing app writes raw pixel data directly to a file after each undo using [NSData writeToFile:atomically:] but I am getting 0.6s delay. Can anyone give some hints on it? 回答1: I don’t know iDraft nor Penultimate, but chances are they have a simpler drawing model than you have. When writing a drawing app you can choose between two essential drawing

Paint method java - Rectangle with outline

半腔热情 提交于 2020-01-02 10:03:46
问题 I want to create a wall with a blue line outline and black filling. I have only a blue wall now and I tried a couple of the Graphics methods but wasn't working. public void paint(Graphics g) { g.setColor(Color.blue); g.fillRect(x, y, size, size); } 回答1: First, override paintComponent , not paint . Second, there's no need to re-invent the wheel like that. Instead, use an existing Swing component (e.g. JPanel ), import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout;