Shape « Graphics « Java Swing Q&A





1. Custom widget shapes in SWT    stackoverflow.com

I'm trying to work out how to make SWT widgets (e.g. Label, Frame) be some shape other than rectangular. I've made a custom shaped main window using the setRegion() method. Now I ...

2. AffineTransform: scaling a Shape from its center    stackoverflow.com

I'm trying to scale a rectangle from its center using AffineTransform. I'm sure the solution is obvious but I cannot make it work ! Here is what I've tested so far...

import ...

3. rotate shape java2d without losing its origin    stackoverflow.com

protected void paintComponent(Graphics g) {
    Graphics2D gr = (Graphics2D) g.create();
    // draw Original image
    super.paintComponent(gr);

    // draw 45 degree ...

4. Creating a Squircle    stackoverflow.com

I'm a first year programmer. I'm trying to create a squircle. (square with round corners). So far i have managed to get. I have been given the constants of a,b and ...

5. java/swing: converting a text string to a Shape    stackoverflow.com

I want to convert some arbitrary text to a Shape (java.awt.Shape) and then stroke/fill the Shape to draw it. How can I do this?

6. java/swing: Shape questions: serializing and combining    stackoverflow.com

I have two questions about java.awt.Shape. Suppose I have two Shapes, shape1 and shape2.

  1. How can I serialize them in some way so I can save the information to a ...

7. Java Swing custom shapes (2D Graphics)    stackoverflow.com

I need to draw custom shapes. Now when a user clicks on several points on the panel I create a shape using a polygon.

public void mouseClicked(MouseEvent e) {
    ...

8. How to draw 'biohazard' with swing    stackoverflow.com

I'm practicing my swing abilities for the upcoming test, and fried gave me idea to draw biohazard sign like this : alt text I could draw the circles with Elipse2D, but ...

9. Drawing star shapes with variable parameters    stackoverflow.com

I have task to write program allowing users to draw stars, which can differ in size and amount of arms. When I was dealing with basic stars I was doing it ...





10. Guidelines to implement a minimal shape drawing tool desktop application using Java    stackoverflow.com

We need to implement a Java desktop application that allows us (initially) to create / edit / resize / polygons on (initially) images. Then these polygons would be mapped to objects ...

11. Java awt/swing AffineTransformation to move around shapes    stackoverflow.com

A program that animates circles is not drawing them fluidly once several hundred are drawn at once. It was suggested to use affine transformation to copy the shapes. This code, refactored ...

12. How do I draw various shapes in Java ? Which library should I use?    stackoverflow.com

I want to write a program which can draw any type of shape that I assign to it like

  1. Circle
  2. Square
  3. Rectangle
Which library should I use , and how do I go about it ...

13. Changing squares to rectangles in simple a Swing program    stackoverflow.com

I'm having some issues with what is probably a very simple problem in Java. I have written the following program that displays a 10x10 color matrix of squares whose colors are ...

14. Java: line-stroke with filled shape    stackoverflow.com

This is not really important, but it was bothering me for a little while. Problem description:
Given: a line (Line2D)
Wanted: drawing the line as a wedge (Filled GeneralPath) Surely this can be ...

15. Eclipse GEF Shapes Look and Feel    stackoverflow.com

I am creating a gef editor for bpmn2 notations. I am able to create figures in editors, but i am lacking in look and feel of the shapes but i tried ...

16. High level API for creating 2D Shapes in Java    stackoverflow.com

I am seeking an API or program which I can use to create Shapes graphically in Java (specifically closed shapes). A tool simalar to paint in windows, but without ...





17. How to create a custom Java Swing GUI Component with a shape and gradient    stackoverflow.com

I have to create a custom component on my JFrame, the Component will show the storage status of that user, the storage will be in percentage. I need to create something like ...

18. Drawing Arbitrarily Sided Shape    stackoverflow.com

I'm writing a drawing program and one feature I would like to implement is arbitrarily sided shapes. I have most of the features worked out, but one thing I need ...

19. Draw a Shape within paint method    stackoverflow.com

My program is a method to draw a circle on JPanel with multi-thread. The following is a part of my code. I can draw a Image in the paint method, but ...

21. Easy rotation of simple shapes    coderanch.com

23. Fill a shape based on a General Path    coderanch.com

I have an applet that has an inner class that extends JComponent. This inner class has a paint method that draws a number of Stars. The Star class is defined as a separate class that implements Shape in the same package. A Star is made from a GeneralPath. This all works fine. My problem is that I don't know how to ...

24. how to paint some shape over another JComponent    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Test { public static void main(String[] args) { JFrame f = new JFrame(); f.setContentPane(new ContentPanel()); f.setSize(400, 400); f.setVisible(true); } } class ContentPanel extends JPanel implements MouseListener { int x; // hold the click point position int y; // hold the click point position JLabel imageLabel; public ContentPanel() { imageLabel = new JLabel(); imageLabel.setIcon(new ...

25. How do I scale a shape?    coderanch.com

I'm drawing shapes on top of an image using a subclass of JLabel. The problem is the image can be scaled (zoomed) in or out and I need each Shape to be scaled to be larger or smaller with the image. This is pretty easy with something simple like a Rectangle, just multiply the width, height, x and y values by ...

26. draw shapes on video and photos in java    coderanch.com

not sure if this is the right forum but I would like to learn how to write a java swing program(not applet) that can open video files to be played. the main thing i also want to do is be able to draw shapes on top of the video like lines, ovals, rectangles etc. does anyone know how i would get ...

28. Shape.getPathIterator() called w/ null AffineTransform    coderanch.com

Hi. I posted this to the 'other APIs' group a few days ago (because it listed Java2D) and didn't garner any responses, so I thought i would try in the GUI forum. Hello. I've written an object that implements Shape. This object has some crazy coordinates that it uses internally that must be mapped to the screen using a transformation. Consider ...

29. Wanted: How to use Strategy Pattern with Shapes?    coderanch.com

I have three questions (1) How do I refactor Craig's code to use Strategy pattern so I can do for(Myshape shape : Shapes) shape.draw(g2); (2) How do I create a class called TextShape so I can use the above loop with shapes that contain text strings. Craig used "g2.draw(at.createTransformedShape(shapes[0]));" and I cannot figure out how to refactor this. When I pass ...

30. Serializable and Shapes    coderanch.com

Hi, I have a interface called FCShape which I have said extends Serializable. I then have various classes that extend JComponent and implement FCShape. Instances of these classes are then stored in a vector. The problem is that I would like to save this vector to a file using writeObject. This works for other objects but will not work for this ...

31. Extending the Shape class    coderanch.com

Hi Guys, Is there anyway of extending the Shape class. I want to draw a circle with a sqiggle in it - to represent a generator. I need to implement this as a Shape as I want to be able to affine transform it with code similar to the one below. Shape transformedCircle = new Path2D.Double(circle0, atf); In this case I ...

32. Can move shapes individually but not as a group    coderanch.com

Hi Guys, Hopefully as Mr Churchill said "This is the end of the beginning". This code is supposed to drag both shapes individually and shapes as a group. The boolean dragging works fine as a signal to move the shapes individually. The boolean draggingScreen DOES NOT work for dragging all the object. This should happen when a shape is not clicked. ...

33. Problems moving shapes when set up own Shapes class extending Path2D.Double    coderanch.com

Author Problems moving shapes when set up own Shapes class extending Path2D.Double Kieran Murray Ranch Hand Joined: May 18, 2008 Posts: 47 posted Jul 29, 2008 08:21:00 0 Dear Guys, Thank you for your help already. I have now used your previous code and enlarged it so that I can use my own shapes rather than the ones provided. I need ...

34. Overlapping Shapes    coderanch.com

So I've got this problem where I have shape (say a pie-shaped arc) and another shape (say an ellipse), and I want to find out if they overlap. However, not only so I need to find out if they overlap, I need to see if the area that the overlap occurs is more than a third shape (say another pie-shaped arc) ...

35. repainting in shapes other than square    coderanch.com

What I want to do is to repaint a square component but only a portion of it say in a circular shape. Something like.... repaint(10,10,new Circle()) ... I think that gets the point across. I do not want to repaint the entire component just some portion of it in a shape other than repaint(0,0,getWidth(),getHeight()) type of deal. Thanks in advance, Christopher ...

36. drawing 3d shapes?    coderanch.com

37. class who implement shape, paint, draw    coderanch.com

38. Information about moving shapes    coderanch.com

Hello, I have a project in which I feel it would be useful to have some form of animation. Not something too complicated, but a stick figure maybe made up of lines and a circle . I have data that I will be reading from files, and was hoping to be able to use this data to make the stick figure ...

39. previously drawn shapes disappear when new one is created    coderanch.com

I'm trying to make an application that allows the user to draw shapes. It works apart from the fact that when I draw a new shape, the previous one I drew disappears. I want to allow the user to draw as many shapes as they want... Below I am posting code of two classes, MapTab class which contains the DrawingCanvas class ...

40. Shapes return 0's as coordinates, width & height    coderanch.com

Hi, the code below is supposed to allow me to draw mutliple shapes. Currently I'm trying to implement selecting shapes by clicking on them (to be able to drag them to a different location). In the mouseClicked() method, I check whether the user just clicked inside a shape. However, it never returns true. In the mouseExited() method I print width, height ...

41. How to bring a shape to front/back?    coderanch.com

I am looking for a way of determining the order of shapes to be able to move them to in front of/behind other shapes. I did a search and I couldn't find anything useful. I remember that some time ago I saw something about z-value (?) that related to the layering order...

42. Java AWT Intersect Function regarding encapsulated shapes.    coderanch.com

I have been running some tests with the java.awt.geom API and i have a question about the Shape Class and i need to work with specifically the Area implementation. I create 2 shapes, both Path2D types, then convert both to an Area. One shape in completely inside the other. When i do an intersect between the two i get some peculiar ...

43. awt.Shape intersect between different shapes    coderanch.com

Hello, I am trying to make a game for school. In this game I simulate collision by using the .collision function of the awt.Shape 's I am using. Now I am adding an object that is not a rectangle and I see that you can not use intersect for a comparison between different shapes. Is there any build in way to ...

44. Zoom in shape object    coderanch.com

45. Creating a circle shape java swing    coderanch.com

46. Help with Move Shape    java-forums.org

I have been able to create simple forms that can accept and store user entered data, as well as perform multiple actions through the use of buttons. No Problem. Next I would like to work with drawing shapes and giving the user the ability to interact with them. This is where Ive hit a wall. This is probably very simple just ...

47. how to select Shape object after rotation.    java-forums.org

Hi aLL, I have a problem while selecting a Shape Object after rotation has made to that when mouse clicked on that object. I am able to select a shape(Rectangle) Object without rotation(0 Degrees) using contains method in the Shape Object. Pls help me... how to select the Shape Object. Thanks in Advance.

48. Rotated Shape Object Line weight is not retaining properly in printing    java-forums.org

Hi All, I have two rectangle objects one has rotated with 45 degrees another one is without rotation both are have double line thickness. while printing ,the one which is not rotated is printing correctly and another one(rotated shape) is printing thin lines. Pls suggest me to overcome this issue. Thanks in Adance.

49. Help, basic shapes using java    java-forums.org

50. How to fix this code to move this shape?    java-forums.org

Hi guys Below code can draw a polygon whenever the mouse is pressed, but it is also supposed to drag the polygon to move to anywhere the mouse is released. But the polygon doesn't move at all. Does anyone know how to fix it? I believe it must be something wrong in OctagonPanel class, please see my OctagonPanel class below: (public ...

51. A Shape Class    java-forums.org

I am relatively new to java and have recently taken an interest in 3D programming. The following is a class i wrote to create a shape in 3D space that can then be represented as a polygon in a java Applet. The problem is that the driver i wrote to create and display one of these shapes didn't work. I was ...

52. Need help moving a shape!    java-forums.org

Hi, I'm a beginner and recently started to see some of JPanel and graphics. I want to make a small square of 10x10 px. move around the screen by pressing the arrows, one pixel for every time I press the arrow. But I can't! Instead of adding or subtracting one pixel in x or y, it adds or subtracts z pixels ...

53. how can create movable and resizable shapes in java    java-forums.org

I have written a program for my java project on. i have attached the code here. i have to use JPanel.. the program allows users to select some shapes from a box and the important things is that users can move this shapes and also can change the size of them with mouse..both of this action must do with mouse..i just ...

54. Using GUI to select a shape object from and array    java-forums.org

Using GUI to select a shape object from and array Well I'm having a problem trying to access shapes from my arrayList (sample) i have to many different classes to post here but my code is like this for what I'm trying to work out. sample = arraylist of drawingShape DrawingShape = superclass of shapes i have (circle, rectangle ...