slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Verteilte Software - Java - Applets 1 PowerPoint Presentation
Download Presentation
Verteilte Software - Java - Applets 1

Loading in 2 Seconds...

play fullscreen
1 / 12

Verteilte Software - Java - Applets 1 - PowerPoint PPT Presentation


  • 162 Views
  • Uploaded on

java.awt.Container. java.awt.Component. paint(Graphics g). paint(Graphics g). Verteilte Software - Java - Applets 1. java.lang.Object. java.awt.Window. java.awt.Panel. java.awt.Frame. java.awt.Applet. init() start() stop() destroy(). Verteilte Software - Java - Applets 2.

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 'Verteilte Software - Java - Applets 1' - khan


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
slide1

java.awt.Container

java.awt.Component

paint(Graphics g)

paint(Graphics g)

Verteilte Software - Java - Applets 1

java.lang.Object

java.awt.Window

java.awt.Panel

java.awt.Frame

java.awt.Applet

init()

start()

stop()

destroy()

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

slide2

Verteilte Software - Java - Applets 2

change_phi = change_phi_stop = null;

setBackground(Color.lightGray);

setLayout(new BorderLayout());

// oben

Panel oben = new Panel();

oben.setLayout(new FlowLayout(FlowLayout.CENTER));

b = new Button[5];

b[0] = new Button(" sin( x) ");

b[1] = new Button(" sin(2x) ");

b[2] = new Button("sin( x) + 1/3 sin(3x)");

b[3] = new Button("sin(2x) + 1/3 sin(6x)");

for ( int i = 0; i <= 3; i++)

{ b[i].addActionListener(this);

oben.add(b[i]);

}

add(oben, BorderLayout.NORTH);

//links

Panel links = new Panel();

b[4] = new Button("Aus");

b[4].addActionListener(this);

links.add(b[4]);

add(links, BorderLayout.WEST);

//zentral

disp = new Display();

add(disp, BorderLayout.CENTER );

import java.awt.*;

import java.awt.event.*;

import java.applet.Applet;

import Display;

public class Oszi extends Applet

implements Runnable,

ActionListener,

ItemListener,

TextListener,

AdjustmentListener

{ Frame f;

Thread change_phi,

change_phi_stop;

Display disp;

Button b[];

Scrollbar sb;

Checkbox cbd, cbl;

TextField tf;

boolean dyn; // Dynamik

int phi, // Phasenwinkel

fw, // Funktionsauswahl

art; // Darstellungsart

public void init()

{ phi = 0;

fw = 1;

art = 0;

dyn = false;

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

slide3

Verteilte Software - Java - Applets 3

//rechts

sb = new Scrollbar(Scrollbar.VERTICAL, 0, 20, 0, 380);

sb.addAdjustmentListener(this);

sb.setUnitIncrement(3); sb.setBlockIncrement(30);

add(sb, BorderLayout.EAST);

//unten

Panel unten = new Panel();

cbd = new Checkbox("Dynamik"); cbd.addItemListener(this);

unten.add(cbd);

cbl = new Checkbox("Lissajous"); cbl.addItemListener(this);

unten.add(cbl);

unten.add(new Label("Phasenwinkel"));

tf = new TextField("0",3); tf.addTextListener(this);

unten.add(tf);

unten.add(new Label("°"));

add(unten, BorderLayout.SOUTH);

setSize(460,420);

// Zusatzfenster

int ausw, ph;

f = new Frame();

f.setTitle("Display Function");

try { ausw = Integer.parseInt(getParameter("Auswahl")); }

catch (NumberFormatException e) {ausw = 1;}

try { ph = Integer.parseInt(getParameter("Phase")); }

catch (NumberFormatException e) {ph = 0;}

if (ausw < 1) ausw = 1; else ausw = ((ausw - 1) % 8) + 1;

ph %= 360; if (phi < 0) ph += 360;

f.add("Center", new Display(ausw, ph));

}

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

slide4

Verteilte Software - Java - Applets 4

public void start()

{

if (change_phi == null)

{

change_phi =

change_phi_stop =

new Thread(this);

change_phi.start();

}

f.setSize( 420, 400 );

f.setVisible(true);

}

public void stop()

{

change_phi_stop = null;

try { change_phi.join(); }

catch (InterruptedException e)

{ System.out.print(e); }

change_phi = null;

f.setVisible(false);

}

public void destroy()

{

f.dispose();

}

public void run()

{

Integer i = new Integer(0);

while (change_phi == change_phi_stop)

{

if (dyn && fw != 0)

{

disp_new();

phi++;

phi %= 360;

sb.setValue(phi);

tf.setText(i.toString(phi));

try

{

change_phi.sleep(100);

}

catch(InterruptedException e){};

}

else

try

{

change_phi.sleep(500);

}

catch(InterruptedException e){};

}

}

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

slide5

Verteilte Software - Java - Applets 5

public void itemStateChanged

(ItemEvent e)

{

Object obj = e.getSource();

if (obj == cbl)

{

if (cbl.getState()) art = 4;

else art = 0;

if (fw != 0) disp_new();

}

if (obj == cbd)

{ if (cbd.getState()) dyn = true;

else dyn = false;

}

}

public void textValueChanged

(TextEvent e)

{

Object obj = e.getSource();

if (obj == tf)

{

phi =

Integer.parseInt(tf.getText());

if (phi < 0) phi = 0;

if (phi > 360) phi = 360;

sb.setValue(phi);

disp_new();

}

}

public void adjustmentValueChanged

(AdjustmentEvent e)

{ Object obj = e.getSource();

if (obj == sb)

{ phi = sb.getValue();

tf.setText(new Integer(phi).toString());

disp_new();

}

}

public void actionPerformed(ActionEvent e)

{ Object obj = e.getSource();

if (obj instanceof Button)

{ for (int i = 0; i < 4; i++)

if (obj == b[i]) fw = i + 1;

if (obj == b[4])

{ fw = 0; art = 0;

phi = 0; dyn = false;

tf.setText("0"); sb.setValue(phi);

cbd.setState(false);

cbl.setState(false);

}

disp_new();

}

}

void disp_new()

{ disp.new_function(art + fw, phi);

disp.repaint();

}

}

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

slide6

Verteilte Software - Java - Applets 6

<HTML>

<HEAD>

<TITLE>Oszilloscop</TITLE>

</HEAD>

<BODY>

<h1>Oszilloscop</h1>

<P>Mit einem Oszilloscop k&ouml;nnen Sie die Spannungsverl&auml;ufe als Funktion der Zeit beobachten</P>

<P>

<HR ALIGN="CENTER">

<APPLET

CODE="Oszi.class" WIDTH=500 HEIGHT=400 >

<PARAM NAME=Auswahl VALUE=3>

<PARAM NAME=Phase VALUE=210>

</APPLET>

<HR ALIGN="CENTER">

<p> In der obigen Nachbildung eines Oszilloscops k&ouml;nnen Sie zwischen

vier verschieden Spannungsverl&auml;ufen w&auml;hlen. Die Darstellung kann

als Zeitfunktion oder als Lissajous-Figur &uuml;ber der Funktion sin(x)

erfolgen. In der Zeitdarstellung k&ouml;nnen Sie mit der linken Maustaste

einen Me&szlig;strahl zur Pegelbestimmung ausl&ouml;&szlig;en.

In der Betriebsart "Dynamik" wird der Phasenwikel um 10 Grad je Sekunde

verschoben.

<p> In einem zus&auml;tzlichen Applet-Fenster wir die Funktion sin(x) + 1/3 sin(3x)

(Auswahl = 3) bei einer Phasenverschiebung von 210 Grad (Phase = 210)

dargestellt. In diesem Fenster ist die Funktionalit&auml;t auf das Ausmessen von

von Pegelwerten beschr&auml;nkt.

</BODY>

</HTML>

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

slide7

Verteilte Software - Java - Applets 7

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

slide8

Verteilte Software - Java - Applets 8

<HTML>

<HEAD>

<TITLE>Blakenkreuz</TITLE>

</HEAD>

<BODY>

<h1>Balkenkreuz</h1>

<P>In zwei Applets verschieben Scrollbars die Balken horizontal bzw. vertikal.</P>

<P>

<HR ALIGN="CENTER">

<APPLET

CODE="Hbar.class" NAME="HBAR" WIDTH=300 HEIGHT=200 >

</APPLET>

miteinander kommunizierende Applets

<APPLET

CODE="Vbar.class" NAME="VBAR" WIDTH=200 HEIGHT=250 >

</APPLET>

</BODY>

</HTML>

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

slide9

Verteilte Software - Java - Applets 9

java.applet.Applet

getAppletContext()

1

1

1

1

java.applet.AppletContext

2 1 1

1 1 1

1 1

1 1

BarScreen

HBar

VBar

1 1

1 1

addVbar()

VValueChanged()

addHbar()

HValueChanged()

ScrollBar

<<uses>>

<<uses>>

2 1

<<interface>>

AdjustmentListener

<<implements>>

<<implements>>

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

slide10

Verteilte Software - Java - Applets 10

import java.awt.*;

public class BarScreen extends Canvas

{

int hvalue,

vvalue;

public BarScreen()

{

hvalue = vvalue = 0;

setBackground(Color.blue);

}

public void setHValue(int h)

{

hvalue = h;

}

public void setVValue(int v)

{

vvalue = v;

}

public void paint( Graphics g )

{

g.setColor(Color.yellow);

g.fillRect(hvalue * (getSize().width - 20) / 100, 0, 20, getSize().height);

g.fillRect(0, vvalue * (getSize().height - 20) / 100, getSize().width, 20);

}

}

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

slide11

Verteilte Software - Java - Applets 11

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

import BarScreen;

import Vbar;

public class Hbar extends Applet

implements AdjustmentListener

{ int hvalue;

Scrollbar hsb;

BarScreen bs;

AppletContext ac;

Vbar vbar_source, vbar_dest;

public void init()

{ hvalue = 0;

setBackground(Color.blue);

setLayout(new BorderLayout());

//unten

hsb = new Scrollbar

(Scrollbar.HORIZONTAL,

0, 20, 0, 120);

hsb.addAdjustmentListener(this);

hsb.setUnitIncrement(1);

hsb.setBlockIncrement(10);

add(hsb, BorderLayout.SOUTH);

setSize(300, 300);

//zentral

bs = new BarScreen();

add(bs, BorderLayout.CENTER );

ac = getAppletContext();

vbar_source = (Vbar)

ac.getApplet("VBAR");

if (vbar_source != null)

vbar_source.addHbar(this);

vbar_dest = null;

}

public void addVbar(Vbar vbar)

{

vbar_dest = vbar;

}

public void VValueChanged(int vv)

{

bs.setVValue(vv);

bs.repaint();

}

public void adjustmentValueChanged

(AdjustmentEvent e)

{ Object obj = e.getSource();

if (obj == hsb)

{

hvalue = hsb.getValue();

bs.setHValue( hvalue );

if(vbar_dest != null)

vbar_dest.HValueChanged(hvalue);

bs.repaint();

}

}

}

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

slide12

Verteilte Software - Java - Applets 12

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

import BarScreen;

import Hbar;

public class Vbar extends Applet

implements AdjustmentListener

{ int vvalue;

Scrollbar vsb;

BarScreen bs;

AppletContext ac;

Hbar hbar_source, hbar_dest;

public void init()

{ vvalue = 0;

setBackground(Color.blue);

setLayout(new BorderLayout());

//links

vsb = new Scrollbar

(Scrollbar.VERTICAL,

0, 20, 0, 120);

vsb.addAdjustmentListener(this);

vsb.setUnitIncrement(1);

vsb.setBlockIncrement(10);

add(vsb, BorderLayout.WEST);

setSize(300, 300);

//zentral

bs = new BarScreen();

add(bs, BorderLayout.CENTER );

ac = getAppletContext();

hbar_source = (Hbar)

ac.getApplet("HBAR");

if (hbar_source != null)

hbar_source.addVbar(this);

hbar_dest = null;

}

public void addHbar(Hbar hbar)

{

hbar_dest = hbar;

}

public void HValueChanged(int hv)

{

bs.setHValue(hv);

bs.repaint();

}

public void adjustmentValueChanged

(AdjustmentEvent e)

{ Object obj = e.getSource();

if (obj == vsb)

{

vvalue = vsb.getValue();

bs.setVValue( vvalue );

if (hbar_dest != null)

hbar_dest.VValueChanged(vvalue);

bs.repaint();

}

}

}

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik