paintcomponent

the images are not loading

走远了吗. 提交于 2019-11-26 13:51:21
The frame window is launching but the background and the foreground images are not loading and the window frame size is also very very small. Please help me to fix the error. here is the code posted Aquarium.java import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.util.Vector; public class Aquarium extends Frame implements Runnable { Image aquariumImage,memoryImage; BufferedImage bImage; Graphics memoryGraphics; Image [] fishImages=new Image[2]; MediaTracker tracker; int

How to draw in JPanel? (Swing/graphics Java)

前提是你 提交于 2019-11-26 13:06:23
I'm working on a project in which I am trying to make a paint program. So far I've used Netbeans to create a GUI and set up the program. As of right now I am able to call all the coordinated necessary to draw inside it but I am very confused with how to actually paint inside it. Towards the end of my code I have a failed attempt at drawing inside the panel. Can anyone explain/show how to use graphics in a example like this? All examples I have found make a class and extend it with JPanel but I don't know if I can do this since it was generated in netbeans. I need to draw inside a JPanel ,

Java make a directed line and make it move

╄→гoц情女王★ 提交于 2019-11-26 11:28:21
问题 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

Stretch a JLabel text

偶尔善良 提交于 2019-11-26 10:57:19
Is there a way to make a JLabel's text stretch to 100% height? I need the text to update when the component's size changes as well. I saw some solution that could work; It involved calculating and setting the font size so it appears the right height. I would have also have to add listeners for when the height changed to make it respond and I do not know exactly where I should do that. I am hoping for a better solution with layout managers, but couldn't find anything. Any ideas? trashgod In the approach shown below, the desired text is imaged using TextLayout using a suitably large Font size

Draw a circle with a radius and points around the edge

徘徊边缘 提交于 2019-11-26 10:31:02
I'm really stuck on how to go about programming this. How to draw a circle in Java with a radius and points around the edge? I need to draw a circle within a JFrame with a radius and points around the circumference. i can mathematically calculate how to find the coordinates of the point around the edge but i cant seem to be able to program the circle. I am currently using a Ellipse2D method but that doesn't seem to work and doesn't return a radius, as under my understanding, it doesn't draw the circle from the center rather from a starting coordinate using a height and width. My current code

Drawing Multiple JComponents to a Frame

这一生的挚爱 提交于 2019-11-26 08:57:50
I am trying to draw multiple car objects onto the same window but it appears that they are overwriting each other. Here is my overridden paintComponent method in the Car class public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(wheelColor); g2.fill(leftWheel); g2.fill(rightWheel); g2.setColor(bodyColor); g2.fill(body); g2.fill(cab); } And in my Viewer Class: JFrame f = new JFrame(); initializeFrame(f); Car x = new Car(100, 100); Car y = new Car(300, 300); f.add(x); f.add(y); Although the coordinates seem to be different, only the last car is being drawn. Any

Spring behavior simulation

一笑奈何 提交于 2019-11-26 08:35:54
问题 Basically, i want to simulate spring behavior on painted image. I want to make it run through a few iterations scaling it up and down (like it is fixed on a spring). All of the examples i found on the net lead to this class - FloatSpring.java It should provide the needed calculations to move point A to point B applying spring-like effect which depends on various FloatSpring class settings. The problem is that i didn\'t find a single clear example how to use it properly. I made this small

Difference between paint() and paintcomponent()?

假如想象 提交于 2019-11-26 08:30:27
问题 I have tried tutorials on this but I still don\'t quite understand it. Basically my question is which method is better and why? Should I use paint or paintComponent ? Please try to keep the answer simple, thanks. 回答1: Quoting from documentation of paint() method This method actually delegates the work of painting to three protected methods: paintComponent, paintBorder, and paintChildren. ... A subclass that just wants to specialize the UI (look and feel) delegate's paint method should just

Swing Worker : function get()

泄露秘密 提交于 2019-11-26 06:02:45
问题 My problem is that I don\'t understand how the swingworker works because what I\'m trying to do is to make fa=worker.get() because I have a long method which compute a lot of points running in background because I don\'t want to freeze my interface and I want to get her results to paint the component image. But I don\'t understand where it goes when I do fa=worker.get() because my console prints \"titi\" and I put a lot of other printing to see the next part of program reached but no one is

the images are not loading

只谈情不闲聊 提交于 2019-11-26 05:54:47
问题 The frame window is launching but the background and the foreground images are not loading and the window frame size is also very very small. Please help me to fix the error. here is the code posted Aquarium.java import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.util.Vector; public class Aquarium extends Frame implements Runnable { Image aquariumImage,memoryImage;