School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,137 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,912 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 Rate Topic: -----

#1 cmoney12051  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 36
  • Joined: 11-March 09


Dream Kudos: 0

Post icon  Posted 08 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
Was This Post Helpful? 0
  • +
  • -


#2 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 08 May 2009 - 04:57 PM

View Postcmoney12051, on 8 May, 2009 - 04:39 PM, said:

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/...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 :^: :D
Was This Post Helpful? 1
  • +
  • -

#3 cmoney12051  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 36
  • Joined: 11-March 09


Dream Kudos: 0

Posted 08 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
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 08 May 2009 - 05:38 PM

View Postcmoney12051, on 8 May, 2009 - 05:32 PM, said:

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: 08 May 2009 - 05:42 PM

Was This Post Helpful? 1
  • +
  • -

#5 cmoney12051  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 36
  • Joined: 11-March 09


Dream Kudos: 0

Posted 08 May 2009 - 05:54 PM

ok thanks, last question, how do you do mouseovers, like a mouseover for a jbutton? thanks
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 08 May 2009 - 06:11 PM

View Postcmoney12051, on 8 May, 2009 - 05:54 PM, said:

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" :D :D

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
Was This Post Helpful? 0
  • +
  • -

#7 cmoney12051  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 36
  • Joined: 11-March 09


Dream Kudos: 0

Posted 09 May 2009 - 05:23 AM

awsome thanks!
Was This Post Helpful? 0
  • +
  • -

#8 cmoney12051  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 36
  • Joined: 11-March 09


Dream Kudos: 0

Posted 09 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
Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 09 May 2009 - 05:37 PM

View Postcmoney12051, on 9 May, 2009 - 03:50 PM, said:

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/...va.lang.String)
Was This Post Helpful? 1

#11 cmoney12051  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 36
  • Joined: 11-March 09


Dream Kudos: 0

Posted 09 May 2009 - 06:03 PM

thats it, thanks!
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month