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 08-03-2007, 05:51 PM
Member
 
Join Date: Jul 2007
Posts: 39
christina is on a distinguished road
Canvas question
I have to do an APButton on a canvas that is to say when I click/press any where in the canvas it should create a button(rectangle) "fillRect(0,0,30,30);"

any ideas?
how can I do that?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-03-2007, 08:21 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,053
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PaintHere extends JPanel { int x = -30; int y = -30; public PaintHere() { addMouseListener(clicker); } protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.drawRect(x, y, 30, 30); } private MouseListener clicker = new MouseAdapter() { public void mousePressed(MouseEvent e) { x = e.getX(); y = e.getY(); repaint(); } }; public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new PaintHere()); f.setSize(300,300); f.setLocation(200,200); f.setVisible(true); } }
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
Calling displayable from a canvas class Snalk CLDC and MIDP 0 03-29-2008 12:58 AM
Using SWT Canvas Java Tip Java Tips 0 01-08-2008 10:06 AM
SWT Canvas JavaForums Java Blogs 0 12-31-2007 05:53 PM
Canvas rendered over JCombobox menu JSK AWT / Swing 2 11-19-2007 09:00 PM
Question mark colon operator question orchid Advanced Java 3 04-30-2007 11:37 PM


All times are GMT +3. The time now is 03:14 AM.


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