Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 01-25-2008, 01:16 PM
Member
 
Join Date: Jan 2008
Posts: 14
Joe2003 is on a distinguished road
Graphics
Hey

Im trying to add some graphics to an JFrame. I have already made a jframe with loads of panels that hold seperate content. Anyway I want to add a picture, eg this smile app I riped off the net :-

Code:
public TestDraw() { setLayout(new FlowLayout()); setTitle("Changing Face"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(250,220); setLocation(300,300); getContentPane().setBackground(Color.yellow); setVisible(true); } public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); g.drawOval(85,75,75,75); g.setColor(Color.blue); g.drawOval(100,95,10,10); g.drawOval(135,95,10,10); g.drawArc(102,115,40,25,0,-180); g.drawString("Changing Face", 80,175); }
So the class holding the above functions must extend the JFrame, fair enough, but is it possible to add this kind of content to a JPanel? Main problem I have, is that the area im drawing "things" in is a 660 x 430 space within a rather crowded window, and the size of the image may vary (its mapping software) so I dont want to start drawing over other widgets?

any pointers?

thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-25-2008, 07:24 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 251
roots is on a distinguished road
This could be one of the way that you define your own JComponent for your graphics object.
Code:
public class SmilePanel extends JComponent { public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); g.drawOval(85, 75, 75, 75); g.setColor(Color.blue); g.drawOval(100, 95, 10, 10); g.drawOval(135, 95, 10, 10); g.drawArc(102, 115, 40, 25, 0, -180); g.drawString("Changing Face", 80, 175); } @Override public Dimension getPreferredSize() { Dimension dimension = new Dimension(200,200); // Change to required size return dimension; } } ... getContentPane().add(new SmilePanel());
__________________
dont worry newbie, we got you covered.
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
Classes in graphics CyberFrog New To Java 0 04-02-2008 10:11 PM
graphics Joe2003 Advanced Java 4 01-18-2008 08:44 PM
Graphics feniger New To Java 1 12-29-2007 05:22 PM
Adding graphics to array romina Java 2D 1 08-01-2007 02:45 AM
Updating Graphics Greedful Java 2D 2 07-20-2007 08:12 PM


All times are GMT +3. The time now is 02:55 PM.


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