Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 300,303 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,108 people online right now. Registration is fast and FREE... Join Now!




Need Java Help

 

Need Java Help, Make a menu bar, and change line thickness

cmoney12051

8 May, 2009 - 04:39 PM
Post #1

New D.I.C Head
*

Joined: 11 Mar, 2009
Posts: 36



Thanked: 1 times
My Contributions
i am making a paint application and need to have a menu bar at the top, how do you make one? it is a java JFrame. also how do you change the thickness of a g.drawLine. thanks

User is offlineProfile CardPM
+Quote Post


pbl

RE: Need Java Help

8 May, 2009 - 04:57 PM
Post #2

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,533



Thanked: 1123 times
Dream Kudos: 450
My Contributions
QUOTE(cmoney12051 @ 8 May, 2009 - 04:39 PM) *

i am making a paint application and need to have a menu bar at the top, how do you make one? it is a java JFrame. also how do you change the thickness of a g.drawLine. thanks

For the menu bar look at JMenuBar

http://java.sun.com/javase/6/docs/api/java...g/JMenuBar.html

as far as the thickness of the drawLine this a feature of Paint programs not a feature of the GUI. You will have to implement it yourself...by invoking drawLine as often as required for the thickness to want to represent
it is easy for perfectly horizontal and vertical lines (just draw thickness lines one beside the other or even draw a filled rectangle) but when lines have different orientation it becomes a challenge icon_up.gif biggrin.gif
User is online!Profile CardPM
+Quote Post

cmoney12051

RE: Need Java Help

8 May, 2009 - 05:32 PM
Post #3

New D.I.C Head
*

Joined: 11 Mar, 2009
Posts: 36



Thanked: 1 times
My Contributions
ok thanks for that, i got the menu bar working, and am working on the line thickness. how would i go about making an eraser? thanks
User is offlineProfile CardPM
+Quote Post

pbl

RE: Need Java Help

8 May, 2009 - 05:38 PM
Post #4

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,533



Thanked: 1123 times
Dream Kudos: 450
My Contributions
QUOTE(cmoney12051 @ 8 May, 2009 - 05:32 PM) *

ok thanks for that, i got the menu bar working, and am working on the line thickness. how would i go about making an eraser? thanks

you have to store independantly the data of what you have to draw
erasing is simply updating what as to be drawn and call repaint()

the same way if another window occludes yours. When the other window will be iconified your paint() method will be called and you have to be able to redraw everything that need to be drawn (not erased and erased parts)

This is a lot of work... if you have a draw rectangle feature the user can draw a rectangle and you can feel like saving the data: there is a rectangle at X,Y width = height =
Then the user earse part of the rectangle... the rectangle is NOT a rectangle anymore.. it is now a bunch of lines or even pixels

Easiest way is to have an array of pixels the size of your screen and to optimize the way you repaint them... not pixel by pixels :-)

This post has been edited by pbl: 8 May, 2009 - 05:42 PM
User is online!Profile CardPM
+Quote Post

cmoney12051

RE: Need Java Help

8 May, 2009 - 05:54 PM
Post #5

New D.I.C Head
*

Joined: 11 Mar, 2009
Posts: 36



Thanked: 1 times
My Contributions
ok thanks, last question, how do you do mouseovers, like a mouseover for a jbutton? thanks
User is offlineProfile CardPM
+Quote Post

pbl

RE: Need Java Help

8 May, 2009 - 06:11 PM
Post #6

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,533



Thanked: 1123 times
Dream Kudos: 450
My Contributions
QUOTE(cmoney12051 @ 8 May, 2009 - 05:54 PM) *

ok thanks, last question, how do you do mouseovers, like a mouseover for a jbutton? thanks

You won't beleive the number of times somebody replied with a phrase starting by "ok thanks, last question" biggrin.gif biggrin.gif

OK I wrote a Code Snippet on how to track mouse over JLabel but it would apply to any JComponent
Just click on "My contributionms" under my sexy picture and go to the snippet talking about listener over JLabels
User is online!Profile CardPM
+Quote Post

cmoney12051

RE: Need Java Help

9 May, 2009 - 05:23 AM
Post #7

New D.I.C Head
*

Joined: 11 Mar, 2009
Posts: 36



Thanked: 1 times
My Contributions
awsome thanks!
User is offlineProfile CardPM
+Quote Post

cmoney12051

RE: Need Java Help

9 May, 2009 - 03:50 PM
Post #8

New D.I.C Head
*

Joined: 11 Mar, 2009
Posts: 36



Thanked: 1 times
My Contributions
alright so i found your thing is your contributions page, but i cant figure out how to make it display text when the mouse is over the label. how would i implement this using your snippet? thanks
User is offlineProfile CardPM
+Quote Post

pbl

RE: Need Java Help

9 May, 2009 - 05:37 PM
Post #9

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,533



Thanked: 1123 times
Dream Kudos: 450
My Contributions
QUOTE(cmoney12051 @ 9 May, 2009 - 03:50 PM) *

alright so i found your thing is your contributions page, but i cant figure out how to make it display text when the mouse is over the label. how would i implement this using your snippet? thanks

A ToolTipText ?

http://java.sun.com/javase/6/docs/api/java...va.lang.String)
User is online!Profile CardPM
+Quote Post

cmoney12051

RE: Need Java Help

9 May, 2009 - 06:03 PM
Post #10

New D.I.C Head
*

Joined: 11 Mar, 2009
Posts: 36



Thanked: 1 times
My Contributions
thats it, thanks!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 01:15PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month