Page 2 of 2 FirstFirst 12
Results 21 to 36 of 36
Like Tree1Likes

Thread: How to draw map in java

  1. #21
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: How to draw map in java

    So the task of Kruskal method is done. The MST is found. The HashSet is bad for Parametrized, and it is better for primitives, at least
    <Integer>.
    But I have such issue.
    The cities of Ukeaine are between 22.3 and 38.3 longitude,
    and 45 and 51.5.
    It should be probably
    multiplied for 10 for bettetr visibility on Map. Except it the 1 grade of meridian is 111.3 everywhere
    but the average 1 grade of paralel is 74 km (depsite ratio is veru strict--1.5). I think I could left these two grades the same on Map--I do not see
    it would be very distorted.
    But when using --
    DrawLine(x1,y1,x2,y2) the map is on 90 rorated.
    So what view of DrawLine(x1,y1,x2,y2) -- (City1.latitude,City1.longitude,City2.latitude,Cit y2.longitude):
    Because it appears some very awkward. To upside-down or when coordinates*10, it is too small, but when *20--it is invisible in the whole.
    (City1.latitude--22,52--City1.longitude,City2.latitude--22,52--City2.longitude): to show map in the left upper part of screen???

  2. #22
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: How to draw map in java

    So I want to know why I should use such weird syntax:
    Java Code:
    import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.Font;
    public class Graf extends Frame
    {
    gPanel map = new gPanel();
    public Graf()
    {
    setBounds(10,10,1500,1300);
    add(map);
    setVisible(true);
    }
    public class gPanel extends Panel
    {
    //Vector v = new Vector();
    
    public gPanel()
    {
    //for (int i=0; i<250; i++)
    //{
    //int r = (int)(Math.random()*75);
    //v.add(new Point(i*2,150+r*-1));
    //}
    }
    Mistax g=new Mistax();
    public void paint(Graphics g)
    {
    this.g.createdges();
    for (int j=1; j<this.g.edges.size(); j++)
    {
    City p1=(City)this.g.edges.get(j).City1;
    City p2= (City)this.g.edges.get(j).City2;
    g.drawLine((int)this.g.edges.get(j).City1.y*10,(int)this.g.edges.get(j).City1.x*10,(int)this.g.edges.get(j).City2.y*10,(int)this.g.edges.get(j).City2.x*10);
    Font font=new Font("Times New Roman",Font.PLAIN,14);
    g.setFont(font);
    g.drawString("Karta Ukrainy",270,150);
    }
    }
    }
    public static void main (String[] args) 
    {
    new Graf();
    }
    }
    --for example why it could not cast to int from double autonatically.
    Is it correct to scale to 10--in such way--"City1.y*10"--as
    the map or graph is something unknown for me
    as --is it due to correlation of longitude to latitude coordinate of 1.5--
    Despite the longitude is x.coordinate and latitude is y.coordiante --but the garph is longer from
    and map is upside-down??

  3. #23
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: How to draw map in java

    Peolples, would you tell me, how correctly pass the coordinates to DrawLine ():
    f.e. when City (x=long, y=lat);
    DrawLine (city1.x,city1.y,city2.x,city2.y);
    Because I got something taht I would not like to see: and if 22 most western point, and 52-most northern point in north semi-sphere,
    should it looks like DrawLine (city1.x-22,52-city1.y,city2.x-22,52-city2.y); to be in left-upper corner?

    And the second issue what I got, when
    I tried to draw also the outline of country map-
    from Graph1 class (gr object) with the vector of Points class (v):
    And in the similar cycle---
    Java Code:
     for (int k=0; k<this.gr.v.size(); k++){
    g.drawLine(this.gr.v.get(k).x,this.gr.v.get(k).y,this.gr.v.get(k+1).x,this.gr.v.get(k+1).y);}---in paint method
    ---I get Graf.java:39: cannot find symbol
    symbol  : variable x (or y)--why. The x or y is the filed of Point class --whose vector 
    is defined in Graph1 class -- v.add(new Point(60,20));
    v.add(new Point(270,60));

  4. #24
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: How to draw map in java

    Just now I should return to the issues that I asked in such thread as http://www.java-forums.org/java-2d/9...tionevent.html.
    So its issue is more urgent. I need also create the GUI for this project. So
    I need the button for choosing and uploading the text file data about cities coordinates as well as the button -DISPLAY the map of roads (or two buttons for DISPLAY of all roads and minimal roads).
    1)For the first button it shpould Filechooser, then assigning the name of chosen file for some variable.
    2) In the second case I do not know how connect the button with name for example DISPLAY..with above refered
    class Graf that extends Frame.Could anybody help. As it could take again a lot of time..

  5. #25
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: How to draw map in java

    I just thought I'd point out that bombarding your own thread with posts is likely to put people off helping as there's far too much to read.
    Just ask willemjava who has a tendency to do the same thing.
    gimbal2 likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #26
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: How to draw map in java

    I wish I had put it in so many words to begin with.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #27
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: How to draw map in java

    I am soddry. But I have no time. All my questions I answered here by myself (so example for 23). But any next issue coluld be unresolved moreover in shortened timeframe. Especially taking into account that this project should be committed in meaven, that tested in junit and then in jecnkins (so I have no clues how difficult it would be to do if here would be some inconsistency).
    But now the issue is in GUI.
    So I ask simple question--how create the view class and then link correctly with filechooser event and paint event(s).
    Could the MapGui class like this:
    //
    package recct;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import java.awt.Color;
    import java.util.*;
    public class MapView extends JFrame {
    private JLabel Fchooser = new JLabel(
    "Choose the file for uploading cities coordinates");
    FileChooser FC=new FileChooser();
    FC.addActionListener()
    public void addFchooserListener(ActionListener listenForButton) {
    FC.addActionListener(listenForButton);
    //Can I define FchooserListener class here
    //Or I should define it in particular class: FchooserListener implement Action(or something another)Listener class
    with public void actionPerformed(ActionEvent e) {
    try {
    …with nessesary actions
    } [/code]
    By analogy with the app contemplated in http://www.java-forums.org/java-2d/9...tml#post405259
    Then what about button for showing map (as well as calculating the graph and mts):
    Java Code:
    public JButton button = new JButton("Show the minimum spanning tree for roads");
    public void addButtonListener(ActionListener listenForButton) {
    button.addActionListener(listenForButton);
    }
    So, here againm, where (after it? Or in controller or separate class) to define ButtonListener class:
    It should looks like
    class ButtonListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    …so how to show this method how to launch the paint method of Graph class—simply by creating new Graph class;
    as it defined in its main method:
    Java Code:
     public static void main (String[] args) 
     {
     new Graf();
     }
     }
    Or I am not correct??

  8. #28
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: How to draw map in java

    At least taht I would be glad to know from forum--could I create one view-window in AWT--it just created with the MAP, and another one in JFrame where I need Button and Filechooser with respective Actionlistener(with the reference to Mapview in ActionPerformed). Other I need reformat my mapview class extending Frame.

  9. #29
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: How to draw map in java

    Again, the whole thread is far too long for anyone to pick up and identify what your current issue is.
    But it's your choice...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #30
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: How to draw map in java

    I have simple question--could one view (mapdisplay)-that I have already done in AWT--to be desighned in AWT(FRAME)-
    and another one--GUIView (with file chooser and button--so with 2 action listeners)--to be written in SWING(JFRAME).The first Jrame actionlistener
    do not have any with reference to Frame(Map), another one redirects to Frame.
    So I understand that in second choice I do need just to create new Graf() instance (class of Mapview) in actionperformed method. Despit I would like to
    make and the second button--for showing just mst(minimal ways), when first button--just to show the whole road system.
    Could I do not with repaint

  11. #31
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: How to draw map in java

    Peolple just one question in this vein--
    if all drawing is defined in paint() methods by such cycles as:
    for (int k=0; k<this.gr.v.size(); k++){
    g.drawLine(this.gr.v.get(k).x,this.gr.v.get(k).y,t his.gr.v.get(k+1).x,this.gr.v.get(k+1).y;
    Can I include such another cycle in another method for example drawagain(Graphics g)--and launch it by another button after
    main drawing is made?

  12. #32
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: How to draw map in java

    I do not understand why this code produce
    the -- x --not found symbol?
    Java Code:
    import java.awt.Point;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    public class Graf1 {
    Vector v = new Vector();
    int i=0;
    public void fill()
    {
    v.add(new Point(51,24));
    //v.add(new Point(51.6,24.0));
    //v.add(new Point(51.6,24.0));
    //v.add(new Point(51.6,24.0));
    }
    public static void main (String[] args) 
    {
    Graf1 g=new Graf1();
    g.fill();
    for (int j=0; j<g.v.size(); j++)
    {System.out.println(""+g.v.get(j).x+"");}
    }
    }
    --Do point has no x field? or Y. But it did not worked.
    {System.out.println(""+g.v.get(j)"--just that it worked but why not with x?
    Last edited by ark; 04-29-2015 at 02:06 AM.

  13. #33
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: How to draw map in java

    You are using a raw Vector.
    So as far as the get(j) is concerned it is returning an Object, not a Point. And Object does not have an x attribute.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #34
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: How to draw map in java

    People. Would you help me to resolve this issue. Why System.out.println(""+g.v.get(j)) -- show the whole objects with the fields in quaratic brackets, but System.out.println(""+g.v.get(j).x)--produce--symbol not found -- x or y. Do Point class of Java2D do not have x and y field, as well as methods getY and getX?? I just need to create in such Graf1 class the vector of main definitive points (about 50-thy ones) of border of Ukraine -- and then by Drawline (v.get(i).x, v.get(i).y) to make outline of border connecting the coordinates of neighboring points. But how?

  15. #35
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    5

    Default Re: How to draw map in java

    "You are using a raw Vector.
    So as far as the get(j) is concerned it is returning an Object, not a Point. And Object does not have an x attribute." -- I did not saw just now it.
    So I need to cast to the point?
    Java Code:
     g.v.get(j)).x--> t=(Point)g.v.get(i); then --> t.x?
    But I use the same class City (num,name,x,y) that extends the Point and Symbol do not found error -- the same.
    Despite I succesfully use thesame technic in another class (object) gm, where the vector is m:
    Java Code:
     int o=(int)(this.gm.m.get(i).x*40*1.5); int d=(int)this.gm.m.get(i).y*40; 
    g.fillOval(d-800-5,3200-5-o,10,10);}
    where the 40 is scale coeficient and 1.5 --longitude and latitude ratio.
    Why I could not use it here--the only difference is that the m --vector of cities created by reading the file with the coordinates of cities--
    Java Code:
     m.add(new City(i++,arr[0],Double.parseDouble(arr[1]),Double.parseDouble(arr[2])));
    Last edited by ark; 04-29-2015 at 08:28 PM.

  16. #36
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

Page 2 of 2 FirstFirst 12

Similar Threads

  1. How to Draw Arc in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:12 PM
  2. How to Draw a Rectangle in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:09 PM
  3. How to Draw a Polygon in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:09 PM
  4. How to Draw line in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:08 PM
  5. how to draw in Java
    By Heather in forum AWT / Swing
    Replies: 2
    Last Post: 07-12-2007, 11:01 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •