john omeara

Greenhorn
+ Follow
since Nov 12, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by john omeara

Sorry that resultset snippet can be taken out - i just copied and pasted it from a previous select statement. Is there anyway of seeing if there is no record to update then to enter the update statement as a fresh record.
john
Hello
I have created the following code to update a paticular mysql record. Could any one inform me of how if the record is not present to add it to the database.
Thanks - heres the relevant code

try {
String query1 = "UPDATE system SET cox='"+first+"', def='"+second+"' WHERE name_d='"+name+"'";
System.out.println(query1);
Statement state1 = connect.createStatement();
ResultSet resultset1=state1.executeQuery(query1);
JOptionPane.showMessageDialog(null,"Database updated: ");
}
catch (Exception exp)
{
JOptionPane.showMessageDialog(null,"Problem with SQL query" + input );
Hello
I have created a JTextArea which at present has scrolling abilities. The problem is that at present when the textarea fills the jtext area still displays the same text whilst giving the ability to scroll for the extra not shown. Is it possible to alter this behaviour so that the JTextArea automatically scolls so the most recent bit of text added is always viewable.
I have the following lines of code at present
text = new JTextArea("",9, 24);
text.setLineWrap(false);
text.setEditable(false);
text.setWrapStyleWord(true);
JScrollPane scrollingResult1 = new JScrollPane(text);
window.getContentPane().add(scrollingResult1, BorderLayout.NORTH);
Many thanks
John
16 years ago
Hi i am having a few problems setting up colors on my text area correctly. I have set up a jtextarea and set the forground color to green. However depending on the content i want to change the text color for that paticular piece of content and not the whole jtextarea. At the moment i keep changing the color of my foregrounf but obviously that is changing the whole jtextarea color. Any one any ideas. Below id a few lines of the code where i am changing the color:
if((packet1.toString().indexOf("ARP"))!=-1){arp_count++;System.out.println("ARP " + arp_count);textarea1.setForeground(colora);}
if((packet1.toString().indexOf("ICMP"))!=-1){icmp_count++;System.out.println("ICMP" + icmp_count);textarea1.setForeground(colorb);}
packetcount=packetcount+1;
text1.append(packet1.toString()+"\n");
thanks again for your time
16 years ago
I have managed to sort that now i hadnt declared file properly earlier in the code. However im getting the error message "Error writing to file" now. Anyone any ideas.
thanks
17 years ago
Hi
I have created a jfilechooser in my program when the user clicks on the save button. What i want to do is then let the user specify the file (or create one) and then write to it via a fileoutput stream but i am having problems with my file references - the complier doesnt like the value file as the agument to the fileoutputstream constructor.
Anyone any ideas - my code is below:

int returnVal = fc.showSaveDialog(Serverside1.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
}
try
{

out = new FileOutputStream(file);

p = new PrintStream( out );

p.println ("This is written to a file");
p.close();
}
catch (Exception f)
{
System.err.println ("Error writing to file");
}
cheers people.
17 years ago
Thanks for your help people that has worked a a treat.
john
17 years ago
Hi people
Hope maybe someone could figure this one out.
I am trying to write some code that displays the time in seconds to millisecond precision i.e. 1.354. Unfortnatley my code at the moment displays 1.354 seconds as 1354. Could someone let me know how to cast this correctly i have included my code below.
public long dt = 0;
public long startTime = System.currentTimeMillis();
dt = System.currentTimeMillis() - startTime;
print(dt);
thanks for your time
17 years ago
Hello i am stuck on a simple problem and was wondering if somebody may know the answer. I have created a JTextarea and want to write some statistics to it. These will change however very regularly and i was wondering how to clear the JTextarea and write the new statistics to it as opposed to appending to the previous ones.
Thanks for your time
john
17 years ago
Thanks for your time Greg that seems to have done the trick.
john
17 years ago
Hello
I am currently having problems with writing to a text area. In the code below i create a JTextArea which is appended to by other classes namely Tcpdump. Unfortuntaley when the first line is written to no more text is written to the JTextArea or that can be seen anyway. Have i set up wordwrap correctly or is there a way that when you call append on my textarea in the tcpdump class it adds a newline character.
Heres my code anyway
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import jpcap.*;
import java.io.*;
public class Serverside1 extends JFrame
{
private JFrame window;
private MenuBar bar;
private MenuItem start;
private Menu capture;
public JTextArea text;
public Tcpdump td;
public Serverside1()
{
// 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);
JTextArea text = new JTextArea("",18, 30);
text.setWrapStyleWord(true);
panel.add(text);
window.getContentPane().add(panel);
window.show();
bar = new MenuBar();
window.setMenuBar(bar);
start = new MenuItem("Start");
capture = new Menu("Capture");
capture.add(start);
bar.add(capture);
window.setVisible(true);
Tcpdump td = new Tcpdump();
try
{
td.printOutput(text);
}
catch(IOException e){
System.out.println("Bollox");}
}
public static void main(String[] args)throws java.io.IOException{
Serverside1 s = new Serverside1();
}
}
Many thanks
17 years ago
Sorry people it was a mistake. I will use the thread in the swing/gui section.
17 years ago
Cheers for the reply Donny.
I have done what you have suggested - the logic to it sounds right, but when i complile by i get an error - here is the new code for serverside1
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Serverside1 extends JFrame
{
private JFrame window;
private MenuBar bar;
private MenuItem about;
private Menu help;
public Serverside1()
{

// 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");
help.add(about);
bar.add(help);
window.setVisible(true);

}
public TextArea getText(){
return text;
}

public static void main(String[] args){
Serverside1 s = new Serverside1();
}
}
the error is below

C:\Project>javac Serverside1.java
Serverside1.java:51: cannot resolve symbol
symbol : variable text
location: class Serverside1
return text;
^
1 error
will i also need to implement any classes in serverside1.
Again thanks for the help
17 years ago
Hi folks
I am returning to java after a bit of a time away so if someone could help me with this little query it would be appreciated. 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 of the network card and displays them in a terminal.
If anyone knows how it will be possible so that the packets are printed to the gui text area by ammending the code it would be most helpful.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Serverside1 extends JFrame
{
private JFrame window;
public Serverside1()
{
window = new JFrame("Network Packet Sniffer");
window.setSize(700,500);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();

TextArea text = new TextArea("Network packets will he here",18, 30, TextArea.SCROLLBARS_NONE);
panel.add(text);
window.getContentPane().add(panel);
window.show();



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

}
Code for packet capture
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 a lot folks.
17 years ago
Hi folks
I am returning to java after a bit of a time away so if someone could help me with this little query it would be appreciated. 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 of the network card and displays them in a terminal.
If anyone knows how it will be possible so that the packets are printed to the gui text area by ammending the code it would be most helpful.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Serverside1 extends JFrame
{
private JFrame window;
public Serverside1()
{
window = new JFrame("Network Packet Sniffer");
window.setSize(700,500);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();

TextArea text = new TextArea("Network packets will he here",18, 30, TextArea.SCROLLBARS_NONE);
panel.add(text);
window.getContentPane().add(panel);
window.show();



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

}
Code for packet capture
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 a lot folks.
17 years ago