Results 1 to 20 of 22
Thread: How do i create this board ?
- 10-16-2011, 08:43 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 8
- Rep Power
- 0
- 10-16-2011, 09:57 PM #2
Member
- Join Date
- Oct 2011
- Posts
- 65
- Rep Power
- 0
Re: How do i create this board ?
Do u really want to use awt/swing or is it obligation?
- 10-16-2011, 10:31 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 8
- Rep Power
- 0
Re: How do i create this board ?
I thought thats the only way for creating gui's ....
Last edited by hunterr1234; 11-03-2011 at 07:32 PM.
- 10-16-2011, 11:28 PM #4
Member
- Join Date
- Oct 2011
- Posts
- 8
- Rep Power
- 0
Re: How do i create this board ?
......................................
-
Re: How do i create this board ?
Your question is very general and begs another question: Where exactly are you stuck?
The geometry?
The painting?
And where specifically in either of these subcategories are you stuck?
- 10-16-2011, 11:40 PM #6
Member
- Join Date
- Oct 2011
- Posts
- 8
- Rep Power
- 0
Re: How do i create this board ?
I am sorry but i do not know how to start also ... i am doing my search and learning about the objects in the awt api's nut everything is very absract ...
ThanksLast edited by hunterr1234; 11-03-2011 at 07:33 PM.
-
Re: How do i create this board ?
I would use Swing if a basic game or a 3rd party graphics library if a commercial game, and I'd start with the Oracle Swing tutorials, in particular the graphics section. You need to understand enough basics of Swing graphics before anyone can help you.
- 10-16-2011, 11:57 PM #8
Member
- Join Date
- Oct 2011
- Posts
- 8
- Rep Power
- 0
Re: How do i create this board ?
Yeah okay !!
there is soo much to read man ... i got no enough time ...
anyways i wil get back after reading and learning swings ...
- 10-17-2011, 09:58 PM #9
- Join Date
- Aug 2011
- Location
- Pretoria, South Africa
- Posts
- 27
- Blog Entries
- 4
- Rep Power
- 0
Re: How do i create this board ?
Well... you need to at least have some sup-class of the Window, like the JFrame, JWindow or JDialog... I would recommend using a JFrame as it seems like you are more of a new guy in java, next I would say using the paint method with the Graphics2D class to do some drawPolygon methods, after that its simply adding some JLabels with images representing the coins with DnD(Drag and Drop) capability's and and methods to do what you need. Ir really doesn't seem that hard... we can merely help you with your current code problems and help you in the right directions... otherwise you can also resource to this link
Freelancer.com | Online Jobs | Freelance Employment | Outsourcing Services | Programmers | Web Design | Freelancers
- 10-22-2011, 08:11 AM #10
Member
- Join Date
- Oct 2011
- Posts
- 8
- Rep Power
- 0
Re: How do i create this board ?
Thanks a man
Last edited by hunterr1234; 11-03-2011 at 07:33 PM.
- 10-22-2011, 08:29 AM #11
Member
- Join Date
- Oct 2011
- Posts
- 8
- Rep Power
- 0
Re: How do i create this board ?
Also ??????????????
Last edited by hunterr1234; 11-03-2011 at 07:34 PM.
- 10-22-2011, 07:47 PM #12
- Join Date
- Aug 2011
- Location
- Pretoria, South Africa
- Posts
- 27
- Blog Entries
- 4
- Rep Power
- 0
Re: How do i create this board ?
o my... I hope by this time you know how to use JFrame... lets move over to JPanel... here is some links
Using JPanel as a canvas : JPanel*«*Swing*«*Java Tutorial
Now for some drawing.
Draw a Polygon : Shape*«*2D Graphics GUI*«*Java
and then a good demo of MouseListener.
Demonstrating the MouseListener and MouseMotionListener : Various Event Listener*«*Event*«*Java
- 10-24-2011, 07:49 PM #13
Member
- Join Date
- Oct 2011
- Posts
- 65
- Rep Power
- 0
Re: How do i create this board ?
here some code for you
first array is x points
second array is y points
6 is number of points
Shape p=new Polygon({10,20,30,40,50,60},{20,30,40,50,60,70},6) ;
Graphics2D g=(Graphics2D) JComponent.getGraphics();
g.setColor(Color.blue);
g.draw(p);
g.fill(p); //This method exists.I guest
//JComponent is where you are drawing. Maybe panel
-
Re: How do i create this board ?
Are you seriously recommending this code including recommending to get the Graphics2D object via calling getGraphics on a component? You do understand that this Graphics object will not persist and that anything drawn with it will disappear as soon as anything is repainted, right? And that your Polygon is really nothing more than a straight line, at most a "degenerate" case if you want to call it a polygon and certainly not a regular hexagon.
Perhaps you want to preface this recommendation with your experience and your results when you tested this code.
- 10-25-2011, 05:50 PM #15
Member
- Join Date
- Oct 2011
- Posts
- 65
- Rep Power
- 0
Re: How do i create this board ?
oke then I will write this code after I compile it I will post
That code just abstract code not designed for real stuff
I showed how he can create Polygon and how can draw Polygon thats all
- 10-25-2011, 06:25 PM #16
Member
- Join Date
- Oct 2011
- Posts
- 65
- Rep Power
- 0
Re: How do i create this board ?
*****************************************Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package showthestuff; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Polygon; import java.awt.Shape; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.geom.Area; import javax.swing.JFrame; import javax.swing.JPanel; /** * * @author acer */ public class ShowTheStuff extends JPanel{ int []xArr={100,100,200}; int []yArr={100,200,200}; Shape p=new Polygon(xArr, yArr, 3); Area a=new Area(p); @Override public void paint(Graphics g) { super.paint(g); Graphics2D g2=(Graphics2D) g; g2.draw(p); g2.fill(p); } /** * @param args the command line arguments */ public ShowTheStuff(){ // I write a point x=110 , y =140 then I checked the click on point if(a.contains(110,140)){ System.out.println("Clicked on image"); } this.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // throw new UnsupportedOperationException("Not supported yet."); ShowTheStuff.this.mouseClickedOnImage(e); } @Override public void mousePressed(MouseEvent e) { // throw new UnsupportedOperationException("Not supported yet."); } @Override public void mouseReleased(MouseEvent e) { // throw new UnsupportedOperationException("Not supported yet."); } @Override public void mouseEntered(MouseEvent e) { // throw new UnsupportedOperationException("Not supported yet."); } @Override public void mouseExited(MouseEvent e) { // throw new UnsupportedOperationException("Not supported yet."); } }); } private void mouseClickedOnImage(MouseEvent e) { // throw new UnsupportedOperationException("Not yet implemented"); if(a.contains(e.getX(),e.getY())){ System.out.println("Clicked on image"); } } public static void main(String[] args) { // TODO code application logic here JFrame anew=new JFrame("try"); anew.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); anew.setVisible(true); anew.setSize(500, 500); anew.add(new ShowTheStuff()); } }
Here is a code that creates Triangle and fills inside also detects when mouse is clicked on imageLast edited by Fubarable; 10-25-2011 at 06:34 PM. Reason: Code tags added
- 10-25-2011, 06:28 PM #17
Member
- Join Date
- Oct 2011
- Posts
- 65
- Rep Power
- 0
Re: How do i create this board ?
If someone changes or arranges Xarr and Y arr then you can draw any shape also detects mouse click is on image or not.
-
Re: How do i create this board ?
Moderator edit: Code tags added to post #16
-
Re: How do i create this board ?
I was thinking more along these lines:
Hexagon.java
Java Code:import java.awt.Color; import java.awt.Polygon; import java.awt.Rectangle; import java.awt.Shape; import java.awt.geom.AffineTransform; import java.awt.geom.PathIterator; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; public class Hexagon implements Shape { public static final int SIDES = 6; public static final Color DEFAULT_FILL_COLOR = Color.pink; private static final Color DEFAULT_DRAW_COLOR = Color.blue; private Point2D center; private double shortRadius; private double longRadius; private Point2D[] vertices = new Point2D[SIDES]; private Polygon polygon = null; private Color fillColor = DEFAULT_FILL_COLOR; private Color drawColor = DEFAULT_DRAW_COLOR; public Hexagon(Point2D center, double shortRadius) { this.center = center; this.shortRadius = shortRadius; longRadius = 2 * shortRadius / Math.sqrt(3); int[] xpoints = new int[SIDES]; int[] ypoints = new int[SIDES]; vertices[0] = new Point2D.Double(center.getX(), center.getY() - longRadius); vertices[1] = new Point2D.Double(center.getX() + shortRadius, center.getY() - longRadius / 2); vertices[2] = new Point2D.Double(center.getX() + shortRadius, center.getY() + longRadius / 2); vertices[3] = new Point2D.Double(center.getX(), center.getY() + longRadius); vertices[4] = new Point2D.Double(center.getX() - shortRadius, center.getY() + longRadius / 2); vertices[5] = new Point2D.Double(center.getX() - shortRadius, center.getY() - longRadius / 2); for (int i = 0; i < xpoints.length; i++) { xpoints[i] = (int)vertices[i].getX(); ypoints[i] = (int)vertices[i].getY(); } polygon = new Polygon(xpoints, ypoints, SIDES); } public Point2D getCenter() { return center; } public double getShortRadius() { return shortRadius; } public double getLongRadius() { return longRadius; } public Point2D[] getVertices() { return vertices; } public Color getFillColor() { return fillColor; } public void setFillColor(Color fillColor) { this.fillColor = fillColor; } public Color getDrawColor() { return drawColor; } public void setDrawColor(Color drawColor) { this.drawColor = drawColor; } @Override public boolean contains(Point2D arg0) { return polygon.contains(arg0); } @Override public boolean contains(Rectangle2D arg0) { return polygon.contains(arg0); } @Override public boolean contains(double arg0, double arg1) { return polygon.contains(arg0, arg1); } @Override public boolean contains(double arg0, double arg1, double arg2, double arg3) { return polygon.contains(arg0, arg1, arg2, arg3); } @Override public Rectangle getBounds() { return polygon.getBounds(); } @Override public Rectangle2D getBounds2D() { return polygon.getBounds2D(); } @Override public PathIterator getPathIterator(AffineTransform arg0) { return polygon.getPathIterator(arg0); } @Override public PathIterator getPathIterator(AffineTransform arg0, double arg1) { return polygon.getPathIterator(arg0, arg1); } @Override public boolean intersects(Rectangle2D arg0) { return polygon.intersects(arg0); } @Override public boolean intersects(double arg0, double arg1, double arg2, double arg3) { return polygon.intersects(arg0, arg1, arg2, arg3); } }
TestHex.java
Java Code:import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Stroke; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; @SuppressWarnings("serial") public class TestHex extends JPanel { private static final Color FILL_COLOR = Color.pink; private static final Color SELECTED_FILL_COLOR = new Color(200, 200, 255); private static final Color BORDER_COLOR = Color.blue; private static final int HEX_COUNT = 8; private static final int SHORT_RADIUS = 50; private static final Stroke HEX_STROKE = new BasicStroke(3f); private List<Hexagon> hexList = new ArrayList<Hexagon>(); public TestHex() { int startingX = 5 * SHORT_RADIUS; int startingY = 2 * SHORT_RADIUS; for (int j = 0; j < HEX_COUNT - 1; j++) { int jX = 3 - Math.abs(j - 3); int x0 = (int) (startingX - jX * SHORT_RADIUS); int y0 = (int) (startingY + j * Math.sqrt(3) * SHORT_RADIUS); for (int i = 0; i < jX + 4; i++) { int x = i * SHORT_RADIUS * 2 + x0; Point2D center = new Point2D.Double(x, y0); Hexagon hex = new Hexagon(center, SHORT_RADIUS); hex.setDrawColor(BORDER_COLOR); hex.setFillColor(FILL_COLOR); hexList.add(hex); } } addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { for (Hexagon hex : hexList) { if (hex.contains(e.getPoint())) { Color c = hex.getFillColor(); c = (c == FILL_COLOR) ? SELECTED_FILL_COLOR : FILL_COLOR; hex.setFillColor(c); repaint(); return; } } } }); } @Override public Dimension getPreferredSize() { return new Dimension(2 * SHORT_RADIUS * HEX_COUNT, 2 * SHORT_RADIUS * HEX_COUNT); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (Hexagon hex : hexList) { g2.setColor(hex.getFillColor()); g2.fill(hex); } Stroke originalStroke = g2.getStroke(); g2.setStroke(HEX_STROKE); for (Hexagon hex : hexList) { g2.setColor(hex.getDrawColor()); g2.draw(hex); } g2.setStroke(originalStroke); } private static void createAndShowGui() { JFrame frame = new JFrame("TestHex"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new TestHex()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGui(); } }); } }Last edited by Fubarable; 10-25-2011 at 08:39 PM.
- 10-28-2011, 05:01 PM #20
Member
- Join Date
- Oct 2011
- Posts
- 65
- Rep Power
- 0
Similar Threads
-
How to share the text Area in White Board?My White Board is in BigBlueButton
By nirasiva in forum New To JavaReplies: 2Last Post: 06-29-2011, 09:08 AM -
how to create a monopoly board using java?
By dizzymj17 in forum AWT / SwingReplies: 4Last Post: 04-18-2011, 02:38 PM -
TINI Board
By ApheoXAIO in forum New To JavaReplies: 1Last Post: 07-03-2010, 12:52 PM -
How to do a score board?
By vlan in forum Java AppletsReplies: 11Last Post: 06-03-2010, 10:10 AM -
how to create board in java...
By zenith in forum New To JavaReplies: 5Last Post: 01-20-2010, 04:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks