1 / 29

INFSY 547: WEB-Based Technologies

Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg. INFSY 547: WEB-Based Technologies. Adding More Applets objects to XML Content. <?xml version="1.0"?> <!DOCTYPE panelslayoutapplet SYSTEM "PanelLayoutsApplet.dtd"> <jclass>

sammier
Download Presentation

INFSY 547: WEB-Based Technologies

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. Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg INFSY 547: WEB-Based Technologies

  2. Adding More Applets objects to XML Content <?xml version="1.0"?> <!DOCTYPE panelslayoutapplet SYSTEM "PanelLayoutsApplet.dtd"> <jclass> <app class="panellayoutsapplet.PanelLayoutsApplet“ width="300" height="250"> </app> <app class="firstapplet.FirstApplet" width="300" height="250"> </app> <app class="urlapplet.URLApplet" width="300" height="250"> </app> </jclass>

  3. xsl Code <TR> <xsl:for-each select="app"> <TD width=“30%"> <applet> <xsl:attribute name="code"> <xsl:value-of select="@class"/> </xsl:attribute> <xsl:attribute name="width"> <xsl:value-of select="@width"/> </xsl:attribute> <xsl:attribute name="height"> <xsl:value-of select="@height"/> </xsl:attribute> </applet> </TD> </xsl:for-each> </TR>

  4. Run Saxon Processor

  5. Applet Considerations Javax.swing supplies best classes setSize is unnecessary but aids in debugging applet size is set in html

  6. package guisampleapplet; import javax.swing.JApplet; import java.awt.*; publicclass GUISampleApplet extends JApplet { PanelClass p; publicvoid init () { p = new PanelClass(); } }

  7. Graphical User Example package guisampleapplet; import javax.swing.JApplet; import java.awt.*; public class GUISampleApplet extends JApplet { PanelClass p; public void init() { p = new PanelClass(); this.setSize(300, 40); this.add("North", p); } } • Extending our code! BorderLayout

  8. package guisampleapplet; import java.awt.Color; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JPanel; public class PanelClass extends JPanel { JButton _button1, _button2, _button3; JPanel _p; public PanelClass() { super(); _p = this; designPanel(); } private void designPanel() { _p.setBackground(Color.blue); _p.setLayout(new FlowLayout()); _button1 = new CreateAButton(_p, _button1, "Button 1 ",Color.orange); _button2 = new CreateAButton(_p, _button2, "Button 2 ", Color.GREEN); _button3 = new CreateAButton(_p, _button3, "Button 3 ", Color.YELLOW); } }

  9. package guisampleapplet; import java.awt.Color; import javax.swing.JButton; import javax.swing.JPanel; public class CreateAButton extends JButton { public CreateAButton (JPanel p, JButton b, String str, Color c) { super (str); this.setBackground(c); p.add (this); } }

  10. Layout Managers In JAVA layout is set in setLayout method Indicate layout of choice or accept default Add () and remove () methods are common to all layouts.

  11. Popular Layout Managers FlowLayout GridLayout BorderLayout

  12. Panels A layout manager may apply to a panel or an applet as a whole An applet may be divided into panels which may themselves be divided into subpanels and so on.

  13. Panels • Labels, buttons and more may be added to containers (panels) • Subsequently, panels are added to the applet

  14. Complete all files to run your applet in a browser • xml • dtd • xsl • css • bat • Run the applet in the browser

  15. Add a class to create a label • Add labels between each button • Remove button labels • Change all button colors • Line up each button and label – one/line using GridLayout (see next slide and page 285 of text)

  16. GridLayout package gridlayoutexample; import javax.swing.JApplet; import javax.swing.JPanel; import java.awt.*; public class GridLayoutClass extends JApplet { CreateAButton b; JPanel j; public void init () { this.setBackground (Color.white); j = new JPanel (); j.setLayout(new GridLayout(5, 2)); for (int i=1; i<=10; i++) { b= new CreateAButton (j, i, Color.red, Color.white); j.add (b); } this.add(j); } }

  17. package gridlayoutexample; import java.awt.Color; import javax.swing.JButton; import javax.swing.JPanel; public class CreateAButton extends JButton { public CreateAButton (JPanel p, int x, Color c, Color f) { super ("Button " + x); this.setBackground(c); this.setForeground (f); } }

  18. Event Driven Programming • Code that is called by the system when an event occurs • An event signifies an occurrence • The event generator notifies event handlers

  19. OS Interrupt Screen Button Object Press Button (Buttons generate events) Event Handling Object Event Notification Text field Object JAVA AWT Environment: Messages are sent between JAVA Objects Update Text Field Typical event handling

  20. Event Handling and Associated Objects Interface Events Flow User clicks a button User types text User uses a mouse When an event occurs, applet is notified Program may take action

  21. Add implements action listenerto the class publicclass PanelClass extends JPanel implements ActionListener1. Add to the action code to:_button1.addActionListener(this);for designPanel method2. Do this for all of your buttons

  22. public void actionPerformed(ActionEvent e) • { • if (e.getSource() == _button1) • { • _button1.setBackground (Color.red); • _button2.setBackground (Color.blue); • _button2.setBackground (Color.yellow); • } • } • Change all of the colors for each button clicked to a different color pattern

  23. BorderLayout Manager • o Divides the container (either a panel or whole • applet) • o Five areas • - North • -South • -East • -West • -Center • May also use the horizontal and vertical gaps as • in FlowLayout

  24. North East West Center South BorderLayout Manager

  25. public void PlacePanels () { setLayout(new BorderLayout(5,10)); . . } Note: 1. may simply be (new BorderLayout () 2. the 5,10 indicates border space in pixels

  26. Pressing a mouse button triggers a mouse event • Rather than implementing ActionListener, you will • implement MouseListener (note that more than one listener • may be implemented) • When a mouse is pressed, the location is stored in x,y • coordinates and location may be retrieved with getx () • and gety (). • MouseEvent handlers are invoked

  27. Example on next slides demonstrate: Mouse enter Mouse exit Left mouse click Right mouse click

  28. import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class mousedemo extends Applet implements MouseListener { //note that this bracket will having matching end bracket next screen TextField mousetext; public void init(){ mousetext = new TextField(25); add(mousetext); addMouseListener(this); } public void mousePressed(MouseEvent e){ if((e.getModifiers()& InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK){ mousetext.setText("Left mouse button down at " + e.getX() + "," + e.getY()); } else{ mousetext.setText("Right mouse button down at " + e.getX() + "," + e.getY()); } }

  29. public void mouseClicked(MouseEvent e){ mousetext.setText("You clicked the mouse at " + e.getX() + "," + e.getY()); } public void mouseReleased(MouseEvent e){ mousetext.setText("The mouse button is up"); } public void mouseEntered(MouseEvent e){ mousetext.setText("The mouse is in the applet"); } public void mouseExited(MouseEvent e){ mousetext.setText("The mouse is out of the applet"); } } //note that this bracket ends the applet from previous page

More Related