Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations

Presentation on theme: "User Interfaces II GUI – Awt, Swing, Web (c) IDMS/SQL News"— Presentation transcript:

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

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

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

4 GUI - Introduction (c) 4 Top Level GUI o Swing Containers – Top Level o - JFrame o - JDialog o -JApplet All three support some common methods like setMenuBar(), getContentPane() J stands for components in Swing... Without J they are usually part of AWT

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

6 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)

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

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

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

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

11 GUI - Introduction (c) 11 Applet Applets are Java classes run from WWW Applets do not have main method Html file will have tags like More on applets later... Sample Java code follows

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

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

Similar presentations

Ads by Google