Hello everybody in the forum,
I have been using neatbeans tool lately which has helped me a lot in designing and implementing gui applications since everything is created automatically.But i would like to know if,and how(if there exists any designing utility,i can draw my own images,because neatbeans has a limited image selection,and use them in my program.Also can someone recommend me a place where to get any already made libraries with gui classes?
Thank you !
Graphic makerHow to create,draw and use own pictures
Page 1 of 1
9 Replies - 1670 Views - Last Post: 25 June 2010 - 11:27 PM
Replies To: Graphic maker
#2
Re: Graphic maker
Posted 23 June 2010 - 02:33 AM
I had to make a gui where the people would click on an object, place it on the canvas, resize, move, delete etc. When i made these objects (trees, snowflakes, houses, snowmen, etc) i would create them with 2d polygons... It would take a bit to set the objects up and figure stuff out, but when you get the hang of it you really start to scoot along. It is alot easier when you dont have to worry about resizing either. That is what i would use to create my various shapes or were you looking for something else?
I could give you a brief synopsis on how you set it up to start working with polygons. My thing was much more elaborate, but if you want to just draw objects and place them into an automatic spot it should be quick. I implemented a click and drag as well, but that doesnt fall within the realm of doing things in your project as all the objects would be pregenerated and placed.
Oh, but remember, i only know 2d graphics. My friends know 3d graphics, and im sure others on this site know as well, but that is a bit harder. I wasnt sure if you were just wanting 2d things or 3d.
I could give you a brief synopsis on how you set it up to start working with polygons. My thing was much more elaborate, but if you want to just draw objects and place them into an automatic spot it should be quick. I implemented a click and drag as well, but that doesnt fall within the realm of doing things in your project as all the objects would be pregenerated and placed.
Oh, but remember, i only know 2d graphics. My friends know 3d graphics, and im sure others on this site know as well, but that is a bit harder. I wasnt sure if you were just wanting 2d things or 3d.
#3
Re: Graphic maker
Posted 23 June 2010 - 02:18 PM
Just for start i am interested in 2d object and 3d later.I want to draw my objects place them on the screen with and withount using them.
Any tips or info would be really appreciated.Thanks.
Any tips or info would be really appreciated.Thanks.
#4
Re: Graphic maker
Posted 23 June 2010 - 08:46 PM
dimdim80, on 23 June 2010 - 03:18 PM, said:
Just for start i am interested in 2d object and 3d later.I want to draw my objects place them on the screen with and withount using them.
Any tips or info would be really appreciated.Thanks.
Any tips or info would be really appreciated.Thanks.
So DON'T use a GUI generator. It will produce hardly readable code for a human being and it is absolutly unmaintanable.
In the real world, You will never seen an application using GUI generated code. They are good for prototyping, proof of concept and feasibility tests but will never go into production.
Java Swing GUI is really easy to use so write your own.
P.S.
If you have problem with your GUI and you use a GUI generator, don't post the offending code here, we won't even look at it.
#5
Re: Graphic maker
Posted 24 June 2010 - 12:16 AM
Writing Java stuff can be a pain in the butt. I would think that you would want to start looking at tutorials on making polygons in Java. I shall paste in some code snippets to give you a start, but it really depends on what YOU want to do, and will look as crappy or good as the time you put into it.
For each object you want to put in the file, i would make a class for it. Below is my code for a 2d snowflake. I would show you my house, but it isnt as noted up as this one is, and the notes would help you for understanding what stuff does. Are you coding the files so that people draw objects at runtime or is everything preset at compiletime? These are done at compile time, with manipulation at runtime.
I have alot of extra stuff in my class because i can change the size of the items, move them around, etc.
For each object you want to put in the file, i would make a class for it. Below is my code for a 2d snowflake. I would show you my house, but it isnt as noted up as this one is, and the notes would help you for understanding what stuff does. Are you coding the files so that people draw objects at runtime or is everything preset at compiletime? These are done at compile time, with manipulation at runtime.
// CS 401 Fall 2009
// Snowflake class implementation of the MyShape interface. Use this
// example to help you with the other shape classes for your project.
// See comments below for more information.
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
class Snowflake implements MyShape
{
// Build a Snowflake using composition. We are using 4 lines to
// represent our Snowflake
private Line2D line1, line2, line3, line4;
// The predefined Line2D class has a contains() method but it
// always returns false (since a line has no area). However, we
// need our Snowflake to to have area, so I am using a Rectangle2D
// as a "box" around the Snowflake. This is used for the
// contains() method, but it is not drawn, so the user does not
// see it at all. This is a good example of data hiding -- the
// user of a Snowflake does not need to know that a Rectangle2D
// is even present in the object.
private Rectangle2D perimeter;
// X,Y position
private int X, Y;
// size of the Snowflake
private int size;
private boolean isHighlighted;
// Create a new Snowflake. Note how the endpoints of the four
// lines are set to give the Snowflake a nice shape. Also note
// that the perimeter variable is set to allow the Snowflake to have
// area (for selecting purposes).
public Snowflake(int startX, int startY, int sz)
{
X = startX;
Y = startY;
size = sz;
line1 = new Line2D.Double(X,Y,X-size,Y-size);
line2 = new Line2D.Double(X-size,Y,X,Y-size);
line3 = new Line2D.Double(X-size/2,Y+size/2,X-size/2,Y-3*size/2);
line4 = new Line2D.Double(X+size/2,Y-size/2,X-3*size/2,Y-size/2);
perimeter = new Rectangle2D.Double(X-size,Y-size,size,size);
isHighlighted = false;
}
public void highlight(boolean B)/>
{
isHighlighted = b;
}
// Draw the Snowflake "onto" the Graphics2D parameter that is passed
// in. This method will be called from a JFrame or JPanel, which
// is where the Graphics2D object originates. Since a Snowflake is
// really just 4 lines, draw each of the lines. See the Line2D class
// and the Shape interface for more information.
public void draw(Graphics2D g)
{
if (!isHighlighted)
g.setColor(Color.white);
else
g.setColor(Color.red);
g.draw(line1);
g.draw(line2);
g.draw(line3);
g.draw(line4);
}
// All this method is doing is resetting the X and Y coordinates,
// and then updating the lines and rectangle to reflect the new
// location.
public void move(int x, int y)
{
X = x;
Y = y;
line1.setLine(X,Y,X-size,Y-size);
line2.setLine(X-size,Y,X,Y-size);
line3.setLine(X-size/2,Y+size/2,X-size/2,Y-3*size/2);
line4.setLine(X+size/2,Y-size/2,X-3*size/2,Y-size/2);
perimeter.setFrame(X-size,Y-size,size,size);
}
// Note the somewhat sneaky way this is implemented. Note that the
// move method reconfigures the figure using the current size. So
// just call move() using the same X,Y values (i.e. moving 0) which
// ends up resizing the figure.
public void resize(int newsize)
{
size = newsize;
move(X,Y);
}
// Note how simple this method is, since the Rectangle2D class
// already has a contains() method that works as we want it to.
public boolean contains(double x, double y)
{
return perimeter.contains(x,y);
}
// Note how this string is formatted. Your other classes should
// format the string in the same way.
public String className(){
return "Snowflake";
}
public int classSize(){
return size;
}
public String saveData()
{
return ("Snowflake:" + X + ":" + Y + ":" + size);
}
}
I have alot of extra stuff in my class because i can change the size of the items, move them around, etc.
#6
Re: Graphic maker
Posted 24 June 2010 - 08:22 AM
You can use the existing Shapes in the java.awt.geom package for advanced drawing, and you can also use the Graphics and Graphics2D classes to draw some basic shapes like lines, rectangles, and ovals. You'll have to override paint() or paintComponent() in your JComponent subclass and use the Graphics param in these methods to do your painting.
There are plenty of tutorials in the Java Tutorials section on painting if you want to check them out.
There are plenty of tutorials in the Java Tutorials section on painting if you want to check them out.
#7
Re: Graphic maker
Posted 24 June 2010 - 10:09 PM
agreed. There are. I was poking around and you should be set, but if you need any 1 on 1 assistance or anything you can let me know and we can arrange something.
#8
Re: Graphic maker
Posted 24 June 2010 - 10:16 PM
Please keep all work in the forums. By working one-on-one, you all restrict yourselves to fewer opinions, including the wisdom of our Java Experts and Mentors. Plus, the threads remain on DIC forever, so future DICs and Guests can benefit from shared knowledge many times over, which is the whole idea behind DIC.
#9
Re: Graphic maker
Posted 25 June 2010 - 05:17 PM
Thank you all for your answers,i have found some tutorials and already doing them.
#10
Re: Graphic maker
Posted 25 June 2010 - 11:27 PM
Well yea, i was thinking that he may of had questions about my posted code on what the certain things in it were partaining to or help step him through it, was thinking it would be on forums anyways. My bad. >_> ugh..
Page 1 of 1

New Topic/Question
Reply



MultiQuote






|