Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-25-2008, 10:23 PM
Member
 
Join Date: Nov 2007
Posts: 8
Lang is on a distinguished road
Trying to use Graphics draw methods
I'm having trouble drawing simple graphics.

This is in my Shuffleboard class
Code:
Board board = new Board("Shuffleboard"); board.setLocation(100, 100); board.setResizable(false); board.setVisible(true);
This is in my Board class
Code:
boardCanvas = new BoardCanvas(); this.add(boardCanvas);
This is in my BoardCanvas class
Code:
super.paintComponent(g); g.setColor(Color.black); for (Weight w : weights){ g.fillOval(200, 200, 50, 50); //g.drawString("Test", 100, 100); System.out.println("Bleh"); }
I know its executing because it is printing Bleh to the console. But no oval is being drawn. There appears to be no error.

My BoardCanvas class extends JPanel - and my Shuffleboard class extends JFrame. Would this be an issue?

Any help is appreciated,
Lang
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-26-2008, 01:49 AM
Member
 
Join Date: Nov 2007
Posts: 8
Lang is on a distinguished road
Ok - I fixed the graphics issues.

However, I can't get the graphics to clear with dispose()

Am I doing something wrong? Is it a different function?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-26-2008, 01:51 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
public class ShuffleBoard extends JFrame { // If Board is a model class and not part // of the componeent hierarchy. Board board = new Board("Shuffleboard"); BoardCanvas boardCanvas; ShuffleTest() { boardCanvas = new BoardCanvas(); this.add(boardCanvas); board.seLocation(100, 100); board.setResizable(false); board.setVisible(true); } } class Board { // This could be some kind of model class. // If so you may not need a reference to // it in the ShuffleBoard class. // If it is designed as part of the component // hierarchy see below. } class BoardCanvas extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.black); for (Weight w : weights) { g.fillOval(200, 200, 50, 50); // g.drawString("Test", 100, 100); System.out.println("Bleh"); } } }
If Board is part of the component hierarchy:
Code:
public class ShuffleTest extends JFrame { Board board = new Board("Shuffleboard"); ShuffleTest() { this.add(board); board.seLocation(100, 100); board.setResizable(false); board.setVisible(true); } } class Board extends Some_JComponent { BoardCanvas boardCanvas; Board() { boardCanvas = new BoardCanvas(); this.add(boardCanvas); } }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-26-2008, 01:55 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
can't get the graphics to clear with dispose()
Don't use dispose to clear graphics.
Set up your painting methods to draw the current state of its enclosing class (the graphic component). Control the state of this class from your event code in this and/or other classes.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 03-26-2008, 03:12 AM
Member
 
Join Date: Nov 2007
Posts: 8
Lang is on a distinguished road
I'm having trouble understanding what you said, hardwired.

When the mouse is released I'd like all the graphics to disappear.

So I tried this:

Code:
public void mouseReleased(MouseEvent e){ this.remove(boardCanvas); startShot = null; endShot = null; }
startShot and endShot are two irrelevant Point variables.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 03-26-2008, 07:49 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Then try adding a call to revalidate
Code:
this.remove(boardCanvas); revalidate()
which tells the parent component to do a new layout.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Draw an arrow Albert SWT / JFace 3 02-01-2008 10:11 AM
help me draw... please... kureikougaiji New To Java 1 01-28-2008 02:22 PM
Draw on JPanel, Help carl Java 2D 1 07-31-2007 08:56 AM
how to draw in Java Heather AWT / Swing 2 07-12-2007 01:01 PM
How to draw a thick line johnt Java 2D 1 05-31-2007 06:27 PM


All times are GMT +3. The time now is 08:43 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org