paintcomponent

JFrame, JPanel, paintComponent how to

一世执手 提交于 2019-12-01 14:36:41
Hi I have following classes, I want display content (paintComponentor that panel with this rectangle from paint class) inside my JFrame. I try already find out how to achieve this by looking at different examples posted on this forum however this doesn't help me I need simple example like panel inside frame with paint component or something similar to understand how should work! ps. don't hang me on tree because I am newbie jut ask question!!! [I want something like this][1] package scp; import java.awt.*; import javax.swing.*; public class Panel extends JPanel { public Panel() { //this

drawing shape objects in java (draggable,resizable and can rotate)

断了今生、忘了曾经 提交于 2019-12-01 13:22:55
I am trying to draw shapes (triangle, rectangle, square and circle) that can be used in creating a picture. A user should be able to place a shape on a canvas and drag it around or even enlarge it to create a desired picture. I tried overriding the paintComponent() of a JPanel to achieve this but realize that the Jpanels shape remains a square so when you have a circle you can still drag it even if u are not necessarily touching it as it is within a square and also having difficulty drawing the triangle What libraries would you suggest? The Shape interface and derived classes, such as Path2D,

Components on the JPanel doesn't show

[亡魂溺海] 提交于 2019-12-01 12:07:11
I created a JPanel and i modify it a bit. I change it's background to gradient color here is the class. public class JGradientPanel extends JPanel { private static final int N = 32; private Color color1, color2; public JGradientPanel(Color color1, Color color2) { this.setBorder(BorderFactory.createEmptyBorder(N, N, N, N)); this.color1 = color1; this.color2 = color2; } @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; //Color color1 = getBackground(); //Color color2 = color1.darker(); int w = getWidth(); int h = getHeight();

drawing shape objects in java (draggable,resizable and can rotate)

前提是你 提交于 2019-12-01 10:25:03
问题 I am trying to draw shapes (triangle, rectangle, square and circle) that can be used in creating a picture. A user should be able to place a shape on a canvas and drag it around or even enlarge it to create a desired picture. I tried overriding the paintComponent() of a JPanel to achieve this but realize that the Jpanels shape remains a square so when you have a circle you can still drag it even if u are not necessarily touching it as it is within a square and also having difficulty drawing

Repaint without clearing

拟墨画扇 提交于 2019-12-01 09:51:53
问题 I am working on a program that mimics Paint. The problem is when I draw a new shape the previous shape gets deleted. I tried to comment out my super call of paintComponents which works but leaves behind too much drawing. import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import javax.swing.JOptionPane; import javax.swing.JPanel; public class Canvas1

Java slideshow image delay using paintComponent

岁酱吖の 提交于 2019-12-01 07:41:31
I am putting together a slideshow program that will measure a user's time spent on each slide. The slideshow goes through several different magic tricks. Each trick is shown twice. Interim images are shown between the repetition. Transition images are shown between each trick. On the first repetition of a trick the JPanel color flashes on the screen after a click before the next image is shown. This doesn't happen during the second repetition of the same trick. It's possible that the image is taking too long to load. Is there an easy way to pre-load the images so that there isn't a delay the

Java slideshow image delay using paintComponent

删除回忆录丶 提交于 2019-12-01 05:32:20
问题 I am putting together a slideshow program that will measure a user's time spent on each slide. The slideshow goes through several different magic tricks. Each trick is shown twice. Interim images are shown between the repetition. Transition images are shown between each trick. On the first repetition of a trick the JPanel color flashes on the screen after a click before the next image is shown. This doesn't happen during the second repetition of the same trick. It's possible that the image is

repaint() in Java doesn't “re-paint” immediately?

帅比萌擦擦* 提交于 2019-11-30 22:20:19
I have a code like that: // In MyPanel.java public void paintComponent(Graphics g) { super.paintComponent(g); // Draw something mypanel_count++; } // In Test.java public void testLargeData() { while (notDone) { panel.repaint(); // do huge work test_count++; System.out.println("Test_count: " + test_count + ", MyPanel_count: " + mypanel_count); } } // Output !!! Test_count: 752, MyPanel_count: 23 Test_count: 753, MyPanel_count: 23 Test_count: 754, MyPanel_count: 23 Test_count: 755, MyPanel_count: 24 But when I change panel.repaint() to panel.paintComponent(panel.getGraphics()) , the out is right

How to move the image inside the JApplet in vertical line?

会有一股神秘感。 提交于 2019-11-30 20:36:25
问题 I have displayed an image(ball) inside the JApplet, now I want the image to move in a vertical way (up and down). The problem is I don't know how to do it. Could someone has an idea about this matter? 回答1: You need to set the position of that image to some calculated value (means you caculate the vertical position using time, speed and maybe other restrictions). How you'd set that position depends on how you draw the image. Example, based on drawing in the applet's (or a nested component's)

Rotating Java 2D Graphics Around Specified Point

为君一笑 提交于 2019-11-30 19:41:47
问题 I'm trying to write a program that will draw several shapes rotated around a center point. The result should be something like a Spirograph. I'm trying to test it using rectangles but I can only get two of them to appear in the window. One of them is where it should be, but then after the first rotation it throws the other square way up in the top left corner of the window. It should be rotated and drawn around the center point. Here is a portion of my code. import java.awt.*; import java.awt