Beginners Question Java !! listen to port and print info

Joined
Sep 25, 2008
Messages
2
Reaction score
0
Hi peeps,

Im a beginner with Java and im trying to make a program that listen's to a certain port and then views the information (information sent to that port) in my Jframe

i've made the framework(wich took me a while), but now i'm stuck...

Does anybody know a simple code that makes it listen to a port and then views the information received in the Jframe? it would help me alot:D

Thanks, i appreciate it.



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;




public class Myframe extends JFrame {


static JTextArea tekstarea;
JButton startb;
JButton refreshb;
static InputStream input;
static boolean start;
String s;


public Myframe()
{
.

setTitle("Test frame");
setSize(new Dimension(800, 700));

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


tekstarea=new JTextArea(20,20);
tekstarea.setEditable(false);
tekstarea.setForeground(Color.black);

JScrollPane panel1=new JScrollPane(tekstarea,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel1.setPreferredSize(new Dimension(200,800));
add(panel1,BorderLayout.WEST);
tekstarea.append("Info Read:\n\n");



startb=new JButton("Start Reading");
refreshb=new JButton("Refresh");
JPanel panel2=new JPanel();
panel2.add(startb);
panel2.add(refreshb);
add(panel2,BorderLayout.CENTER);


ActionListener listener1=new StartHandler();
startb.addActionListener(listener1);
ActionListener listener2=new RefreshHandler();
refreshb.addActionListener(listener2);


setVisible(true);
start=false;



}


class StartHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
start=true;
}
}


class RefreshHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{



}
}


public static void main(String[] args)
{



Myframe tc=new Myframe();



while(start==false){
try
{Thread.sleep(500);
}
catch(InterruptedException exception){};
};





}


}
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top