1 / 12

User Interfaces II GUI – Awt, Swing, Web

User Interfaces II GUI – Awt, Swing, Web. (c) IDMS/SQL News http://www.geocities.com/idmssql. User Interfaces - recap. In Java one can create at least 3 types of programs. Applet. Servlet/JSP. Windows. Java Class. Graphical User Interface. Started with AWT – Abstract Windowing Toolkit

raja
Download Presentation

User Interfaces II GUI – Awt, Swing, Web

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. User Interfaces IIGUI – Awt, Swing, Web (c) IDMS/SQL News http://www.geocities.com/idmssql

  2. User Interfaces - recap • In Java one can create at least 3 types of programs Applet Servlet/JSP Windows Java Class GUI - Introduction (c)http://www.geocities.com/idmssql

  3. Graphical User Interface • Started with AWT – Abstract Windowing Toolkit • Later came Swing • Today AWT components are included in Swing • AWT components are called heavyweight • Swing components are called lightweight • Gui is based on events which are generated by things like mouse, button, list selections, window close operations, menu pulldowns, etc GUI - Introduction (c)http://www.geocities.com/idmssql

  4. Top Level GUI • Swing Containers – Top Level • - JFrame • - JDialog • -JApplet All three support some common methods like setMenuBar(), getContentPane() ‘J’ stands for components in Swing... Without ‘J’ they are usually part of AWT GUI - Introduction (c)http://www.geocities.com/idmssql

  5. GUI Jargons • One of the negative(!) things about new technology is the overuse of common words and known technical words in a totally different sense! • So we hear terms like component, container, layout, listener, Frame, Panel, Window, Dialog ... a never ending list • We have to live with this!!! GUI - Introduction (c)http://www.geocities.com/idmssql

  6. GUI Objects – at lower level • GUI is based on 3 types of objects • Containers - JPanel, JScrollPane etc • Selectors - JButton, JTextField, JCheckBox etc • Info Display JTextArea, JTable etc (editable) JLabel, JProgressBar etc (non-editable) GUI - Introduction (c)http://www.geocities.com/idmssql

  7. Sample Methods ... • Paint(), setFont(), setSize() ... • setLayout() • setBoarder(), setToolTipText(), setOpaque() ... the list is endless... GUI - Introduction (c)http://www.geocities.com/idmssql

  8. Example : GuiSample1 import java.awt.*; import javax.swing.*; // Packages used import java.awt.event.*; public class GuiSample1 extends JFrame { JButton myButton = new JButton("Press Here"); JTextArea myArea = new JTextArea(10,20); public void setupGUI() { setTitle("S212 - Java Crash Course"); myButton.setEnabled(true); Container c = getContentPane(); c.setLayout(new FlowLayout()); c.add(myButton); c.add(myArea); setSize(400,300); } See next Page GUI - Introduction (c)http://www.geocities.com/idmssql

  9. Gui Code continued... // we need a main to instantiate and execute this class public static void main(String args[]) { GuiSample1 dec18 = new GuiSample1(); dec18.setupGUI(); dec18.setVisible(true); dec18.myArea.setEditable(false); // Quit the application when the user 'closes' the Window f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);} }); }//main } // The above code does very little, but is complete. GUI - Introduction (c)http://www.geocities.com/idmssql

  10. GUI .. note ... • The class extends JFrame • Container is created by getContentPane() • setLayout method is used • Buttons etc added by add(...) command • Main () gets controll first • Main instantiate a new object ‘dec18’ • Method setupGUI does the housekeeping... • We utilize a standard ‘WindowsListener’ mechanism to close. A complete example is given as GuiSample1.java GUI - Introduction (c)http://www.geocities.com/idmssql

  11. Applet • Applets are Java classes run from WWW • Applets do not have main method • Html file will have tags like <applet code=“Hello5.class" width=”400" height=”325"></applet> • More on applets later ... • Sample Java code follows GUI - Introduction (c)http://www.geocities.com/idmssql

  12. Applet sample code /*Applet program hello5.java*/ import java.applet.Applet; import java.awt.*; public class Hello5 extends Applet { public void paint(Graphics screen) { screen.drawString("Hello World",50,25); screen.drawRoundRect(20, 40, 100, 100, 30,10); }//end paint() } //End hello5 class. GUI - Introduction (c)http://www.geocities.com/idmssql

More Related