N
nutzer
Gast
HI leute ich hab eine frage ist es möglich ein Swing Fenster in ein Applet einzubinden?
Wenn Ja wie?
Wenn Ja wie?
package clients;
import java.awt.Container;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class clientthread extends JApplet
{
public static JTextField na = new JTextField();
public static JLabel l1 = new JLabel();
public static JButton b1 = new JButton();
Socket server ;
DataInputStream in ;
PrintStream ps ;
boolean endFlag = false;
/** Creates a new instance of clientthread */
public clientthread()
{
try
{
Socket s = new Socket("127.0.0.1",7788);
in = new DataInputStream(s.getInputStream());
ps = new PrintStream(s.getOutputStream());
this.start();
}
catch (Exception e)
{
System.out.println("Err 04: " + e.toString());
return;
}
}
public void init()
{
String zeile="";
int i=0;
try
{
;
final String MSG;
MSG = in.readLine();
if(MSG!=null)
{
final JFrame f = new JFrame( "Chatclient" );
f.setLayout(null);
na.setBounds(10,30,80,20);
l1.setBounds(10,10,400,10);
b1.setBounds(100,30,150,20);
b1.setText("Namen senden");
l1.setText(MSG);
// f.getContentPane().add(na);
// f.getContentPane().add(l1);
// f.getContentPane().add(b1);
f.add(na);
f.add(l1);
f.add(b1);
f.setBounds(300,400,380,100);
f.setResizable(false);
f.setVisible(true);
ActionListener al = new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
ps.println(na.getText()+"\r\n");
f.setVisible(false);
String test = null;
try {
test = in.readLine();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int i = test.indexOf("leider");
if(i!=-1)
{
f.setVisible(true);
System.out.println("Nickname vorhanden neu eingeben:");
}
else
{
f.dispose();
JFrame t = new JFrame();
t.getContentPane().setLayout(null);
t.setBounds(300,400,500,200);
final JTextField z = new JTextField();
JButton a = new JButton();
a.setBounds(270,170,180,30);
z.setBounds(10,10,250,150);
t.getContentPane().add(z);
t.getContentPane().add(a);
a.setText("MSG zum Server senden");
t.setVisible(true);
try {
String Server = in.readLine();
z.setText(Server+"\n"+in.readLine());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
z.setText("");
ActionListener sl = new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
ps.println(z.getText());
try {
String b = in.readLine();
while(b != null)
{
z.setText(b);
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
};
a.addActionListener(sl);
}
}
};
b1.addActionListener(al);
}
}
catch (Exception e)
{
System.out.println("Fehler 05: " + e.toString());
}
}
}
L-ectron-X hat gesagt.:Du meinst, du willst ein Fenster von einem Applet aus öffnen?
Beispiel-Applet