paintcomponent

Inclined plane Java (Triangle with angle)

落花浮王杯 提交于 2019-12-11 14:57:11
问题 i need to create an inclined plane according to a certain angle with a bloc on it and then use the physics laws to see if the bloc slides or not. For now, i created my bloc with a Path2D.Double, but i can't find a way to change the angle of the bloc. The angle is chosen from a spinner in the frame in the application.I created 2 class, one is the Frame, and the other is the Panel, where i draw my bloc. Here is the code of my path: @Override public void paintComponent(Graphics g) { super

Combining MouseListeners with Polygons in Graphics2D

限于喜欢 提交于 2019-12-11 13:39:05
问题 I've tried extending Polygon for my data class of choice (implementing MouseListener ). My paintComponent override in the parent JPanel is rendering the extended Polygon class (I called it Hexagon ) with .fillPolygon - it renders fine! But it doesn't let me interact with the MouseListener implemented in the code of it. Is there a stage I'm missing somewhere? Looked around for inspiration, arrived at this: https://docs.oracle.com/javase/tutorial/2d/advanced/user.html Unfortunately this limits

Drawing with graphics and with widgets in JApplet/Swing?

荒凉一梦 提交于 2019-12-11 13:04:06
问题 Basically I have a JApplet that tries to draw with the graphics (ie, g.drawOval(10,10,100,100) and also include JCompotents (ie. JButton). What happens is that the repaint can get really wacky. Sometimes the graphics will draw over widgets or vis-versa. It's not reliable and leads to unpredictable behavior. (Button also always be on top of those graphics) I've played around with it trying to override or manually draw components, changing orders, etc, but think I'm missing something very

Removing flashiness/ shakiness from scrolling text

假如想象 提交于 2019-12-11 12:30:03
问题 I have finally made a ticker that functions how I want it to, but the only problem now is that it seems kind of shaky and looks like it is being displayed on an old tv. How do I make it look smoother? Here is my code: import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class Scroll1 extends JPanel{ private int x; private int x2; private int y; private int width; private String text; private Font f=(new Font(

JPanel Drawing Glitch

烂漫一生 提交于 2019-12-11 09:59:59
问题 I am using a JPanel to draw my game onto, using a fixed game loop, and double buffering; however I get a glitch somewhere on the screen. The glitch is a screen tearing visual artifact that stretches across X axis, and is about 20 pixels tall. I have recreated the problem in 1 class, as shown below. To recreate the problem, you can run the code and move the square around with the arrow keys, when the square moves over the place where the visual tearing occurs, you should see the effect. (The

JPanel repaint from another class

[亡魂溺海] 提交于 2019-12-11 09:51:24
问题 I have a JPanel which displays an image. In a separate class, I'm reading from an xml file points. I am firstly creating an arraylist of triangles from these points. However I need to show the triangles on the image, i.e. draw them on! (yes this should be simple). But as these points and triangles are created in another class, I do not seem to be able to draw them on the already-displayed image within the GUI class. I have tried creating a ArrayList in the JPanel itself, which I update and

Repainting/refreshing JLabels on a JPanel

梦想的初衷 提交于 2019-12-11 07:01:17
问题 I'm having trouble getting my JLabels in a 2D array to update during runtime. The program I'm working on is a variant of Connect Four. I create a 2D array of JLabels, which all default to an ImageIcon containing an image of a blank slot. Players 1 and 2 choose their colors, and on a player's turn, he can click to drop a piece into a column (gravity causes the piece to fall to the bottom or until it lands atop another piece). I'm pretty positive that my addToColumn method is working fine. My

repaint() not calling PaintComponent to use Graphics2D

流过昼夜 提交于 2019-12-11 06:44:28
问题 I have spent a few days now trying to get the Graphics2D class to work within my code. I have it structured in such a way that when a click event is registered the call to repaint is done, however this only produces a nullpointer exception when it reaches the stage of calling repaint(). It is all working as expected when debugging and not called from within the paintComponent method, however when trying to call the code properly using paintComponent and repaint() to allow the Graphics2D class

java pick random images

别等时光非礼了梦想. 提交于 2019-12-11 06:25:56
问题 English is not my native language, sorry for any mistakes. I have to make a Bubble Shooter game in Java. I want to use images for the bubbles and I want the images to be picked randomly. I used Random and ImageIcon classes. My program doesn't show anything when I compile it and I don't know where the problem is. I'm a beginner in Java. This is the code for my Game class: import java.awt.Graphics; import java.awt.Image; import java.util.Vector; import javax.swing.JPanel; public class Game

Image drawing with PaintComponent Java

别说谁变了你拦得住时间么 提交于 2019-12-11 05:45:55
问题 I'm studying java currently, and yet again I ran into a code in the book which doesn't wanna work and i can't figure out why. This code snippet is from Head First Java import javax.swing.*; import java.awt.*; public class SimpleGui { public static void main (String[] args){ JFrame frame = new JFrame(); DrawPanel button = new DrawPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(button); frame.setSize(300,300); frame.setVisible(true); } } import java.awt