• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How do I refresh the JFrame or call the paint method without calling initComponents()? :(  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make a program which calculates the distance between two points which the user gives by clicking on the JPanel. After the points are clicked, dots will be drawn on the points where the users clicked, lines will be drawn to mark the paths, and updates the appropiate JLabels using the Pythagorean theorem and Manhattan distance formulas.

The problem is how do I call my paintEntryPanel method with my graphics argument without having to call initComponents() all the time, because it screws up the display by placing components over each other. I've tried using setters to pass the graphics argument to a global variable, but that doesn't work. I've been taught to use a custom creation code on the JPanel, but I'm not really sure how or why it works and now I'm completely stuck on how to fix the code so I can separate the jPanel and draw function.
Any help would be greatly appreciated.


 
Sheriff
Posts: 21461
96
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just call repaint() on jPanel. This will call it's paint method which calls paintComponent which calls ep.paintEntryPanel.
 
Paul Nguyen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Prime wrote:Just call repaint() on jPanel. This will call it's paint method which calls paintComponent which calls ep.paintEntryPanel.



Oh my god, was that all I had to do? Thanks. It works now.
Now I just got to finish up the rest of the project. Thanks a bunch Rob!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!