paintcomponent

Graph Plotting Issue

杀马特。学长 韩版系。学妹 提交于 2019-12-12 03:17:12
问题 I am creating line graph using outputs from a thread, the threads are simulations of incoming and outgoing bill that run over a course of 52 seconds and this will be dipicted on a line graph as shown below to show the bank balance over the 52 seconds! Currently the program runs fine, when I click start the point gets updated but every a new point is placed on the graph the previous one disappears. How i can i keep all the points on the graph. I would assume i would have to create 2 new int

Create a disappearing JPanel?

白昼怎懂夜的黑 提交于 2019-12-12 03:14:19
问题 I am trying to create an extended JPanel that acts as a way to highlight some region of the screen. I have taken some code from this SO answer but would like to extend it further though I am not sure how to go about it. I would like to be able to have my JPanel ( MatchAreaPanel below) disappear after a given timeout is reached. That is the JPanel sets its visible property to false and subsequently disposes of itself. What would be the best way to go about doing this? import java.awt

repaint() paints slower than paintComponent()?

为君一笑 提交于 2019-12-12 03:07:39
问题 I am painting vehicle objects that I defined using the paintComponent(). Because the vehicles can move, I implement ActionListener and set a Timer() to trigger. As a result, my vehicles can move. But it is kind of "shaking". When I keep resizing the window to call the paintComponent(), the movement becomes smooth. When I do not resize the window (not calling paintComponent), it gets skaking again. Why? How to fix it? public class VehiclesComponent extends JComponent implements ActionListener{

Using ActionListener to update variables in other classes

青春壹個敷衍的年華 提交于 2019-12-12 03:06:32
问题 I am designing an applet so it allows a user to plot a graph. I am having problems to construct a code which from another file (ControlsB.java) the variables in the Graph.java file are updated. Below is my code: import java.awt.*; import javax.swing.*; public class Calculator extends JFrame{ /** * */ private static final long serialVersionUID = 1L; private static final int HORIZONTAL_SCROLLBAR_NEVER = 0; private static final int VERTICAL_SCROLLBAR_ALWAYS = 0; public static void main (String[]

Why doesn't this Java paint program paint more than one oval?

蓝咒 提交于 2019-12-12 02:56:59
问题 I have a Java paint program that uses a custom JPanel to paint on. While when clicking on the JPanel paints a small oval (or circle, if you will), the oval disappears each time you click on another place. The coordinates also get updated, but the oval does not stay, it moves to wherever the user clicks next... Here's the code for the custom JPanel: int xCord, yCord; public class PaintPanel extends JPanel implements MouseListener { // default serial whatever... private static final long

how can i draw a circle again if it goes too far on a JPanel

不打扰是莪最后的温柔 提交于 2019-12-12 01:47:45
问题 I am trying to make a program that starts with 7 circles at the top of a JPanel. All the circles have a random size and color. The circles start at the top of the screen and move downwards once they reach the bottom of the JPanel they should reappear at the top of the JPanel and move downwards again. I can already make the circles move downwards but I am unsure of how to draw them back at the top again. I made a method called replaceCircle to use to draw the circles back at the top of the

Java call to create new Area doesn't create shape?

泪湿孤枕 提交于 2019-12-11 21:22:38
问题 I was working on an issue where I was getting a cast problem trying to cast from Shape to Area (see previous post cast exception question). Now it seems that my shape that is create is not getting created correctly. Instead of posting all of my source code here I am attaching a link to all the source files here. Essentially I create the shape as follows with a standard call of YingYang shape = new YingYang(); shape = shape.moveTo(x, y); shape = shape.scaleBy(size); shape.setColor(getNextColor

How to GUI - Using paintcomponent() to initialize a GUI and then to add GUI based on mouse

社会主义新天地 提交于 2019-12-11 18:13:13
问题 Title says it all... My friend and I are doing this and we have no idea why Ball.java isn't actually making the balls in the gamePanel and then making the GUI. This is 8-ball pool, by the way. Here is the code: Driver or Final2 import javax.swing.*; import java.awt.*; import java.io.*; import java.util.*; import java.awt.event.*; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; import java.awt.geom.Rectangle2D; public class Final2

Some trouble with paintComponent()

时光怂恿深爱的人放手 提交于 2019-12-11 17:52:38
问题 Following a previous message, I have another problem (what a newbie). I have a class Fenetre , containing the following code (and more) : @Override public void paintComponent(Graphics g) { super.paintComponent(g); if(!init) { afficher= new Afficher(g); init = true; } g.setColor(Color.white); g.fillRect(0, 0, 1000, 500); if(lol)afficher.setMapOne(2,2,6); System.out.println("paintComponent : "+lol); afficher.checkChanges(g); } public void setLol(boolean n) { lol = n; System.out.println("setLol

Java: Speed up my code

隐身守侯 提交于 2019-12-11 16:06:47
问题 I have been coding an application which renders tiles and GUI and all that. I seem to have come across a problem where my paintComponent seems to hog too much CPU and can no longer run much higher than 10 FPS on my small computer. I was wondering if there was any more efficient way of running this code or threading it or anything to enhance the calculation speed. Here is my code: import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import javax.swing.JPanel;