Drawing 3D Shapes With Java
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
ADVERTISEMENT
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
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
Apr 21, 2015
I've done basic programming in java using Netbeans IDE. So I've good foundational knowledge in java programming. Now I looking forward to draw shapes in java and eventually learn to make simulations. Now I want to learn to create geometric shapes like circle triangle, rectangle etc. I don't know in which Jcomponent(s) should I set the drawing of the shapes, the codes, the libraries and classes I need to import.
View Replies
View Related
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
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
May 9, 2014
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
public class Game extends JPanel implements ActionListener, KeyListener{
Timer t = new Timer(5,this);
double x = 0, y = 0, velx = 0, vely = 0;
[Code] .....
So why doesn't it work and what about the second dot.... ?
View Replies
View Related
Aug 31, 2014
I am trying to get random shapes to generate automatically. I was able to get just three shapes to generate but nothing random. When I added the random code now only the frame shows up and no shapes. I also keep getting an error with frame.setVisible(true). It says identifier expected. Here is what I have so far:
Main program:
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class ShapeGen {
public static void main(String [] args) {
//Create window and set title
draw panel = new Draw();
[Code] ....
This is the draw program to generate random shapes:
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class draw extends JPanel {
public draw(Color backColor) {
setBackground(backColor);
[Code] .....
View Replies
View Related
Oct 21, 2014
Write a class that has three overloaded static methods for calculating the areas of the
following geometric shapes:
• circles -- area = π*radius^2 (format the answer to have two decimal places)
• rectangles -- area = width * length
• trapezoid -- area = (base1 + base2) * height/2
Because the three methods are to be overloaded, they should each have the same name , but different parameters (for example, the method to be used with circles should only take one parameter , the radius of the circle).
Demonstrate the methods in a program that prints out the following areas, each on a separate line:
• the area of a circle with radius 3
• the area of a rectangle with length 2 and width 4
• the area of a trapezoid with base lengths 3 and 5 and height 5
SAMPLE RUN #1
--- Prompts For Keyboard/Console/Standard Input ---
Inputs
Outputs
--- Monitor/Console/Standard Output ---
28.27
8.0
17.5
What The Console Looks Like In An Interactive Session:
(Note: this combines standard input with standard output )
>java Area
28.27
8.0
17.5
THIS IS MY CODE
import java.util.*;
public class Area {
public static double area(double radius)
{
return (double)(Math.PI*Math.pow(radius,2));
}
public static int area(int length, int breadth)
[Code] ....
View Replies
View Related
May 25, 2015
I have a problem in with colissions in JavaFX.
First, I detect a collision between a line and a circle using the follow code:
if(line.getBoundsInParent().intersects(circle.getBoundsInParent())){
System.out.println("Collision!");
}
After this, i need catch the coordinate of collision, like the below figure:
How to catch this coordinate?
[]'s
View Replies
View Related
Apr 28, 2015
Is there some way to create compound shapes/paths in JavaFX?
For the record I'm not implying the use of the methods intersect, subtract, or union. These produce other shapes. A compound shape/path is one that has a knockout of some sort. For instance, a circle within a circle, such as in a 2d donut shape. Alternatives do not include a circle with a thick stroke nor an overlayed circle with the background color. Specifically, JavaFX supports the FillRule, in the case of the Path object. However, there doesn't appear to be an "add" method as there was in the Area shape in Swing.
View Replies
View Related
May 9, 2014
How to draw geometry shapes(line,circle) inside a textarea.
View Replies
View Related
Oct 1, 2014
How to make shapes move at same time when user enter up it should move up. It works for rectangle but i don't know how to move the others like that. (btw i am new to java). How can i do that?
import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
import java.awt.geom.Ellipse2D;
[Code] .....
View Replies
View Related
Feb 16, 2014
I have a problem with a shape generator. It randoms the shapes just fine, I just do not know how to make all the shapes fully stay within the frames border.
RandomShapeMaker.java
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import java.util.Random;
public class RandomShapeMaker extends JPanel{
private static final Random randomShape = new Random();
public void paintComponent( Graphics g ){
super.paintComponent( g );
[Code] ....
View Replies
View Related
Jun 4, 2014
I am currently writing a small drawing program and I am having trouble with changing the size of the shapes. To do this, I have to access the arraylist shapes, check whether pressedX/pressedY is on any of the shapes in the arraylist using the findShape() method and then when released, uses moveBy() in the Rectangle/Oval/Line class and moveShape() in the miniDraw class to move the shape and draw it in the newreleasedX/releasedY position.
So far I think I have pin pointed the problem to being the method in all the shapes classes, that checks whether the pressedX/pressedY which is the on() method, and the findShape() method in the miniDraw class.
This is the minidraw class
import ecs100.*;
import java.awt.Color;
import java.io.*;
import java.util.*;
import javax.swing.JColorChooser;
[Code] .....
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
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