Java Swing Chris North cs3724:  HCI
AWT to Swing AWT:  Abstract Windowing Toolkit import java.awt.* Swing:  new with Java2 import javax.swing.* Extends AWT Tons o’ new improved components Standard dialog boxes, tooltips, … Look-and-feel, skins Event listeners API:  http://java.sun.com/j2se/1.3/docs/api/index.html
Swing Set Demo J2sdk/demo/jfc/SwingSet2 Many predefined    GUI components
GUI Component API Java:  GUI component = class Properties Methods Events JButton
Using a GUI Component Create it Instantiate object:  b = new JButton(“press me”); Configure it Properties:  b.text = “press me”;  [avoided in java] Methods:  b.setText(“press me”); Add it panel.add(b); Listen to it Events:  Listeners JButton
Anatomy of an Application GUI JPanel JButton JFrame JLabel GUI Internal structure JFrame JPanel JButton JLabel containers
Using a GUI Component 2 Create it Configure it Add children  (if container) Add to parent  (if not JFrame) Listen to it order important
Build from bottom up Create: Frame Panel Components Listeners Add:  (bottom up) listeners into components components into panel panel into frame JPanel JButton Listener JFrame JLabel
Code JFrame f = new JFrame(“title”); JPanel p = new JPanel( ); JButton b = new JButton(“press me”); p.add(b);   // add button to panel f.setContentPane(p);  // add panel to frame f.show(); press me
Application Code import javax.swing.*; class hello { public static void main(String[] args){ JFrame f = new JFrame(“title”); JPanel p = new JPanel(); JButton b = new JButton(“press me”); p.add(b); // add button to panel f.setContentPane(p);  // add panel to frame f.show(); } } press me
Layout Managers Automatically control placement of components in a panel Why?
Layout Manager Heuristics Left to right, Top to bottom c n s e w FlowLayout GridLayout BorderLayout none,  programmer  sets x,y,w,h null One at a time CardLayout GridBagLayout JButton
Combinations JButton JButton JTextArea
Combinations n JPanel:  BorderLayout c JFrame JPanel:  FlowLayout JButton JButton JTextArea
Code:  null layout JFrame f = new JFrame(“title”); JPanel p = new JPanel( ); JButton b = new JButton(“press me”); b.setBounds(new Rectangle(10,10, 100,50)); p.setLayout(null); // x,y layout p.add(b); f.setContentPane(p); press me
Code:  FlowLayout JFrame f = new JFrame(“title”); JPanel p = new JPanel( ); FlowLayout L = new FlowLayout( ); JButton b1 = new JButton(“press me”); JButton b2 = new JButton(“then me”); p.setLayout(L); p.add(b1); p.add(b2); f.setContentPane(p); Set layout mgr before adding components press me then me
Applets JApplet is like a JFrame Already has a panel Access panel with JApplet.getContentPane( ) import javax.swing.*; class hello  extends JApplet  { public void  init (){ JButton b = new JButton(“press me”); getContentPane().add(b); } } JApplet contentPane JButton
Applet Methods Called by browser: init( )  - initialization start( )  - resume processing (e.g. animations) stop( ) - pause destroy( ) - cleanup paint( ) - redraw stuff (‘expose’ event)
Application + Applet import javax.swing.*; class helloApp { public static void main(String[] args){ // create Frame and put my mainPanel in it JFrame f = new JFrame(“title”); mainPanel p = new mainPanel(); f.setContentPane(p); f.show(); } } class helloApplet extends JApplet { public void init(){ // put my mainPanel in the Applet mainPanel p = new mainPanel(); getContentPane().add(p); } } // my main GUI is in here: class mainPanel extends JPanel { mainPanel(){ setLayout(new FlowLayout()); JButton b = new JButton(“press me”); add(b); } } JApplet contentPane JPanel JFrame JButton or Browser Command line
Applet Security No read/write on client machine Can’t execute programs on client machine Communicate only with server “Java applet window” Warning
In JBuilder

More Related Content

PPT
Java Swing
PPTX
PPTX
Java- GUI- Mazenet solution
PPT
java swing
PPT
Awt and swing in java
PPT
Swing and AWT in java
PPTX
Complete java swing
Java Swing
Java- GUI- Mazenet solution
java swing
Awt and swing in java
Swing and AWT in java
Complete java swing

What's hot (20)

PPTX
Chapter 1 swings
PPTX
Java swing
PPT
Java swings
PPT
Java Swing JFC
PDF
04b swing tutorial
PDF
JAVA GUI PART I
PPT
Graphical User Interface (GUI) - 1
PPT
Basic using of Swing in Java
PPTX
Java Swing
PDF
The AWT and Swing
PPT
Java swing
PDF
swingbasics
PPTX
Java swing
PPTX
Swings in java
PPTX
GUI Programming with Java
PPTX
GUI components in Java
PPTX
tL19 awt
PDF
Java GUI PART II
PPTX
GUI programming
Chapter 1 swings
Java swing
Java swings
Java Swing JFC
04b swing tutorial
JAVA GUI PART I
Graphical User Interface (GUI) - 1
Basic using of Swing in Java
Java Swing
The AWT and Swing
Java swing
swingbasics
Java swing
Swings in java
GUI Programming with Java
GUI components in Java
tL19 awt
Java GUI PART II
GUI programming
Ad

Viewers also liked (20)

PPT
PPTX
Chapter 11.4
PPTX
Power editor basics
PPTX
PPT
011 more swings_adv
PPT
PPT
java swing programming
PPTX
Tinn Capital 2010 piet van vugt
PPTX
2014 naples
PPTX
2014 villefranche
PPTX
Nobel Visie
PPTX
Cloudxp keynote 19 sept pvu
PPT
Oracle 11i OID AD Integration
PDF
Nilai un dan_us_2010_ips
PDF
AMD Putting Server Virtualization to Work
PPT
Cell :: Properties
PDF
IDC Tech Spotlight: From Silicon To Cloud
PPS
Key Compliances in Investing Abroad | Vinita Bahri-Mehra
PDF
Catalyst Eye Tracking: Bing vs Google
PPT
Cap Editing
Chapter 11.4
Power editor basics
011 more swings_adv
java swing programming
Tinn Capital 2010 piet van vugt
2014 naples
2014 villefranche
Nobel Visie
Cloudxp keynote 19 sept pvu
Oracle 11i OID AD Integration
Nilai un dan_us_2010_ips
AMD Putting Server Virtualization to Work
Cell :: Properties
IDC Tech Spotlight: From Silicon To Cloud
Key Compliances in Investing Abroad | Vinita Bahri-Mehra
Catalyst Eye Tracking: Bing vs Google
Cap Editing
Ad

Similar to java2 swing (20)

PPTX
it's about the swing programs in java language
PDF
Getting started with GUI programming in Java_1
PDF
11basic Swing
PDF
Basic swing
PDF
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PPTX
Unit 4_1.pptx JDBC AND GUI FOR CLIENT SERVER
PPTX
PPTX
swings.pptx
PDF
package buttongui; import static com.sun.deploy.config.JREInf.pdf
PPTX
01. introduction to swing
PPTX
A Simple Java GUI Application.pptx
PPTX
Awt, Swing, Layout managers
PDF
Swingpre 150616004959-lva1-app6892
PPTX
09 gui
PPTX
09 gui
PPTX
09 gui
PPTX
UNIT 2 SWIGS for java programing by .pptx
DOC
java swing notes in easy manner for UG students
it's about the swing programs in java language
Getting started with GUI programming in Java_1
11basic Swing
Basic swing
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
Unit 4_1.pptx JDBC AND GUI FOR CLIENT SERVER
swings.pptx
package buttongui; import static com.sun.deploy.config.JREInf.pdf
01. introduction to swing
A Simple Java GUI Application.pptx
Awt, Swing, Layout managers
Swingpre 150616004959-lva1-app6892
09 gui
09 gui
09 gui
UNIT 2 SWIGS for java programing by .pptx
java swing notes in easy manner for UG students

Recently uploaded (20)

PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
Connector Corner: Transform Unstructured Documents with Agentic Automation
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PDF
Advancing precision in air quality forecasting through machine learning integ...
PDF
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
PDF
Electrocardiogram sequences data analytics and classification using unsupervi...
PDF
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
PDF
4 layer Arch & Reference Arch of IoT.pdf
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
EIS-Webinar-Regulated-Industries-2025-08.pdf
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
PDF
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PDF
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
PDF
Build Real-Time ML Apps with Python, Feast & NoSQL
PDF
Planning-an-Audit-A-How-To-Guide-Checklist-WP.pdf
PPTX
Training Program for knowledge in solar cell and solar industry
PDF
Introduction to MCP and A2A Protocols: Enabling Agent Communication
Build automations faster and more reliably with UiPath ScreenPlay
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Connector Corner: Transform Unstructured Documents with Agentic Automation
Rapid Prototyping: A lecture on prototyping techniques for interface design
Advancing precision in air quality forecasting through machine learning integ...
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
Electrocardiogram sequences data analytics and classification using unsupervi...
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
4 layer Arch & Reference Arch of IoT.pdf
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
EIS-Webinar-Regulated-Industries-2025-08.pdf
NewMind AI Weekly Chronicles – August ’25 Week IV
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
Build Real-Time ML Apps with Python, Feast & NoSQL
Planning-an-Audit-A-How-To-Guide-Checklist-WP.pdf
Training Program for knowledge in solar cell and solar industry
Introduction to MCP and A2A Protocols: Enabling Agent Communication

java2 swing

  • 1. Java Swing Chris North cs3724: HCI
  • 2. AWT to Swing AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends AWT Tons o’ new improved components Standard dialog boxes, tooltips, … Look-and-feel, skins Event listeners API: http://java.sun.com/j2se/1.3/docs/api/index.html
  • 3. Swing Set Demo J2sdk/demo/jfc/SwingSet2 Many predefined GUI components
  • 4. GUI Component API Java: GUI component = class Properties Methods Events JButton
  • 5. Using a GUI Component Create it Instantiate object: b = new JButton(“press me”); Configure it Properties: b.text = “press me”; [avoided in java] Methods: b.setText(“press me”); Add it panel.add(b); Listen to it Events: Listeners JButton
  • 6. Anatomy of an Application GUI JPanel JButton JFrame JLabel GUI Internal structure JFrame JPanel JButton JLabel containers
  • 7. Using a GUI Component 2 Create it Configure it Add children (if container) Add to parent (if not JFrame) Listen to it order important
  • 8. Build from bottom up Create: Frame Panel Components Listeners Add: (bottom up) listeners into components components into panel panel into frame JPanel JButton Listener JFrame JLabel
  • 9. Code JFrame f = new JFrame(“title”); JPanel p = new JPanel( ); JButton b = new JButton(“press me”); p.add(b); // add button to panel f.setContentPane(p); // add panel to frame f.show(); press me
  • 10. Application Code import javax.swing.*; class hello { public static void main(String[] args){ JFrame f = new JFrame(“title”); JPanel p = new JPanel(); JButton b = new JButton(“press me”); p.add(b); // add button to panel f.setContentPane(p); // add panel to frame f.show(); } } press me
  • 11. Layout Managers Automatically control placement of components in a panel Why?
  • 12. Layout Manager Heuristics Left to right, Top to bottom c n s e w FlowLayout GridLayout BorderLayout none, programmer sets x,y,w,h null One at a time CardLayout GridBagLayout JButton
  • 14. Combinations n JPanel: BorderLayout c JFrame JPanel: FlowLayout JButton JButton JTextArea
  • 15. Code: null layout JFrame f = new JFrame(“title”); JPanel p = new JPanel( ); JButton b = new JButton(“press me”); b.setBounds(new Rectangle(10,10, 100,50)); p.setLayout(null); // x,y layout p.add(b); f.setContentPane(p); press me
  • 16. Code: FlowLayout JFrame f = new JFrame(“title”); JPanel p = new JPanel( ); FlowLayout L = new FlowLayout( ); JButton b1 = new JButton(“press me”); JButton b2 = new JButton(“then me”); p.setLayout(L); p.add(b1); p.add(b2); f.setContentPane(p); Set layout mgr before adding components press me then me
  • 17. Applets JApplet is like a JFrame Already has a panel Access panel with JApplet.getContentPane( ) import javax.swing.*; class hello extends JApplet { public void init (){ JButton b = new JButton(“press me”); getContentPane().add(b); } } JApplet contentPane JButton
  • 18. Applet Methods Called by browser: init( ) - initialization start( ) - resume processing (e.g. animations) stop( ) - pause destroy( ) - cleanup paint( ) - redraw stuff (‘expose’ event)
  • 19. Application + Applet import javax.swing.*; class helloApp { public static void main(String[] args){ // create Frame and put my mainPanel in it JFrame f = new JFrame(“title”); mainPanel p = new mainPanel(); f.setContentPane(p); f.show(); } } class helloApplet extends JApplet { public void init(){ // put my mainPanel in the Applet mainPanel p = new mainPanel(); getContentPane().add(p); } } // my main GUI is in here: class mainPanel extends JPanel { mainPanel(){ setLayout(new FlowLayout()); JButton b = new JButton(“press me”); add(b); } } JApplet contentPane JPanel JFrame JButton or Browser Command line
  • 20. Applet Security No read/write on client machine Can’t execute programs on client machine Communicate only with server “Java applet window” Warning