repaint

How to clear/ reset a JFrame

巧了我就是萌 提交于 2019-12-22 12:37:20
问题 Me and my friend have decided to work on a card game which cycles between 3 screens ( Player1HandScreen, Player2HandScreen and FightScreen ). Once Player1 has chosen their card from Player1HandScreen , Player1HandScreen leads to Player2HandScreen where Player2 does the same. then Player2HandScreen leads to FightScreen where the two cards are compared and one player is declared the winner of that round. The problem we are having is that once the round ends we want to clear Player1HandScreen as

java applet paint method trouble

老子叫甜甜 提交于 2019-12-22 09:46:40
问题 In code I am calling repaint() method from init() method but Output is not as per I expect. I called repaint() method 10 times but It called paint() only once(See Screenshot of O/P). Am I making any mistake. please help me. Thanks code import java.awt.*; import java.applet.Applet; /* <applet code="test" height=300 width=300> </applet> */ public class test extends Applet { int x,y; public void init() { x=5; y=10; for(int i=1;i<10;i++) { System.out.println("From init "+i); x+=(i*2); y+=(i*3);

Calling repaint from another class JFrame

。_饼干妹妹 提交于 2019-12-20 07:10:31
问题 I'm trying to call repaint from another class. But it does not work. I have to draw on a frame. public class Tester extends JFrame{ public static dtest d ; public static void main(String[] args) { Tester t = new Tester(); d = new dtest(); test tnew = new test(); } public static class dtest extends JFrame implements MouseMotionListener{ public static int x,y; dtest() { super("title"); setSize(500,500); setVisible(true); addMouseMotionListener(this); } @Override public void mouseDragged

no repaint while resizing when using .setPaint(gradient)

爷,独闯天下 提交于 2019-12-20 04:08:07
问题 As soon a I use gradients in my code, the repaint isn't done while resizing I get something like that while resizing (black rectangles where it has been resized, see image in the link below). And when i stop resizing, everything is drawn again, but only then. if I don't use g2d.setPaint(gradient); I have a quick redraw http://gui-builder.com/C41142775162.rar public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; //sample of the code GradientPaint

.setVisible(true) immediate repaint

喜你入骨 提交于 2019-12-19 19:54:08
问题 In a short method, I hide a JFrame using setVisible(false). Then I take a screenshot and restore the JFrame with setVisible(true). After made visible again, the window is supposed to show a different picture than before (lets say a part of that screenshot taken). The problem is that after setVisible(true) is called, the window is flashed with the old content for a split second before paintComponent is called and the updated state is drawn. I could probably workaround this in an ugly way, but

Line not appearing on JDesktopPane

橙三吉。 提交于 2019-12-19 12:28:39
问题 I want to draw line between two JPanels but line is not appearing on layeredPane. This is what i have done please go through it, compilable.Do try and correct this code. I have tried on drawing lines on Internal frames this way but it is not working for JPanels. package build; import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point;

repaint() in Java doesn't “re-paint” immediately?

人盡茶涼 提交于 2019-12-19 03:21:07
问题 I have a code like that: // In MyPanel.java public void paintComponent(Graphics g) { super.paintComponent(g); // Draw something mypanel_count++; } // In Test.java public void testLargeData() { while (notDone) { panel.repaint(); // do huge work test_count++; System.out.println("Test_count: " + test_count + ", MyPanel_count: " + mypanel_count); } } // Output !!! Test_count: 752, MyPanel_count: 23 Test_count: 753, MyPanel_count: 23 Test_count: 754, MyPanel_count: 23 Test_count: 755, MyPanel

How to force repaint in JS?

风流意气都作罢 提交于 2019-12-18 09:38:47
问题 What I am trying to achieve: user clicks on an element the screen shows the "calculation in progress" screen the system performs time-consuming math calculations the screen shows the result ("done") Here's the stripped code: <div id ="di" onclick="calc()">initial</div> <script> function calc() { var n,a=0; document.getElementById('di').textContent="calculation in progress"; for(n=0;n<1000000000;n++) // Here's the time consuming calculation { a=a+n; // for clarity's sake, I removed a

Java - repainting JPanel gives an error

蹲街弑〆低调 提交于 2019-12-18 09:21:27
问题 I'm a beginner in Java, and I'm trying to create an application that draws a rectangle where ever the cursor is located. I've already done everything, but I can't get the mouseMoved(MouseEvent) method to repaint the JPanel . Without the repaint, the rectangle is only drawn once and that's it. With the repaint, it compiles fine, but when I run it, every time the mouse is moved, I get this big " Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException " error. So, can anyone please

Repaint leaves trail

北城余情 提交于 2019-12-18 08:57:30
问题 I know that this isn't the first time that this question has been asked, but the responses haven't helped me much, so I am helping I am finally going to get my answer I have made this little game where I have made a car drive around a track (using rectangles was mandatory). When I use the repaint() metod the rectangle representing the car repaints in the new location, but leaves a trail behind. I have this code: import java.awt.Color; import java.awt.Component; import java.awt.Dimension;