Presentation is loading. Please wait.

Presentation is loading. Please wait.

User Interfaces II GUI – Awt, Swing, Web

Similar presentations

Presentation on theme: "User Interfaces II GUI – Awt, Swing, Web"— Presentation transcript:

1 User Interfaces II GUI – Awt, Swing, Web
(c) IDMS/SQL News

2 User Interfaces - recap
In Java one can create at least 3 types of programs Applet Servlet/JSP Windows Java Class GUI - Introduction (c)

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)

4 GUI - Introduction (c)
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)

5 GUI - Introduction (c)
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)

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)

7 GUI - Introduction (c)
Sample Methods ... Paint(), setFont(), setSize() ... setLayout() setBoarder(), setToolTipText(), setOpaque() ... the list is endless... GUI - Introduction (c)

8 GUI - Introduction (c)
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)

9 GUI - Introduction (c)
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)

10 GUI - Introduction (c)
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 GUI - Introduction (c)

11 GUI - Introduction (c)
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)

12 GUI - Introduction (c)
Applet sample code /*Applet program*/ 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)

Download ppt "User Interfaces II GUI – Awt, Swing, Web"

Similar presentations

Ads by Google