Draw Geometry Shapes 2
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
ADVERTISEMENT
May 9, 2014
How to draw geometry shapes(line,circle) inside a textarea.
View Replies
View Related
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
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
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
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
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 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
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
Apr 16, 2015
I have a JPanel embedded in a JScrollPane. I draw in the JPanel, using the paint() method. I have to draw some shapes that can go far in the y direction, that's why I put my JPanel in a scroll pane, in order to scroll down to be able to discover the shapes down. But even though I put my JPanel in a JScrollPane, it soon blocks in the y direction and does not show the shapes far in the y direction.
Note: I used a GridBagConstraints which is correctly set, with its fill attribute etc.
View Replies
View Related
Oct 30, 2014
So I also am working on this problem. My frame does print each new rectangle; however, it is printed each time from the top left corner, and the bottom right is where I click.
Here is my RectangleComponent:
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.util.ArrayList;
import javax.swing.JComponent;
public class RectangleComponent extends JComponent
[Code] ....
View Replies
View Related
Jan 21, 2014
So I drew a menu in DrawingPanel extends JPanel, that gets user input of number of players...etc. I also have a boolean, when true, the board is drawn, but apparently, right when I run, the boolean is checked, returns false and so board isn't drawn at all. When the user finishes input, the boolean becomes true, but the board doesn't get drawn. So my question is, how do I draw something not immediately when the program is ran?
View Replies
View Related
May 26, 2014
I 'm trying to draw a button by resizing a simple button background image to fit the size of the text. Everything works well except for the actual drawing of the string. The y value that I give the Graphics object designates the baseline, however I would like to draw the the string above the y. So that the image below doesn't happen.
I gave the graphics object the y of the bottom of the "P" and would instead like to give it the value of the bottom of the "y". Is there a way to do that by reading the String's bounds or something, or is there a way to get the Graphics object to use the passed y value as the definite bottom of the String?
View Replies
View Related
Apr 8, 2014
If I have a function for example y=x^2
How can I draw the curve?
View Replies
View Related
May 16, 2014
I'm doing a exercise for dragging mouse to draw a line. I found a code to do this, but I don't know something in the code. example array Shape in the code.
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
[Code] ....
View Replies
View Related
May 14, 2014
draw a sequential diagram using java.with out using any other tool or plugins.
View Replies
View Related
Aug 3, 2014
I've tried multiple things but I can't seem to figure out how to get my JButton over the background graphics. On lines 104-108 I create the JButton I need to put on the screen, though I have no clue how to draw it. How I can paint over this background and have my button stay there?
public static final int WIDTH = 1024;
public static final int HEIGHT = 640;
private Thread thread;
private boolean running;
private BufferedImage image;
private Graphics2D g;
[Code] .....
View Replies
View Related
Sep 27, 2014
I'm not looking for answers, well I am.. but not just straight given to me. I'm trying to learn but for this program I'm not even sure where to start. One step looks like this:
O *******
/| * *
/ * *
************
It must increase by a constant named STEPS. They ascend from left and go up right.
I'm just gonna start asking some questions I guess. Before I do anything I wanted to know whether I should have the stick man on the step drawn out with print and println statements or try to have him drawn with a loop as well? I'm not sure if my teacher wants everything drawn by characters with loops for each character, or if I can do print statements and draw the stick figure plus some stars and have a loop for multiple characters at once.
View Replies
View Related
Apr 14, 2015
I've been trying to draw a panel on a frame with simple drawString drawRect and oval but when i run it the frame shows up with the exit on close stuff but nothing will show inside . this is my code :
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JFrame;
class Draw extends JPanel{
public void paintcomponents(Graphics g){
super.paintComponent(g);
g.drawLine(10,15,20,30);
[Code] .....
I'm not sure what's wrong , probably something to do from this pc ? since in the lab work at uni it worked fine .
View Replies
View Related
Apr 21, 2015
So currently I'm trying to learn how to draw a square with asterisks based on the input I give for it's sideLength.
So if I have a Square(5) it should draw a 5x5 looking like this:
*****
*****
*****
*****
*****
but then in the main method, it should draw multiple squares of given sizes, so say 5, 6, and 7. Making a square for each of the given numbers. This is what I currently have so far ....
class Square {
int sideLength; Square( int size ) {
sideLength= size;
} int getArea() {
return sideLength * sideLength;
[Code] ....
View Replies
View Related
Jul 23, 2014
I extracted columns from database and made calculations inside while loop. I know i need to make array to get from it coordinates for points. I want to draw them in interface created in another class but i have black hole and don't know how to get datas from while loop to array which is below.
View Replies
View Related
Jul 31, 2014
I have been trying to add a draw system to my code so far once all the boxes have been taken it does not tell the player its a draw game over. I have tried and deleted some code but I have commented some stuff that did'nt work at the bottom and also the X's and O's can be replaced in the same spaces?
import java.util.*;
//import for scanner
public class NoughtsAndCrosses {
public static int row,col; //integer for rows and columns
public static Scanner scan = new Scanner(System.in); //Scans the program
public static char[][] board = new char [4][4]; //Characters for the board set out 4/4
[Code] .....
View Replies
View Related