Ich habe 3 Applets
1.Applet (TwoControl.java)
----------------------------------------------------------------------------------------------
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class TwoControl extends Applet
implements ActionListener {
private TextField userInput;
private Button sendButton;
TwoResult resultApplet;
public void init() {
setLayout (new FlowLayout() );
Label l1 = new Label("TwoControlApplet: ");
add(l1);
userInput = new TextField("", 20);
userInput.addActionListener(this);
add(userInput);
/*sendButton = new Button ("Send result");
sendButton.addActionListener(this);
add(sendButton);*/
try {
AppletContext browser = getAppletContext();
resultApplet = (TwoResult) browser.getApplet("result");
} catch (Exception e) {
System.out.println("ResultApplet not found: " +e);
sendButton.setEnabled(false);
}
setVisible(true);
}
public void actionPerformed (ActionEvent e) {
String s = userInput.getText();
resultApplet.userInput.setText(s);
resultApplet.winner.setText(s);
}
}
----------------------------------------------------------
mit diesem Applet kann ich etwas was der Benutzer eingibt an das 2. Applet (TwoResult.java) übergeben und auf dem Bildschirm ausgeben
---------------------------------------------------------------------------------
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class TwoResult extends Applet
{
private Label headLine, h2, h3;
public Label winner;
public TextField userInput;
public void init() {
setLayout (new FlowLayout (FlowLayout.CENTER,6,10) );
headLine = new Label("TwoResultApplet:");
add(headLine);
h2 = new Label("Label:");
add(h2);
winner = new Label("test",);
add(winner);
h3 = new Label("TextField:");
add(h3);
userInput = new TextField("er",5);
add(userInput);
setVisible(true);
}
}
--------------------------------------------------------------------------
Jetzt mein Problem ich will das was ich im 2.Applet ausgegeben habe auch im 3.Applet (DreiControl.java) ausgeben ohne dabei auf das 1.Applet zurückzugreifen zu müssen, also ich will die Methode "userInput" aus dem 2.Applet mit dem 3.Applet auslesen.
---------------------------------------------------------------------------
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class DreiControl extends Applet implements ActionListener{
private Label headLine ;
public Label winner1;
TwoResult resultApplet;
String s;
public void init() {
setLayout (new FlowLayout(FlowLayout.LEFT) );
headLine = new Label("DreiControlApplet");
add(headLine);
AppletContext browser = getAppletContext();
resultApplet = (TwoResult) browser.getApplet("result");
winner1 = new Label(" du ");
add(winner1);
setVisible(true);
}
public void actionPerformed (ActionEvent e) {
s = resultApplet.userInput.getText();
winner1.setText(s);
}
}
---------------------------------------------------------------
Aber irgend etwas mach ich woll falsch weil es geht einfach nicht.
Kann mir jemand helfen?
Hier noch das HTML zum aufrufen der Applets
--------------------------------------------------------------
<html>
<head>
<title>Two Applets Example</title>
</head>
<body>
<h1>Two Applets</h1>
<p>
Applet1:
<p align=center>
<applet code="TwoResult.class" name="result"
width=300 height=100>
Sorry, no results without Java.
</applet>
<p>
Applet2:
<p align=center>
<applet code="TwoControl.class" name="control"
width=300 height=100>
Sorry, no controls without Java.
</applet>
<p>
Applet3:
<p align=center>
<applet code="DreiControl.class" name="result2"
width=300 height=100>
Sorry, no results without Java.
</applet>
</body>
</html>
-------------------------------------------------------------------------
Danke im Vorraus