LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
LinkBack Search this Thread
Old 10-27-2005, 05:47 PM   #1
z24561
LQ Newbie
 
Registered: Oct 2005
Posts: 1

Rep: Reputation: 0
JAVA: Graphics problem


ok, I may be a to this forum, but I'm not a newbie to Linux nor Java.

That being said, I have a problem with ActiveRendering on Linux. At home I have a Mac (running Tiger - 10.4) and it runs the program well. I do have to resize the window to get it to display anything but it still works. In Linux, no matter what I do, it displays nothing.

I have been modifying code that did work considerably well, it was just not as efficient. The main problem was that some of our components need to render themselves first before they can know their exact width and height. So, when the Components are added to the TopWindow (which actually contains a JFrame) it needs to call their render(Graphics2D) method. The problem with being able to do this is that I need to create the JFrame, pack it, and then JFrame.setVisible(false). Somehow, the Graphics and BufferStrategy get disconnected with the global JFrame in TopWindow. Here's some code:

This is in the Constructor:
visible = false;
container = new JFrame(title);
container.addMouseListener(this);
container.addKeyListener(this);
container.addMouseMotionListener(this);
container.pack();
container.createBufferStrategy(2);
strategy = container.getBufferStrategy();
g2d = (Graphics2D) strategy.getDrawGraphics();
container.setVisible(visible);

add(Component):
public void add(Component element) {
listOfComponents.add(element);
element.addObserver(this);
element.render(g2d);
}

I thought that maybe the problem lay in the fact that the graphics are never disposed of nor the strategy shown. But in renderAll() (the call made when we just want to re-render everything, such as on resizing or moving the window) if I dispose of the graphics and show the strategy, it still doesn't work. I do have mouseListeners and ActionListeners set correctly with the TopWindow as the parent of all the Components, and they work. Also, before actually displaying the window but aftert all the elements are added to it, I have these lines:

container.setBounds(this.alignmentX, this.alignmentY, this.width,
this.height);

// Disable repainting to be able to use accelerated-mode
container.setIgnoreRepaint(true);

container.setResizable(true);

// automatically renders when resized or moved
container.addComponentListener(this);
container.addWindowListener(this);

Help! This is for a class and it's really bad if you have to say, "Oh, don't worry about not seeing anything, it's all there, just imagine it." I don't think they'll accept that.
 
Old 10-28-2005, 10:37 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Are you - or would you consider - overriding the "update()" method, and having it call "paint()":

EXAMPLE:
public void update(Graphics g) {
paint (g);
}

And if you're not already doing it, double-buffering might solve the problem ... and give you a much speedier, cleaner display to boot. Here's one example:

http://www.codeproject.com/java/javadoublebuffer.asp

'Hope that helps .. PSM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
graphics with java simcox1 Mandriva 3 04-02-2005 11:55 AM
java Graphics[2D] requires an X server? Cand1e Programming 12 02-18-2004 07:18 AM
Java Graphics in Linux hiteshmaisheri Linux - Software 10 02-08-2004 10:39 AM
graphics problem d_lake Linux - General 1 03-11-2003 06:46 PM
Graphics problem frkstein Linux - General 6 02-22-2002 06:50 PM


All times are GMT -5. The time now is 02:17 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration