graphics2d

Rotating Image with AffineTransform

只愿长相守 提交于 2019-12-17 02:32:00
问题 I have got class called Airplane . Inside this class i have got variable img which is a BufferedImage type. What is more i have got class WorldMap which overrides function paintComponent(Graphics g) : @Override public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.drawImage(mapa, 0, 0, getWidth(), getHeight(), null); drawAirplanes(g2d); } Function drawAirplanes() look like this: private void drawAirplane(Graphics2D g){ for(Samolot i: s){ i.rotateAirplane(); g.drawImage

Code is producing a gray screen

纵饮孤独 提交于 2019-12-14 03:50:05
问题 I can't seem to work out what the problem is here. import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.JPanel; public class GamePanel extends JPanel implements Runnable, MouseMotionListener { private static final int SCREEN_WIDTH = 640; private static final int

make image point toward specific location in java

跟風遠走 提交于 2019-12-14 03:35:57
问题 BEFORE YOU MARK IT AS DUPLICATE I have searched a lot in the internet for that and tried every solution, but no one does it the same way I do it. In my case the rotation is in a sperate class. I have created a java class that inherits JLabel class, in my class I have an arrow BufferedImage which I draw using the paintComponent(Graphics g) method. I am trying to make the arrow point to a specific point (which I get from a different method) but something goes wrong and the arrow rotates to the

Calling methods to draw on JFrame

狂风中的少年 提交于 2019-12-13 08:58:45
问题 Can somebody explain to me why this isn't working? The error seems to be inside the Gen class but I think it may something to do with BoxMan. The error says cannot find symbol- variable g. I also tried putting in ints and doubles but it gives me: Required (Java.awt.Graphics) Found(int) / (double). So how can fix this? I've looked everywhere and can't find the answer. Help a beginner! import java.awt.*; import javax.swing.JFrame; import javax.swing.WindowConstants; import java.lang.Object.*;

Drawing a curve in Java using mouse drag

我的梦境 提交于 2019-12-13 07:46:52
问题 I am new to java and I am trying to draw a curve. The functionality I am trying to implement is that the curves should be defined by a mouse drag followed by a mouse click. Once the drag action is done, I want a line to be drawn from the start of the drag to the end. Clicking on the canvas after that should be considered the third point necessary to define the curve and the line drawn should be changed into a curve. How do I do that? I've gone through different posts here about how to draw

Exception in thread “Thread” java.lang.OutOfMemoryError: Requested array size exceeds VM limit

戏子无情 提交于 2019-12-13 05:58:55
问题 The only thing difference is there is two different crop location. The question is why i get this error?? Method call CropRealOriginalImage1 orderName = new CropRealOriginalImage1(); FourAreaCropAgain1 orderNameFirst=new FourAreaCropAgain1(); orderNameFirst.orderNameFirst(); Decode decode= new Decode(); decode.inputImage("C:/TEMP/Image/Embed Image/Four Area/OrderFirst.png"); if(decode.s.equals("")){ System.out.println("OderFirst=null"); }else{ //put b into txt file System.out.println("decode

Put JLabel in front of Graphics 2D Rectangle in JPanel

匆匆过客 提交于 2019-12-13 04:01:50
问题 Is there any way to put the JLabel in front of the rectangle? Currently, the JLabel is underneath the rectangle. Here is my relevant code: public class MainMenu_South extends JPanel { MainMenu_BlueJay t; JLabel start=new JLabel("START"); @Override public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.blue); g2d.drawRect(0, 30, 900, 30); g2d.fillRect(0, 30, 900, 30); } public MainMenu_South(MainMenu_BlueJay t){ setLayout(null); this.t=t;

How do I make Graphics2D draw a tooltip on Mouse Hover

烂漫一生 提交于 2019-12-13 03:56:49
问题 so I have initialized each individual vertex as a JLabel and drawn the dot on the application with Graphics2D. However, I can't get a mouse listener to work with the graphic drawing for some reason. I am trying to get a tooltip to appear whenever the user has their mouse on the point (making an interractive graph). package GUI; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import javax

Drawing Shapes with lines on a transparent Graphics2D to get a png image

不羁的心 提交于 2019-12-13 03:38:35
问题 So my goal is to have a window that opens where you can draw some lines on a white background by just clicking. The problem is that when it try to save it always comes back as a png, but it comes as a square image. If I draw a triangle with my lines I get a triangle inside a white square but I want the triangle only. I would really appreciate any help I tried every solution I came accross on stackoverflow and I tried to understand Graphics2D in depth but sadly failed public class Draw{ public

Java - Good and free library to resize images [closed]

扶醉桌前 提交于 2019-12-12 18:45:56
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I want to resize images in java. Until now i use this: BufferedImage resizedImage = new BufferedImage((int) new_dim.getWidth(), (int)