• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying ellipse onto Jpanel

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new here ! trying to display my data from my Jtable onto my "map" which is a GPanel but have been having difficulty and am not sure how to do this. This is what my output looks like at the moment , https://snag.gy/L67z9O.jpg

My map frame

[


How i read the data to my Jtable


 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch I am not sure what you were doing about code tags, but I sorted it out for you. Please don't post links to sites, because many people are reluctant to click them; under the posting window there is an attachments tab, which you can use to load the screenshot, remembering that screenshots are only suitable for showing pictures or layouts.
I cannot see where you are trying to draw circles as opposed to blobs, but I can only see one minor error in your paintComponent() method. It sho‍uld have protected access. Remember you never call that method directly; leave it to the JVM to call it. You would write something like
g.drawOval(123, 456, 50, 50);
inside paintComponent. If I have got that bit wrong, please supply some more explanation of the problem.
What is the relationship between the locations of the stations and the circles? I can't see an obvious relationship between the numbers in code and those in the // comments
Don't use /* comments */ for commenting‑out. Write // at the beginning of each line, or use something like ctrl‑shift‑C and your IDE will do it automatically. That is because you can get errors if */ appears anywhere in the commented‑out code (i.e. there are any nested comments).
Don't do any file reading inside a frame. You sh‍ould create a separate class which does the reading and creates your model.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you shou‍ld rethink your model. You are using many Strings but you are not dealing with writing. Strings mean writing and locations aren't writing. I think you shou‍ld be thinking much more in terms of objects, and create an object which represents a location. Let's try something. Start with an interfaceYou still want your List<Location>. You can decide whether the implementing classes will produce mutable objects or immutable. You can add more methods to that interface. You decide whether implementing classes have colour or name fields. You decide how to pass a line from the file to the constructor of the implementing classes. Consider whether you want a Shape interface which Location can inherit from. Remember that interfaces can inherit from other interfaces, and mutliple inheritance is permitted for interfaces.
Now what follows is the nice thing about OO programming and polymorphism:-Remember that you can cast the Graphics object to Graphics2D if you need anything more sophisticated than ordinary Graphics provides.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think a new interface is required.
Java already has a built in class called Point which

A point representing a location in {@code (x,y)} coordinate space, specified in integer precision.

 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But do you want your shapes to extend Point?
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Point has some very dubious design features: it has public fields and there is something about its equals method which makes Joshua Bloch use it as an example of what can go wrong with the equals method in subclasses.
 
rey des
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the disorganized code. I have drawn the other ovals on my frame1 class under paintComponent. But I'm trying to access the Jtable or file to be able to get the co ordinate (x,y) to be able to display it on the map. attached is the csv file I am reading
 
rey des
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry looks like I dont know how to attach screenshots -.-
id x.location y.location status patient
A7 17 25 Responding 2
A42 9 31 At Scene 1
A117 1 1 At Station


But this is pretty much the contents
 
rey des
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry looks like I dont know how to attach screenshots -.-
id x.location y.location status patient
A7 17 25 Responding 2
A42 9 31 At Scene 1
A117 1 1 At Station


But this is pretty much the contents
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, your class names should begin with an upper-case letter, so 'Frame1' instead of 'frame1'.

Next, you have a problem on lines 31 and 32 of Frame1:
On line 31, you add txtrKeyAmbulancePatient to the JPanel named 'contentPane'.
On line 32, you add txtrKeyAmbulancePatient to the JPanel named 'PanelKey'. Since a component can have only one parent, this line removes txtrKeyAmbulancePatient from 'contentPane' and instead adds it to 'PanelKey'. (Note: your variable names should begin with a lower case letter, so this should be 'panelKey').

You need to decide which JPanel you want to be the parent of txtrKeyAmbulancePatient.
 
rey des
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry about that I can change it, how should i move forward after this ?
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would approach it this way

1) Create a custom Class say Position which will hold all required parameters. I think you have them as Id, Location, Status, Patient Id. Location itself will be an object which will hold the x and y co-ordinates
2) Subclass JPanel. Have it encapsulate a List of Position objects.
3) Override the paintComponent to iterate over this list. For every Position object extract the Location object and fill the oval for it's x and y
4) Add this to a JFrame

Depending on the work flow requirement
1) Application starts. Initially nothing shows on the screen
2) Ask the user for the source file (JFileChoose)
3) Read source file, parse contents, create Position object from each line and pass it  to the JPanel
4) Invoke repaint on JPanel
 
rey des
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Maneesh I will give it a go cheers !
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

rey des wrote:Sorry looks like I dont know how to attach screenshots -.-


Use the attachment tab on the post/reply screen to attach your images
 
rey des
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Maneesh you suggesting to start from scratch ? Because I have two more files with code on it and spent some time on it.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:I would approach it this way. . .

Slightly different from what I suggested, but the concept of having an object to encapsulate location and type looks similar.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Maneesh Godbole wrote:I would approach it this way. . .

Slightly different from what I suggested, but the concept of having an object to encapsulate location and type looks similar.


Not really. After you pointed out the flaws with Point, which I had initially in my mind

Location itself will be an object which will hold the x and y co-ordinates

 
reply
    Bookmark Topic Watch Topic
  • New Topic