• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Paul Nguyen
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.


 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic