paintcomponent

Why is paintComponent executed 2 times?

£可爱£侵袭症+ 提交于 2020-01-04 05:15:07
问题 I have following code: canvas=new MembershipFunctionComponent(functions); canvas.setPreferredSize(new Dimension((int)this.getWidth(), (int)this.getHeight())); canvas.addMouseListener(canvas); pane.add(canvas); MembsershipFunctionComponent extends JComponent. Why is paintComponent method executed 2 times? 回答1: paintComponent can get called at pretty much any time by the Swing framework. Examples of when this might happen: Any time a component is resized Any time part of the component is

Why does my jFrame update only after I resize the window?

风流意气都作罢 提交于 2019-12-31 03:27:07
问题 I understand that when you add/remove a component, you need to revalidate() and then repaint() . However, I am changing the state of my polygon. Initially, the image is shown, however when I press the left and right keys, the image does not move. If I move the window, the gui is updated. Why doesn't it update as I press the keys? public class Terminos { private LeftTermin ter; private String[] commands = { "UP", "DOWN", "RIGHT", "LEFT" }; public Terminos() { initComp(); } public void initComp

JFrame, JPanel, paintComponent how to

旧时模样 提交于 2019-12-30 14:42:41
问题 Hi I have following classes, I want display content (paintComponentor that panel with this rectangle from paint class) inside my JFrame. I try already find out how to achieve this by looking at different examples posted on this forum however this doesn't help me I need simple example like panel inside frame with paint component or something similar to understand how should work! ps. don't hang me on tree because I am newbie jut ask question!!! [I want something like this][1] package scp;

JFrame, JPanel, paintComponent how to

本小妞迷上赌 提交于 2019-12-30 14:42:12
问题 Hi I have following classes, I want display content (paintComponentor that panel with this rectangle from paint class) inside my JFrame. I try already find out how to achieve this by looking at different examples posted on this forum however this doesn't help me I need simple example like panel inside frame with paint component or something similar to understand how should work! ps. don't hang me on tree because I am newbie jut ask question!!! [I want something like this][1] package scp;

Difference between Graphics object of getGraphics and paintComponent

谁说胖子不能爱 提交于 2019-12-30 12:13:15
问题 If I'm working with a JPanel, what's the difference between the Graphics object returned by getGraphics, and the Graphics object that is passed in paintComponent method? 回答1: getGraphics Can be null Is a "snap shot" of the last paint process Anything painted to it will be lost on the next paint cycle You should avoid using getGraphics and simply use what is past to the paintComponent method. In theory, there is no difference between them, but if you want what you have painted to survive

Anti-aliasing in paintComponent() method

◇◆丶佛笑我妖孽 提交于 2019-12-30 07:23:11
问题 I want to print some text using the paintComponent(..) method. @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.red); g.drawString("Hello world", 10, 10); } But the text is somewhat jaggy. How could you force text drawing with [anti-aliasing] in this method? Thank you. 回答1: You can set double buffering by: class MyPanel extends JPanel { public MyPanel() { super(true);//set Double buffering for JPanel } } or simply call JComponent

about drawing a Polygon in java

泪湿孤枕 提交于 2019-12-29 01:33:11
问题 hi there i'm trying to improve myself about java2D and first of all i'm dealing with drawing polygons. However, i can not see the polygon on frame. I read some tutorials and examples but as i said i face with problems. here is the sample code of drawing a polygon; import java.awt.Color; import java.awt.Graphics; import java.awt.Polygon; import javax.swing.JFrame; public class jRisk extends JFrame { private JFrame mainMap; private Polygon poly; public jRisk(){ initComponents(); } private void

Move an Oval in java

非 Y 不嫁゛ 提交于 2019-12-28 06:54:10
问题 I made a mini code that draw oval and link each other , now i try to move the oval(Circle) but I have a problem (in coding) // Panneau.java public class Panneau extends JPanel { private int R = 20; private boolean isDrag = false; String text = "stack"; int x = 250, y = 200; int height = 50, width = 50; Random Rnd = new Random(); int rand=Rnd.nextInt(); int r=Math.abs(rand%250); int r2=Math.abs(rand%250); public Panneau() { addMouseListener(new MouseAdapter() { @Override public void

I am trying to make ball gradually move

て烟熏妆下的殇ゞ 提交于 2019-12-28 04:32:08
问题 I am trying to make a ball gradually move when you press one of the arrow keys, right now it kind of just teleports. I want it so that you can see it move. Based on this example, I am using key bindings, and there is a variable called delta that causes the ball move by 50 pixels, but like I said the ball just appears 50 pixels in whichever direction the arrow key is you pressed, I want it to be like if you were to kick a ball you can see it get from point a to b. Go to line 89 that is where I

paintComponent does not work if its called by the recursive function?

馋奶兔 提交于 2019-12-27 16:07:31
问题 I want to see all the Points one after another but I see only able to see 1 point. What shold I change to see all the Points ? In the System.out you can see 10 times "set" and then 2 times "paintComponent". what should I change that after each time set is called it change the "paintComponente" ? ================================================================================== public class exampe extends JPanel { int x; int y; public void paintComponent(Graphics g) { super.paintComponent(g);