Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

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

Ähnliche Präsentationen


Präsentation zum Thema: "Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java -"—  Präsentation transkript:

1 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - Applets 1 java.awt.Window java.lang.Object java.awt.Frame java.awt.Container paint(Graphics g) java.awt.Panel java.awt.Applet init() start() stop() destroy() java.awt.Component paint(Graphics g)

2 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik 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;

3 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik 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)); }

4 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik 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){}; }

5 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik 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(); }

6 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - Applets 6 Oszilloscop Oszilloscop Mit einem Oszilloscop können Sie die Spannungsverläufe als Funktion der Zeit beobachten <APPLET CODE="Oszi.class"WIDTH=500HEIGHT=400 > In der obigen Nachbildung eines Oszilloscops können Sie zwischen vier verschieden Spannungsverläufen wählen. Die Darstellung kann als Zeitfunktion oder als Lissajous-Figur über der Funktion sin(x) erfolgen. In der Zeitdarstellung können Sie mit der linken Maustaste einen Meßstrahl zur Pegelbestimmung auslößen. In der Betriebsart "Dynamik" wird der Phasenwikel um 10 Grad je Sekunde verschoben. In einem zusä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ät auf das Ausmessen von von Pegelwerten beschränkt.

7 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - Applets 7

8 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - Applets 8 Blakenkreuz Balkenkreuz In zwei Applets verschieben Scrollbars die Balken horizontal bzw. vertikal. <APPLET CODE="Hbar.class" NAME="HBAR" WIDTH=300HEIGHT=200 > miteinander kommunizierende Applets <APPLET CODE="Vbar.class" NAME="VBAR" WIDTH=200HEIGHT=250 >

9 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - Applets 9 java.applet.AppletContext > AdjustmentListener java.applet.Applet BarScreen > addVbar() VValueChanged() HBar 1 addHbar() HValueChanged() VBar ScrollBar > getAppletContext() 1 1 1 1 2 1 1 2 1 1111 1111

10 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik 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); }

11 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik 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(); }

12 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik 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(); }


Herunterladen ppt "Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java -"

Ähnliche Präsentationen


Google-Anzeigen