gayle j yaverbaum phd professor of information systems penn state harrisburg n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
INFSY 547: WEB-Based Technologies PowerPoint Presentation
Download Presentation
INFSY 547: WEB-Based Technologies

Loading in 2 Seconds...

play fullscreen
1 / 29

INFSY 547: WEB-Based Technologies - PowerPoint PPT Presentation


  • 428 Views
  • Uploaded on

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>

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'INFSY 547: WEB-Based Technologies' - libitha


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
gayle j yaverbaum phd professor of information systems penn state harrisburg
Gayle J Yaverbaum, PhD

Professor of Information Systems

Penn State Harrisburg

INFSY 547: WEB-Based Technologies

adding more applets objects to xml content
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>

xsl code
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>

applet considerations
Applet Considerations

Javax.swing supplies best classes

setSize is unnecessary but aids in

debugging

applet size is set in html

slide6
package guisampleapplet;

import javax.swing.JApplet;

import java.awt.*;

publicclass GUISampleApplet extends JApplet

{

PanelClass p;

publicvoid init ()

{

p = new PanelClass();

}

}

slide7

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

slide8

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

}

}

slide9

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

}

}

layout managers
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.

popular layout managers
Popular Layout Managers

FlowLayout

GridLayout

BorderLayout

panels
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.

slide13

Panels

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

Complete all files to run your applet in

a browser

      • xml
      • dtd
      • xsl
      • css
      • bat
  • Run the applet in the browser
slide15

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)

slide16

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

}

}

slide17

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

}

}

slide18

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
slide19

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

event handling and associated objects
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

slide21

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

slide22

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
slide23

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
slide24

North

East

West

Center

South

BorderLayout Manager

slide25

public void PlacePanels ()

{

setLayout(new BorderLayout(5,10));

.

.

}

Note: 1. may simply be (new BorderLayout ()

2. the 5,10 indicates border space in pixels

slide26

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
example on next slides demonstrate
Example on next slides demonstrate:

Mouse enter

Mouse exit

Left mouse click

Right mouse click

slide28

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());

}

}

slide29

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