• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I make things in my JFrame?

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

I'm very very new to java swing, and java at all. But I have now maneged to make a JFrame and now I'm trying to put some things in it, and I have been watching very many tutorials, but I can't make it work

I have only got this far:



And I would ask, how I can make something like a rectangle, or string?

Tanks in advance.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A frame is generally used to as a container for other GUI components. If you want to perform custom drawing, use a JPanel. The steps you'd need to do are:
  • write a class that extends JPanel
  • go wild with drawing in that classes's paintComponent method
  • add an instance of that class to the JFrame

  • This is covered in the Sun Java Tutorial in more detail including example code: http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html
     
    Hans vogn
    Ranch Hand
    Posts: 46
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks!

     
    Greenhorn
    Posts: 23
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You can make your class executable by adding a main method as follows



    You should capitalize your class name (frame -> Frame); this is a universal convention of Java programmers. You can then see your empty frame displayed on the screen. As you add stuff to the content pane, you can run your program and watch it appear.

    JMM
     
    Marshal
    Posts: 79179
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    John M Morrison wrote:You should capitalize your class name (frame -> Frame)

    Correct . . .

    But there already is a Frame class, so a different name would be more appropriate.
    reply
      Bookmark Topic Watch Topic
    • New Topic