IT 3203 Introduction to Web Development Java and the Web IA and the Enterprise November 26 28 Study Abroad Spend July in Madrid Informational meeting: Wednesday, November 28 3:00 pm in Room J-308 http://spsumadrid08.blogspot.com/ Notice: This session is being recorded. Copyright 2007 by Bob Brown Java Applets This is not a Java course! (You re supposed to know about Java.) Our goal is to learn when and how to use Java in Web Development, not how to write Java programs. public class myapplet extends JApplet { or applet There is More to Java than Applets Java is a programming language Java applets take advantage of a part of Java Applets are restricted by the browser For client-side. There are servlets for the server side. Advantages of Java Applets Good support for graphics Powerful programming language Large collection of classes This will be on the exam. Disadvantages of Java Applets Browser support (Microsoft vs. Sun Now getting better; but ask me about object support!) Speed Download time JVM execution Swing support is improving. This will be on the exam. 1
How Java Fits with the Web The browser: finds an applet (or object) reference in HTML downloads the applet calls init calls start (also on return to page) calls paintcomponent On leaving a page: calls stop Exiting browser: calls destroy paintcomponent paintcomponent: Is called by the browser, never directly Paints to a JPanel The JPanel is added to a content pane The 'Wel' Applet public class Wel extends JApplet { Container messagearea = getcontentpane(); MessagePanel mymessagepanel = new MessagePanel(); public void init() { messagearea.add(mymessagepanel); class MessagePanel extends JPanel { public void paintcomponent(graphics grafobj) { super.paintcomponent(grafobj); grafobj.drawstring("welcome!", 50, 50); Compiling Java The Java compiler is javac You run it from the command line or an IDE Assume you have created Wel.java with nano: javac Wel.java This will create Wel.class and MessagePanel.class provided there are no errors. Setting Font Properties Invoke the setfont method before drawstring Font font1 = new Font("TimesRoman", font.italic, 24); grafobj.setfont(font1); Connecting Java to HTML: Object The <object> tag can connect a Java applet to an HTML document. <object codetype="application/java" classid="java:wel.class" width="300" height="100"> </object> The <object> tag can be used with other things besides Java applets. 2
Connecting Java to HTML: Applet The <object> tag is not yet well-supported by browsers. <applet code="wel.class" width="300" height="100"> </applet> <applet> is deprecated. (But it works where <object> does not.) Why Not Use Object This works in IE6, Netscape, Mozilla, and Firefox. <applet code="wel.class" width="300" height="100"> Applets are not supported here! </applet> Text between tags is displayed if applets are not supported by the browser. One Form of the <object> Tag This works in Netscape, Mozilla, Firefox, but not IE6. <object codetype="application/java" classid="java:wel.class" width="300" height="100"> </object> The code with yellow background is used by the browser. 3
The code with yellow background is used by the browser. Supplying Parameters to Applets <applet... > <param name="size" value="24"> </applet> String mysize=getparameter("size"); Also do this with objects. Returns null if the parameter is not defined; Check for null and supply a default value (or error.) AWT Graphics Coordinate System Distances are pixels. 0,0 Increasing Y Increasing X The drawline Method public void paintcomponent(graphics grafobj){ grafobj.drawline(20,10,60,80); Other Methods of class Graphics drawrect(x,y,width,height); fillrect(x,y,width,height); drawroundrect(x,y,w,h,rh,rw); fillroundrect(x,y,w,h,rh,rw); draw3drect(x,y,w,h,state); drawoval(x1,y1,width,height); filloval(x1,y1,width,height); A 3D rectangle is like a button. State is a Boolean that tells whether it looks "pushed" or "unpushed." 4
Arrays of coordinates Number of coordinates Polygons int xcoord [] = {30,50,64,64,50,30,16,16,30; int ycoord [] = {10,10,24,44,58,58,44,24,10; grafobj.drawpolygon(xcoord,ycoord,9); Or, create an object of class Polygon; see pp. 280 282 Colors 24-Bit color available RGB values, 8 bits each or, named colors pp. 282-283. Color mycolor = new Color(r, g, b); Set background and foreground colors with methods of class Panel. Swing Widgets Similar to HTML forms controls; provide for interactivity. JLabel mylabel = new JLabel("Name:"); JButton mybutton = new JButton("Click me"); JCheckbox mybox1 = new JCheckbox("Milk"); JTextField custname = new JTextField(32); Swing Radio Buttons Create a button group Create buttons Add buttons to group ButtonGroup payment = new ButtonGroup(); JRadioButton btn1=new JRadioButton("Visa",true); JRadioButton btn2=new JRadioButton("MC",false); payment.add(btn1); payment.add(btn2); The Panel Again paintcomponent is not needed for Swing JPanels can be created in the applet public class Pizza extends JApplet{ Container contentpane = getcontentpane(); public void init() { JPanel mypanel = new JPanel();... Jlabel namelabel = new JLabel("Name:"); JTextField myname = new JTextField(30); mypanel.add(namelabel); mypanel.add(myname);... contentpane.add(mypanel); Colors Again JPanel has methods to set foreground and background colors. mypanel.setbackground(color.yellow); mypanel.setforeground(color.blue); 5
Inheritance Java is a true object-oriented language. Objects in a panel (generally) inherit the methods of the panel. So, this works: JTextField myname = new JTextField(30); mypanel.add(myname); myname.setforeground(color.red); Events and Event Handlers Control (widget) actions generate event objects Event listeners can be registered for event objects. Simple listeners can be anonymous classes btn1.addactionlistener(new ActionListener(){ public void actionperformed(actionevent e) { text.setfont(newfont); ); Example: pp. 290-292 Economies Don t Always Scale Information Architecture and the Enterprise Large organizations need: Consistent processes Clear and consistent communications The purpose of an organization is to coordinate the efforts of many people. However, technology drives decentralization. The Decentralizing Nature of Technology Compare and contrast: A personal Web site A corporate or university Web site Building a Web page is easy Everyone in the enterprise will want to do it They will all be different! 6
The Corporate Portal Model Problems Where to begin? Silos of information Same concept, different labels Different concept, same labels Inconsistent navigation systems Ignorance is not bliss! The cost of finding information The cost of not finding information Inconsistent information The Case for Centralization Increased Revenues Reduced Costs Clearer Communication Shared Expertise Centralization is Inevitable Anyway (?) 7
Roadblocks to Centralization Unrealistic Scheduling No Stone Unturned The Monolithic Effort Human Nature Ignored Insufficient Support A Framework for Centralization A New Business Unit Phasing In Strategy and Tactics A New Business Unit Establish, with support of senior management, a business unit for IA and content management. Become a service provider. Become self-supporting. Offer basic services free (For consultants, this is pitching. ) Bill for premium services. Billing limits demand. (Good.) A Phased Rollout You cannot do everything all at once. Identify the best clients Content Users Context You will have to sell your services! A client information checklist Projecting demand Strategy and Tactics Separate strategy and tactics Strategy Strategic alignment Financial and political stability Management and performance Tactics Implementing IA for clients Coming Attractions Monday: Other Media, Accessibility Intellectual Property Q and A Wednesday: Review for Final Term papers due Monday, December 10 Final exam 6:00 to 7:50 8
Questions 9