Source code of program which receive packets
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
public class net9 extends Frame implements ActionListener,WindowListener
{
static DatagramSocket ds2;
JButton a=new JButton("Send");
JLabel b=new JLabel("Two Way Chatting");
static JTextField c=new JTextField(30);
static JTextArea d=new JTextArea(10,30);
net9() throws Exception
{
setLayout(new FlowLayout(FlowLayout.CENTER));
setBackground(Color.GREEN);
setForeground(Color.BLUE);
setSize(400,300);
setLocation(50,50);
addWindowListener(this);
add(b);
add(d);
add(c);
add(a);
a.addActionListener(this);
setVisible(true);
}
public void windowClosing(WindowEvent w)
{
System.exit(1);
}
public void windowDeiconified(WindowEvent w){}
public void windowIconified(WindowEvent w){}
public void windowClosed(WindowEvent w){}
public void windowActivated(WindowEvent w){}
public void windowDeactivated(WindowEvent w){}
public void windowOpened(WindowEvent w){}
public void actionPerformed(ActionEvent ae)
{
String z= c.getText();
byte m[]=z.getBytes();
try{
InetAddress ia =InetAddress.getLocalHost();
System.out.println(ia);
DatagramPacket dp3=new DatagramPacket(m,m.length,ia,45);
ds2.send(dp3);} catch(Exception e){}
c.setText("");
d.append("sent--"+z+'\n');
System.out.println(""+z);
}
public static void main(String args[])throws Exception
{
DatagramSocket ds2=new DatagramSocket(1);
net9 w=new net9();
while(true)
{
byte u[]=new byte[100];
DatagramPacket dp2=new DatagramPacket(u,u.length);
ds2.receive(dp2);
String g=new String(dp2.getData(),0,dp2.getLength());
System.out.println(g);
d.append("Recieved--"+g+'\n');
}
}
}
Vardan Gupta wrote:I was trying to make an applet which invokes a frame, and frame is implementing WindowListener and ActionListener but it gives an exception
Exception in thread "AWT-EventQueue-1" java.security.AccessControlException
the coding done in listener is {System.exit(1);}
please help me out, i m a beginner in java.