NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Using Canvas in NetBeans GUI

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
pedymaster



Joined: 12 Apr 2012
Posts: 1

PostPosted: Thu Apr 12, 2012 9:26 pm    Post subject: Using Canvas in NetBeans GUI Reply with quote

Hi, I am doing a team project to school. It's program where I get some data, process them, enable simple editing and so on... we already have every functions and also have the GUI. The GUI has a lot of buttons, radioButtons and so on.... also it has two canvases. The problem now is that I just cannot figure out how to draw to them.

So created that class JFrame so i have: public class MainGui extends javax.swing.JFrame { .....

there is generated code from NetBeans IDE, listeners for buttons and some other things for the project... also there are those canvases :

canvas1 = new java.awt.Canvas();

canvas1.setBackground(new java.awt.Color(255, 255, 255));

and

canvas2 = new java.awt.Canvas();

canvas2.setBackground(new java.awt.Color(255, 255, 255));


Now, can anyone tell me please how to draw to them? Just an example with a single line, but such that I can paste it to code or something like that.... I've been trying and searching for hours... few days you can say...

Thanks a lot for help.
Back to top
Brenden Towey
Posted via mailing list.





PostPosted: Sat Apr 14, 2012 2:04 am    Post subject: Using Canvas in NetBeans GUI Reply with quote

On 4/12/2012 2:27 PM, pedymaster wrote:
Quote:
Quote:
Hi, I am doing a team project to school. It's program where I get some data, process them, enable simple editing and so on... we already have every functions and also have the GUI. The GUI has a lot of buttons, radioButtons and so on.... also it has two canvases. The problem now is that I just cannot figure out how to draw to them.

So created that class JFrame so i have: public class MainGui extends javax.swing.JFrame { .....

there is generated code from NetBeans IDE, listeners for buttons and some other things for the project... also there are those canvases :

canvas1 = new java.awt.Canvas();

canvas1.setBackground(new java.awt.Color(255, 255, 255));

and

canvas2 = new java.awt.Canvas();

canvas2.setBackground(new java.awt.Color(255, 255, 255));


Now, can anyone tell me please how to draw to them? Just an example with a single line, but such that I can paste it to code or something like that.... I've been trying and searching for hours... few days you can say...


Drawing to a Canvas in NetBeans is the same as drawing to a Canvas without NetBeans. Try reading the manual:

<http://docs.oracle.com/javase/7/docs/api/java/awt/Canvas.html>

Which says "An application must subclass the Canvas class in order to get useful functionality such as creating a custom component. The paint method must be overridden in order to perform custom graphics on the canvas."

So, "new Canvas()" isn't going to cut it because you clearly didn't subclass anything, nor override paint(). Now try making a subclass, who knows, it might work.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo