Beginners Question Java !! listen to port and print info

Discussion in 'Java' started by RTypeX, Sep 25, 2008.

  1. RTypeX

    RTypeX

    Joined:
    Sep 25, 2008
    Messages:
    2
    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){};
    };





    }


    }
    RTypeX, Sep 25, 2008
    #1
    1. Advertising

  2. RTypeX

    RTypeX

    Joined:
    Sep 25, 2008
    Messages:
    2
    Nobody? :oops:
    RTypeX, Sep 25, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonah Olsson
    Replies:
    1
    Views:
    662
    Jonah Olsson
    Oct 7, 2004
  2. Ahan Hsieh
    Replies:
    1
    Views:
    2,232
    David W. Burhans
    Nov 4, 2003
  3. =?ISO-8859-1?Q?Daniel_G=F3mez?=

    how to listen to port 53 (DNS)

    =?ISO-8859-1?Q?Daniel_G=F3mez?=, May 30, 2004, in forum: Java
    Replies:
    3
    Views:
    7,269
    Mark Thornton
    May 30, 2004
  4. Donny
    Replies:
    13
    Views:
    645
    Donny
    Aug 5, 2004
  5. Gerald Klix
    Replies:
    0
    Views:
    1,250
    Gerald Klix
    Oct 26, 2005
Loading...

Share This Page