Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-22-2009, 11:27 AM
|
#1
|
|
Member
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301
Rep:
|
JAVA: Popup menu in diffrent class then main Applet, how to repaint()?
In an attempt to better organise my code, I decided to have a main class,
Code:
public class MainClass extends Applet implements MouseListener, MouseMotionListener
and a second DrawMenu class,
Code:
public class DrawMenu extends PopupMenu implements MouseListener, MouseMotionListener, ActionListener
And it works perfect, except that after issuing a command in the menu, I need a repaint() in MainClass... ofc I can't create an instance of MainClass in DrawMenu, can't call MainClass.repaint() as it is not static... so I'm kind of stuck. Is there a proper way to do this, or do I have to put them in the same class?
|
|
|
|
10-22-2009, 06:30 PM
|
#2
|
|
Member
Registered: Sep 2006
Posts: 89
Rep:
|
I assume that your first class creates the instance of the second class.
In which case, simply pass a reference of MainMenu to DrawMenu - either in the constructor, or as a method call after the constructor, and store the reference in an instance variable.
Then, when you need to call MainMenu "repaint" in DrawMenu, you can call it - by using the reference you have saved.
WARNING - TECHNICAL ALERT
But if I was to be honest, I would have to say that this will only work if the routine in DrawMenu was being invoked in the GUI thread, but it might not be - so ignore this caveat :-)
|
|
|
|
10-24-2009, 03:14 PM
|
#3
|
|
Member
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301
Original Poster
Rep:
|
Thanks for your reply
Found another solution, sort of... Made MainClass runnable, and in it, created a "boolean modified", which will be set true if i click something in the menu in the other class.
Then I have a...
Code:
public void run(){
while (true){
System.out.print("");
if (modified){
repaint();
modified=false;
}
}
}
What's with the System.out.print("");? Well, apparently, if I don't have something outside the if that executes on each run, it doesn't work...
So... new question: why is this, and how is it usually done?
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:56 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|