• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How are GUI components implemented?

 
Ranch Hand
Posts: 545
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off I am happy to be back I have not posted in almost a year,took some time off to focus on other aspects of the computer science field but I have been programming quite a bit just not learning much new stuff,

any who,I have a question and I couldn't find much answers online,how are GUI components such as a JButton or Jframe implemented??

are they written in assembly language,surely you cannot just create GUI components out of nothing,I am guessing assmebly is used,

and if so how is the assembly used to create them?

anybody have any links to how these components are created in code??


thanks
 
Marshal
Posts: 80128
417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know, but try looking for the source. There is a file in most Java® installation folders called src.zip; unzip that and find the code. The Swing components called JXXX are usually written in Java®, but their AWT superclasses may have native methods. I have never looked. For the code, which is probably in C/C++, download an OpenJDK file and unzip that. There are websites that show you some of the code directly without your having to unzip things.

And welcome back I thought I recognised the name. What sort of CS topics have you been doing this last year?
 
Adam Chalkley
Ranch Hand
Posts: 545
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Campbell,

yes long time no speak , I have been mainly focusing on cyber security/ forensics as I have a few repeat exams in them in August,

not much programming mainly static and dynamic analysis of malware but also cryptography,and pen testing(using different frameworks such as metasploit/nmap armitage etc)

the little programming that I have been doing since is mainly with C / C++ but I feel like now having a better understanding of C++ will help me with Java aswell.
 
Bartender
Posts: 15737
368
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome back!

It's important to distinguish between so called "heavyweight" and "lightweight" components. The heavyweight components are implemented through native calls to the windowing system. This is probably done in C or C++ code that is custom to each OS.

Most AWT components are heavyweight, and in Swing, so are the top level containers (JFrame, JWindow, JDialog and JApplet).

Lightweight components are written in Java. They are all the classes that inherit from JComponent. They function by painting themselves on a portion of the top level container using a Graphics object that they receive from the container they're inside of. They receive events to react to by registering listeners with the container they're inside of.

You can actually get a really good feel for lightweight components if you write your own JComponent subclass. If you have never done so, you may start by extending JPanel and overriding the paintComponent() method. Otherwise, it's an interesting challenge to write a completely new JComponent, that also uses the current LookAndFeel when it displays itself.

Finally, for more information refer to the JRootPane class documentation.
 
Campbell Ritchie
Marshal
Posts: 80128
417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:. . . . for more information refer to the JRootPane class documentation.

. . . and in that case, this Java™ Tutorials section might help too.
 
Saloon Keeper
Posts: 28420
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:The heavyweight components are implemented through native calls to the windowing system.



Note "windowing system", not "operating system".

Although some systems - notably Microsoft Windows - incorporate the windowing system as an integral part of the OS, that is not universally the case. In Unix/Linux, the windowing system was typically an X client (client and server have un-intuitively opposite meanings here). On the Commodore Amiga, the OS was in 3 parts - the task and resource managing Exec, the filesystem-managing AmigaDOS (written in BCPL), and the graphical subsystem, which provided graphics layering functions, graphics primitives, windowing functions, and the GUI desktop.

Unix-style OS's are often run without any windowing system at all. My own server farm runs that way. Saves system resources for more profitable functions. This does lead to some problems, however. Not only do GUI systems like Swing, AWT, and SWT depend on an underlying graphics infrastructure, so do things like webapps that generate charts and graphs. In such a case, the JVM has to be configured to run what is referred to as "headless graphics".

Although the JVM will invoke external graphics functions to render graphic objects and - where applicable, interact with an external windowing system, the graphics systems themselves almost always interact closely with the machine's graphics card. That's because modern-day graphics cards are much more efficient at graphics rendering than CPU code and have been ever since the Amiga pioneered graphics co-processors with its "blitter" chip. Thus, you might put a high-performance graphics card in a headless system if that machine was responsible for generating lots of graphic images.
 
Shiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic