paintcomponent

Java: Add Background image to frame [duplicate]

十年热恋 提交于 2019-11-27 08:52:15
问题 Possible Duplicate: java swing background image drawing your own buffered image on frame I am trying to add a back ground image to my frame, but nothing that I have done works. I designed a slot machine consisting of several panels added to the container. Now, I am trying to add a nice background to the frame. I tried using the paint method. But, since I am already using the paint method to paint the reel images, it is not working on the background. I also tried adding a JLabel, but when I do

Having two objects move in an SwingBot

怎甘沉沦 提交于 2019-11-27 08:20:51
问题 I'm trying to make it so that both shapes move when the commands are pressed. My question is: How do I get the blue polygon to move along with the yellow rectangle? I can't seem to figure it out, no matter what I do. Any help is appreciated! thanks! EDIT: Removed Timer Code (it is for something different) import javax.swing.JFrame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import javax.swing.JComponent; import java.awt.geom.Ellipse2D; import java.awt

Visual Artifacts appearing on JPanel

假装没事ソ 提交于 2019-11-27 08:14:58
问题 I am trying to create a program with 2 JPanel using BorderLayout . The center panel is for random drawing of rectangle while the south panel is for the buttons. I am getting a weird image of the button on the top left corner of the JFrame whenever I hover the mouse cursor over the North or South button. I did some research and found out that this could be the reason for having a transparent background. I tried using super.paintComponent(g) for the panel but the rest of the rectangles drawn

Why gif animation doesn't animate when using it in paintComponent()?

谁都会走 提交于 2019-11-27 07:46:36
问题 I'm using paintComponent() to paint a gif animated image at the backgound of JPanel . It shows up the gif but doesn't animate. I use java 1.5 and i know that i can use label with icon. Does any body know why and how to fix it? private static class CirclePanel extends JPanel { ImageIcon imageIcon = new ImageIcon(BarcodeModel.class.getResource("verify.gif")); Point point = f.getLocation(); protected void paintComponent(Graphics g) { Graphics gc = g.create(); Graphics2D g2d = (Graphics2D) g

painting a particular button from a grid of buttons

北战南征 提交于 2019-11-27 07:16:59
问题 The following grid of buttons is defined as : JButton button_x = new RoundButton(); where RoundButton is defined as : public class RoundButton extends JButton { public RoundButton(String label) { super(label); this.setContentAreaFilled(false); Dimension size = this.getPreferredSize(); size.height = size.width = Math.max(size.height, size.width); this.setPreferredSize(size); } @Override protected void paintComponent(Graphics g) { if(!GameState.getIfComplete()) { // If the game is not complete

Java JPanel getGraphics()

做~自己de王妃 提交于 2019-11-27 07:03:17
问题 Since Java only supports single inheritance , I desire to paint directly on an instance of a JPanel that is a member of the class Panel . I grab an instance of Graphics from the member and then paint whatever I desire onto it. How can I not inherit from JComponent or JPanel and still utilize getGraphics() for painting on this without overriding public void paintComponent(Graphics g) ? private class Panel { private JPanel panel; private Grahics g; public Panel() { panel = new JPanel(); }

Java make a directed line and make it move

做~自己de王妃 提交于 2019-11-27 05:13:37
I want to make a directed line and make it move. I am able to make a directed line and move the line but the arrow get displaced while i move the line This is my paint method Line2D.Double line = new Line2D.Double(startX, startY, endX, endY); g2d.draw(line); tx.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); tx.translate(line.x2, line.y2); tx.rotate((angle - Math.PI / 2d)); Graphics2D gClone = (Graphics2D) g2d.create(); gClone.setTransform(tx); Polygon arrowHead = new Polygon(); arrowHead.addPoint(0, 15); arrowHead.addPoint(-15, -15); arrowHead.addPoint(15,

JPanel image flies from the screen

痴心易碎 提交于 2019-11-27 04:52:42
问题 I'm trying to make my Pedestrian object move, and it moves but at a certain point it flies away from the screen. The Pedestrian moves by a List of points. First the Pedestrian is added to toDraw to paint it and in startAndCreateTimer I loop through the same list to move the Vehicles Maybe it's because of this line i = (double) diff / (double) playTime; I actually don't want to set a playtime how not to do that, could this be the problem or is it something else? Here a link with the point

Java: mouseDragged and moving around in a graphical interface

℡╲_俬逩灬. 提交于 2019-11-27 02:13:15
newbie programmer here. I'm making a program that renders user-inputted equations in a Cartesian coordinate system. At the moment I'm having some issues with letting the user move the view around freely in the coordinate. Currently with mouseDragged the user can drag the view around a bit, but once the user releases the mouse and tries to move the view again the origin snaps back to the current position of the mouse cursor. What is the best way to let the user move around freely? Thanks in advance! Here's the code for the drawing area. import java.awt.Color; import java.awt.Graphics; import

java what is heavier: Canvas or paintComponent()?

 ̄綄美尐妖づ 提交于 2019-11-26 23:43:04
问题 Can someone tell me what should I use for painting graphics on a JPanel : Canvas , or simply drawing everything in paintComponent() ? I am painting hundreds of small images around 30 times per second, and I wonder which one would be the most lightweight, and in what conditions should I use both? Thanks. 回答1: The issue is rather broad and the context rather slim. Consider taking a look at Rotating multiple images causing flickering. Java Graphics2D and Swing animation running extremely slow