Help with gui

J

John O'Meara

Hi folks sorry if this has appeared twice i found no sign of my
original post after submitting it

If anyone can help me with this it would be appreciated as its been a
while since i have programmed

Below are two sets of code. The first draws a simplegui with a
textarea. The second is a piece of code given to me to capture packets
off the network card and displays them in a terminal.

If anyone knows how it will be possible so that when the start button
on my application is pressed the packets are printed to the gui text
area. I have added an actionlistener to the button but i am unsure of
the next step. i have been told one option is to have my program
implement jpcap handler but as i havent programmed for a while im
struggling with syntax. If anyone has suggestions they would be
appreciated. Heres my code any how:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import jpcap.*;

public class Servercapture extends JFrame implements ActionListener
{
private JFrame window;
private MenuBar bar;
private MenuItem about;
private Menu help;
private MenuItem start;
private Menu capture;

public Servercapture()
{

// Create frame and panels for GUI
window = new JFrame("Network Packet Sniffer");
window.setSize(700,500);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
GridLayout gridLayout = new GridLayout(2,1);
panel.setLayout(gridLayout);

// Add textarea for packet capture diaplay
TextArea text = new TextArea("Packet Capture Off",18, 30,
TextArea.SCROLLBARS_NONE);
panel.add(text);
window.getContentPane().add(panel);
window.show();
bar = new MenuBar();
window.setMenuBar(bar);
about = new MenuItem("About");
help = new Menu("Help");
start = new MenuItem("Start");
start.addActionListener(this);
capture = new Menu("Capture");
capture.add(start);
bar.add(capture);
help.add(about);
bar.add(help);

window.setVisible(true);

}


public void actionPerformed(ActionEvent e){
Object source = e.getSource();
if (source == start)
{

}

}

public static void main(String[] args){
Servercapture s = new Servercapture();
}
}

********************************************************************

import jpcap.*;

class Tcpdump implements JpcapHandler
{
public void handlePacket(Packet packet){
System.out.println(packet);
}
public static void main(String[] args) throws java.io.IOException{
String[] lists=Jpcap.getDeviceDescription();
System.out.println("Start capturing on "+lists[0]);

Jpcap jpcap=Jpcap.openDevice(Jpcap.getDeviceList()[0],1000,false,20);
jpcap.loopPacket(-1,new Tcpdump());
}


Thanks folks
 
J

John O'Conner

John said:
Hi folks sorry if this has appeared twice i found no sign of my
original post after submitting it

If anyone can help me with this it would be appreciated as its been a
while since i have programmed


When you press start, pass the packet handler a reference to the text
area in your GUI. In the handler's "handlePacket" method, use the text
area reference to print the packet info.

Regards,
John O'Conner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top