My code which is supposed to capture the network traffic AND display it on textarea but it ain't doing it.Please have a look at the code and check if there is any correction to be made.
public class NewClass {
public static JTextArea textarea = new JTextArea();
NewClass() throws IOException{
JButton capture = new JButton("Capture");
JFrame frame = new JFrame();
JScrollPane scroll;
NetworkInterface[] NI= JpcapCaptor.getDeviceList();
int INDEX=0;
JpcapCaptor JPCAP = JpcapCaptor.openDevice(NI[INDEX], 65536, false, 20);
frame.setSize(700,500);
frame.setLocation(200,200);
frame.getContentPane().setLayout(null);
frame.setBackground(Color.yellow);
textarea.setEditable(false);
textarea.setFont(new Font("Tahoma",0,14));
textarea.setForeground(Color.RED);
textarea.setLineWrap(true);
//textarea.setBackground(Color.WHITE);
scroll = new JScrollPane();
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setViewportView(textarea);
frame.getContentPane().add(scroll);
scroll.setBounds(10,16,740,290);
capture.setBackground(Color.RED);
capture.setForeground(Color.GREEN);
frame.getContentPane().add(capture);
handler ob = new handler();
capture.addActionListener(ob);
capture.setBounds(100, 400, 90, 25);
frame.setVisible(true);
}
public class handler implements ActionListener{
public void actionPerformed(ActionEvent Event){
class Print implements PacketReceiver{
public void receivePacket(Packet packet){
String info = packet.toString();
textarea.append(info);
//System.out.println(packet.toString());
}
}
}
}
Well for one, your handler's actionPerformed method doesn't really do anything. It defines an inner class but creates no objects of this class and does nothing with it:
Consider creating an object of your Print class (a terrible name for a class since there already is a Print class that is part of the core Java libraries) and having this Print object do something useful, perhaps receive packets (however it's supposed to do that). Be careful not to do long-running processes in the main Swing thread, the EDT though, or you'll freeze your Swing GUI.
Edit
e.g.,