graphics2d

How to obtain the state of grid cells based on a specific location on a 2D array

主宰稳场 提交于 2019-12-19 04:15:09
问题 Consider a 2D grid with n rows and n columns (here 75x75). The symbols (tokens) are drawn in each cell on mouse click. The code below is used to draw grid lines and symbols within cells: class DrawCanvas extends JPanel{ @Override public void paintComponent(Graphics g){ super.paintComponent(g); setBackground(Color.WHITE); //Lines g.setColor(Color.BLACK); for(int ligne = 1; ligne < ROWS; ++ligne){ g.fillRoundRect(0, cellSize * ligne - halfGridWidth, canvasWidth - 1, gridWidth, gridWidth,

How to obtain the state of grid cells based on a specific location on a 2D array

匆匆过客 提交于 2019-12-19 04:15:06
问题 Consider a 2D grid with n rows and n columns (here 75x75). The symbols (tokens) are drawn in each cell on mouse click. The code below is used to draw grid lines and symbols within cells: class DrawCanvas extends JPanel{ @Override public void paintComponent(Graphics g){ super.paintComponent(g); setBackground(Color.WHITE); //Lines g.setColor(Color.BLACK); for(int ligne = 1; ligne < ROWS; ++ligne){ g.fillRoundRect(0, cellSize * ligne - halfGridWidth, canvasWidth - 1, gridWidth, gridWidth,

Why does this image look so bad after being scaled down in Java?

扶醉桌前 提交于 2019-12-19 03:24:26
问题 Here is the original image: http://rank.my/public/images/uploaded/orig-4193395691714613396.png And here it is scaled down to 300x225: http://rank.my/public/images/uploaded/norm-4193395691714613396.png And here it is scaled down to 150x112: http://rank.my/public/images/uploaded/small-4193395691714613396.png As you can see, 300x225 looks pretty bad, and 150x112 looks awful. Here is the code I'm using to scale down the image: private static BufferedImage createResizedCopy(final BufferedImage

fitting PrinterJob Object to specific print format of BufferedImage

穿精又带淫゛_ 提交于 2019-12-18 09:49:08
问题 Im using PrinterJob object in order to print my Bufferedimage, I have a BufferedImage which I proccess and send it to Printer job with Paper Format etc, and I cant make it fittable to my card printer. when i save it to my hard-disk and print via windows printing manager it printing very good on my card printer but with PrinterJob it came out too big and not fittable for a card the size of the card is 86X54mm and the size of my buffered image is 1300x816px The Code : PrinterJob printjob =

can't get my coordinates graphics2D mouseclick java

假如想象 提交于 2019-12-18 09:36:41
问题 I got an extended JLabel class where I draw my Map using the code below : the new AffineTransform() is the identity to left my image as it is (0,0,w,h) mygraphics2D = (Graphics2D) getGraphics(); graphics2D.scale(2.0,2.0) ; graphics2D.rotate(.... graphics2D.drawImage(myImageIcon.getImage(),new AffineTransform(), this); now when I click on my JLabel using this event : public void mouseClicked(MouseEvent e) { x =e.getX() ; y = e.getY(); NewX = ???? NewY = ???? } I want to retrieve my new

Painting in a BufferedImage inside Swing

落花浮王杯 提交于 2019-12-18 04:27:06
问题 Im working on a paint application written in java and running into a few (more) problems. I have a gui and a working program(kinda), my only problem is that the lines and graphics that the user draws are not saved(disappear after next one is drawn). From a past question i learned that i will need to use a BufferedImage to store the drawings then paint that inside my paint class. My questions are, Can anyone provide a basic explanation/example of how to use a bufferedimage to store and paint

How to implement oval GradientPaint?

不问归期 提交于 2019-12-17 19:53:20
问题 We know that there are a class named RadialGradientPaint in Java and we can use it to have a gradient painting for circle. But I want to have an oval (ellipse) GradientPaint . How to implement oval GradientPaint ? 回答1: Use an AffineTransform when drawing the RadialGradientPaint . This would require a scale instance of the transform. It might end up looking something like this: import java.awt.*; import java.awt.MultipleGradientPaint.CycleMethod; import java.awt.geom.*; import java.awt.event.*

how to save panel as image in swing?

被刻印的时光 ゝ 提交于 2019-12-17 16:45:27
问题 Hi i want to convert panel which contains components like label and buttons to image file. I have done the following code. The image was saved. but the content of the panel not visible or saved. Can anyone tell me how to save the panel with its components. Code: package PanelToImage; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; import javax.swing.*; public class sample extends JPanel { public JPanel firstpanel; public JPanel

Java how to paint rectangles on mouseclick

心不动则不痛 提交于 2019-12-17 10:04:20
问题 As the title says, I'm having a hard time trying to draw some rectangles (filled) in JApplet. The exact goal is to have a 50x50 table and when you click on a targeted cell, to make it filled (possibly done by drawing a filled rectangle). I have done the maths about the coordinates of the starting point, but for some reason I can't draw the new rectangle in the MouseClicked method. Any suggestions? public class Main extends JApplet { public static final int DIMX = 800; public static final int

Drawing a simple line graph in Java

此生再无相见时 提交于 2019-12-17 02:35:12
问题 In my program I want to draw a simple score line graph. I have a text file and on each line is an integer score, which I read in and want to pass as argument to my graph class. I'm having some trouble implementing the graph class and all the examples I've seen have their methods in the same class as their main, which I won't have. I want to be able to pass my array to the object and generate a graph, but when calling my paint method it is asking me for a Graphics g... This is what I have so