Drawing Animations In Java (SWT)
Apr 21, 2014
I've got a question about drawing animations in Java (SWT). I try to draw an animation of some process.
When i use canvas.redraw() it seems like program firstly erases everything that has been drawn and then draws again.
My program draws about 1000 of rectangles per time step so animation doesn't looks smooth - it blinks all the time and I can't avoid drawing that many rectangles.
Is there a way to make it look smoother (for example to paint new objects over old ones, without erasing them)?
I won't paste code, it's rather large.
View Replies
ADVERTISEMENT
Feb 17, 2014
I have a problem which can't solve it for 2 days search. I need to draw 3d shapes , i downloaded all packages and set an example code and run it ...
Exception in thread "main" java.lang.UnsatisfiedLinkError: no J3D in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java :1886)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1088)
[Code] ....
View Replies
View Related
Nov 20, 2014
I use a program called eclipse. I want to know how to build a house with the program. We use a pen in java. It is a drawing tool. I dont know how to do it.
View Replies
View Related
Mar 4, 2015
rJ38Sk0.jpg8xPkese.jpg
So I'm supposed to draw this flag using java grids, here is what i currently have.
int height = grid.getHt();
int width = grid.getWd();
//Paint everything Blue
for(int c=0;c<height;c++){
for(int d=0;d<width;d++){
grid.setColor(c,d,Color.CYAN);
[Code] ....
at size 9 it looks fine, but at size 12 it is missing a black dot. How can I solve this?
View Replies
View Related
Nov 4, 2014
Java 2D Drawing Application. The application will contain the following elements:
a) an Undo button to undo the last shape drawn.
b) a Clear button to clear all shapes from the drawing.
c) a combo box for selecting the shape to draw, a line, oval, or rectangle.
d) a checkbox which specifies if the shape should be filled or unfilled.
e) a checkbox to specify whether to paint using a gradient.
f) two JButtons that each show a JColorChooser dialog to allow the user to choose the first and second color in the gradient.
g) a text field for entering the Stroke width.
h) a text field for entering the Stroke dash length.
I) a checkbox for specifying whether to draw a dashed or solid line.
j) a JPanel on which the shapes are drawn.
k) a status bar JLabel at the bottom of the frame that displays the current location of the mouse on the draw panel.
If the user selects to draw with a gradient, set the Paint on the shape to be a gradient of the two colors chosen by the user. If the user does not chosen to draw with a gradient, the Paint with a solid color of the 1st Color.
Note: When dragging the mouse to create a new shape, the shape should be drawn as the mouse is dragged.
Java Code:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
[Code] ....
Missing things for the code check boxes for color gradients, line width and dashed.
View Replies
View Related
Jul 14, 2014
I'm trying to draw an image in grayscale. This is my code:
Java Code:
public void paintComponent(Graphics g) {
super.paintComponent(g);
setOpaque(true);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
Graphics g1 = image.getGraphics();
g1.drawImage(CardData.CARD_ART[cardID], 0, 0, null);
g1.dispose();
setOpaque(false);
} mh_sh_highlight_all('java');
For some reason, nothing displays.
View Replies
View Related
May 28, 2014
I have to write a program for class that basically uses Paint Component to draw a bunch of rectangles to look like a building then have them change color randomly. I am stuck I can't figure out how to make it draw the rectangles in rows and columns to look like the building i can make it display multiple squares randomly however but thats not the assignment.. here is my code
package labBuilding;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class Building extends JPanel {
[code]....
View Replies
View Related
May 1, 2014
import java.awt.*;
public class Program5 {
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(300,500);
panel.setBackground(Color.white);
Graphics g = panel.getGraphics();
g.setFont(new Font("Helvetica", Font.PLAIN, 12));
double ball = 10;
[code]....
I'm fairly new to Java and am having a hard time with this particular assignment. The program runs and shows up on the drawing panel fine but I can't get the lines quite right.Capture.jpg
View Replies
View Related
Apr 23, 2015
solve my problems regarding drawings on my JPanel(Transparent panel).My Jframe & other components are created by netbeans GUI builder & the transparent panel is created manually but one problem is that i can't impose this Transparent panel into JFrame like it is attached to the JFrame.Another problem is that,i want that transparent panel size should be counted in inch like my attached picture(TOTAL SIze 36 inch) & also when i clicked on that panel those mouse points highest distance should be measured in Inch.How can i do all of these three task??
View Replies
View Related
Jun 17, 2014
I have a question about the execution of code to draw images relative to code that comes after that. I don't normally do this sort of thinghere's the problematic code:
int stn = 0;
while (stn < 10)
{
glb1.xOfText += 20;
glb1.yOfText += 20;
gc1.drawImage(glb1.img1 , glb1.xOfText , glb1.yOfText);
TimeKeeper.pause(500);
stn++;
}
Where glb1 is a final reference to an object that holds common data for the game.while its x and y values say they are for text, they are also used for image placement (at least during this testing phase.)
gc1 is the "graphics context" of the canvas that the images are being drawn on.
The person who wrote this said, "When the attached code is run, the calls to TimeKeeper.pause(500), which in turn call Thread.sleep(500), are all executed in row, and then the results of drawing the image 10 times is displayed. (I know because some of the previous image pastes left some visual data behind.)"
I recall from reading about drawing graphics (a long time ago) that drawImage() could take time, but I don't know why the thread does not indeed sleep between calls to drawImage().
View Replies
View Related
Dec 20, 2014
how to phrase the question. I created a small applet in java.. it allows me to move a toon around a blank applet window. I am using four gif files that have a walking animation in them. The issue i am having is after moving around the gif just flashes in and out really quickly.. when i start the program, moving up and down seems to be working perfectly fine, but the moment i move left or right it starts messing up for all directions. here is my code.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CharactorMove extends JApplet implements KeyListener
[code]....
View Replies
View Related
Feb 7, 2014
I am trying to draw an image unto the screen, however, nothing appears...
Java Code:
private ImageIcon i = new ImageIcon("image.png");
private Image image;
...
image = i.getImage();
...
g.drawImage(image, (int)(x - r), (int)(y - r), null); mh_sh_highlight_all('java');
Am I doing it right? The program gives me no error, it's just that when I try to draw it, I see nothing.
View Replies
View Related
Mar 17, 2014
I am having issues with drawing shapes from bottom right to top left.
Issue:
- g.drawRect() will show like I am calling g.fillRect()
- other shapes will not even show the shape in that area
Needs:
- g.drawSHAPE needs to show and not be filled unless I have my fill checkbox selected
The Program:
- Create a JFrame with a draw panel and a component panel
- have a combobox with shapes that, when selected, will draw that shape in the draw panel
- have a button that, when clicked, will launch JColorChooser to change the color of the drawn shape (draw panel is set to black)
- have a checkbox that, when checked, fills the shape
- have mouse listeners to adjust X and Y and will instantly update the shapes size to where you drag/click/press/release
Code for my drawRect():
Java Code:
// if statement to check if mouse drag X is less than starting X
if(x2 <= x){
if(emptyORfill.isSelected()) // emptyORfill is my JCheckBox
g.fillRect(x2, y, x-x2, y2-y); // x-x2 is the same as Math.abs(x2-x)
else
g.drawRect(x2, y, x-x2, y2-y);
[Code] .....
This is just for my Rectangle. This will show a filled rectangle when both mouse drag X and Y are less then the starting X and Y. If I take this fully functional code and adapt it to drawRoundRect(), the round rectangle wont even show the shape when mouse drag X and Y are less than the starting X and Y but will be fine if one or the other is less than the starting X or Y. NOTE: This same exact code worked on my classmates laptop in her program, but in my program on her laptop it did not. She took out the "else" in the else if's and just made them if statements all the way down and it worked on her laptop in my program, but the same "fix" did not work on my pc.
My mouse listener just sets X and Y values in my Shape class that updates my shape methods. I have an item listener for my comboBox that sets default values when a new selection is made and enables/disables editable on my fill checkbox for certain shapes. My action listener looks for the button click and the checkBox click.
View Replies
View Related
Oct 21, 2014
I've just started working on a program and I'm already having difficulties with the program. I can't get the background color to change from the basic gray color.
Java Code:
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import java.awt.*;
import java.lang.Object;
import java.awt.Color;
public class FrameDemo{
[Code] .....
View Replies
View Related
Aug 6, 2014
I am trying to make a GUI that allows the user to input the NumberLink puzzle (through mouse action events), and then, displays the puzzle in a grid with features to draw a path, and undo it. This is almost exactly the same functionality as in Numberlink on Nikoli
1. In my project, I have a Stage in which a setup scene prompts user for rows and columns (to take size of puzzle),
2. Then, it generates an empty grid (I'm thinking of using a GridPane here), and the user clicks the squares to enter the numbers into the square. this phase isnt a problem if I use text fields and mouse listeners and store info in a grid... the next phase is what I'm stuck at... unless I know exactly how to do that, I cant make progress...
3. In the third stage, I have to display the numbers to the user just like on the Nikoli site (the highlighting number pairs on mouse hover is a necessary feature too, which I think I can handle with CSS).. and the user should draw paths between the numbers, just as on that site ( I thought VLineTo and HLineTo classes would be suitable.. but I'm not sure, and cant find any alternatives) .....
So with this in mind, I made FXML based dummy gui layouts to test if my ideas work... And I cant get the GridPane to have lines drawing atop it (meaning, I cant place Line objects like HLine on top of the grid panes).... is there any other way to do what I need to do ? I also thought of making canvases in a grid (each square is its own canvas)
How I can implement a user inputted path drawing ??
View Replies
View Related
Jun 30, 2014
I have to do an assigment using Swing, where I have to make a Board(extends JPanel) and add multiple instances of moving elements to it, with following requirements:
By adding a new object to the Board, the others must not slow down. Also the user interface must not be blocked by the moving objects. So, the movement of the objects must be handled in a separate thread.
and
The application must support adding lots of objects, so it is not okay if every object has its own thread, as this would take too many resources. Design the application in such a way that it uses a constant number of threads, meaning that the number of threads does not grow when adding more objects.
The question is:
How to do this thing with constant number of threads?
View Replies
View Related
Nov 13, 2014
The program is where you will click anywhere in the jframe and it will draw a new rectangle. I have altered the code given to us but the problem that I am having is the fact that when I click the rectangle will always be connected to the upper left hand part of the jframe, no matter where I click. The program should create rectangles of the same length and width wherever you click. Here is what I have. I believe I have to change something in the addRectangle method, but nothing that I have tried works.
Java Code:
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
import java.util.ArrayList;
public class RectangleComponent2 extends JComponent
[Code] .....
View Replies
View Related
Feb 6, 2014
Ok. So I have decided that taking a step back is better than trying to go forward blind. I am trying to come to an understanding of how java draws simple shapes, but continue to run into problems. I have now gone ahead and directly copied code from a book just to see if it will work. It does not. The code is just supposed to make a smiley face, but when I run it I get a bunch of errors. I have attached the code that I am trying to run and the error report at the bottom.
Java Code:
import javax.swing.JFrame;
public class DrawSmileyTest
{
public static void main( String[] args );
DrawSmiley panel = new DrawSmiley();
JFrame application = new JFrame();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add( panel );
[Code] ....
9 errors found:
File: /Users/brad/Documents/Courses/Mobile App Development/Java Intermediate/Assignments/Assignment 1/DrawSmileyTest.java [line: 10]
Error: /Users/brad/Documents/Courses/Mobile App Development/Java Intermediate/Assignments/Assignment 1/DrawSmileyTest.java:10: <identifier> expected
[Code] .....
View Replies
View Related
Jul 3, 2014
Gyazo - e5663e8da42ac46a642895d72836b933.png
As you can see I have specified a file path, as it is needed to draw the image.
The image "sun" is in a certain folder inside the directory of my jar file.
But If I were to send the whole package to my teacher to review. The file path would still remain the same, local to my computer making the image, unloadable.?
View Replies
View Related
Jun 12, 2014
I am trying to draw at my mouse a certain shape that I have set. I defined some shapes where they extend shape and draw circles and stuff. But when I click on panel it seems the paint doesnt put anything there. Debugger tells me shapes are saved though.
public void mouseClicked(MouseEvent e) {
currentX = e.getX();
currentY = e.getY();
Shape newShape = owner.currentBrush.clone();
picture.add(newShape);
repaint();
[Code] ....
View Replies
View Related
Nov 6, 2014
I am buildning a paint application in java, where the user can choose from a combobox wheather he/she wants to draw a rectangle or by free hand. The objects are stored in an arrayList. The user can also choose in the menubar to go back one step, which means to remove the last drawn item from the arrayList and then loop through the arraylist to draw the remaining objects.
It works fine with rectangles. When I create a rectangle it creates only one rectangle, which I add to the arrayList.
My problem is with the free hand. When I draw by free hand (using mousePressed and mouseDragged) I add every "dot" of the line as an object. Which means that when I remove the last item in the arrayList it only removes one dot of the line, not the whole line.
I need to add the dots together as one line, but how can I do that?
if (e.getSource().equals(comboBox)) {
JComboBox cb = (JComboBox)e.getSource();
if (cb.getSelectedItem().equals("Rectangle")) {
this.addMouseListener(new MouseAdapter() {
[Code] .....
View Replies
View Related
Jan 16, 2015
I'm trying to make a simple program that will feature some graphics. It will have a JCombobox that the user selects to draw various shapes. I can't get the repaint function to work however.
package selectingshapes;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JPanel;
import java.awt.Graphics2D;
[Code] .....
View Replies
View Related
Aug 29, 2014
I have a method that draws a polygon on the screen:
public void poly(List<Point> points) {
//code
}
For the usage of the method, it makes no difference whether points is an array or a List. In fact, switching doesn't even change any of the code in the method since I use a for-each loop. So, my question is, is it a better practice to use a List as an argument, or an array when the method itself doesn't care about which to use?
View Replies
View Related
Sep 9, 2014
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
import com.googlecode.javacv.cpp.opencv_core.CvMemStorage;
import com.googlecode.javacv.cpp.opencv_core.CvPoint;
import com.googlecode.javacv.cpp.opencv_core.CvScalar;
import com.googlecode.javacv.cpp.opencv_core.CvSeq;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_highgui.CvCapture;
import com.googlecode.javacv.cpp.opencv_imgproc.CvMoments;
[code]....
Everything works in this except the part where drawing a convexhull and the convexitydefects around an object. Drawing circle around the COG works OK. I tried to draw them with these lines but no luck.
hullSeq = cvConvexHull2(bigContour, hullStorage, CV_COUNTER_CLOCKWISE, 0);
defects = cvConvexityDefects(bigContour, hullSeq, defectsStorage);
cvDrawContours(img1,defects , CvScalar.BLUE, CvScalar.BLUE, 1,0,0);
cvDrawContours(img1,hullSeq , CvScalar.BLUE, CvScalar.BLUE, 1,0,0);
View Replies
View Related
Jul 15, 2014
I am subclassing a Pane to be able to use my custom NGRegion:
public class MyPane extends Pane {
@Override
public NGNode impl_createPeer() {
return new MyNGRegion();
}
}
in MyNGRegion i override renderContent(Graphics g) for custom drawing
@Override
protected void renderContent(Graphics g) {
/* custom drawing */
}
The custom NGRegion gets drawn one time, but i want to continuously draw on every pulse.
i already tried a lot of things, but don't see how to do it properly:
using -Dprism.forcerepaint=true did not work.
overriding clearDirty() and set it
View Replies
View Related
Sep 19, 2014
So Ive got to make a turtle on an image draw a semicircle that starts at the top of a circle and goes down and to the left, changing colors halfway through. I've got everything down, I can draw the turtles and make them do straight lines. My problem is more math related. I need to use the equation of a circle, give it points, and figure out how to write that code in java.
We use the equation for a circle: (x - a)^2 + (y - b)^2 = r^2
amanda.setName("amanda");
amanda.setShellColor(Color.BLUE);
amanda.setBodyColor(Color.RED);
amanda.setPenColor(Color.YELLOW);
amanda.setPenWidth(3);
amanda.forward();
amanda.turn(-90);
amanda.setPenColor(Color.BLUE);
amanda.forward(???);
the question marks are where I need to draw a line on an arc, like in the picture.
View Replies
View Related