Avatar billede ronaldowitch Nybegynder
25. november 2002 - 11:30 Der er 9 kommentarer og
1 løsning

Udskrivning af indkomne ascii data til text felt

Jeg har lavet en rutine som opsamler data via en telnet session. Jeg ønsker at få disse data præsenteret i et text felt med 7 linier.

Der kommer lige et uddrag af min kode her:

public void run()
  {
      int n=0;
      boolean replyUnknown=true;
      int fg, bg, grid, text;
      String currentLine;
      char charArray[];


      startListener();

      tSemaphore.unlock();
      //if (sock != null && meter != null) meter.enable(true);

      while ( runner != null && sock != null)
      {
        try {runner.sleep(20);}
        catch (InterruptedException slE) {}
        // meter.rxOn(false);
        if (inBuf != null)
        {
            try {
              currentLine = inBuf.readLine();
              // meter.rxOn(true);
            }
            catch (IOException e ) {
              currentLine = null;
              //meter.rxOn(false);
              status("No data available.");
            }
           
            if (currentLine != null)
              // her skal indsættes metode til udskrivning i text area
        }
      }
      stopListener();
  }

Det er sikkert skide nemt, men jeg har ikke så meget erfaring med java.

Hvis der er en der gider at hjælpe med mit lille problem er der 200 points

På forhånd Tak.....
Avatar billede carstenknudsen Nybegynder
25. november 2002 - 12:35 #1
I starten af jeres program skal I have koden:
JFrame f = new JFrame();
JTextArea t = new JTextArea(20,8);
f.getContentPane().add( t );
f.pack();
f.show();
I starten af jeres løkke skal I have:
t.setText("");
I jeres udskrift del skal I have:
t.append(currentLine+System.getProperty("line.separator");
Avatar billede carstenknudsen Nybegynder
25. november 2002 - 12:39 #2
I skal også have import javax.swing.*; øverst i jeres program.
Avatar billede carstenknudsen Nybegynder
25. november 2002 - 12:45 #3
JTextArea t = new JTextArea(8,20);
Avatar billede ronaldowitch Nybegynder
25. november 2002 - 13:18 #4
Jeg får følgende fejl når jeg kompiler:

symbol  : variable t
location: class WebnetMod3
              t.append(currentLine+System.getProperty("line.separator"));
              ^


Jeg har tilføjet t.append(currentLine+System.getProperty("line.separator"); i run og de andre variabler i min init.
Avatar billede ronaldowitch Nybegynder
25. november 2002 - 13:20 #5
Jeg kan e-maile hele koden til dig hvis det er til nogen hjælp
Avatar billede carstenknudsen Nybegynder
25. november 2002 - 13:23 #6
Du kan lægge koden herop så alle kan se den.
I jeres klasse skal I lige erklære
JTextArea t = new JTextArea(8,20);
således at det ikke ligger i en metode.
JFrame'en kan I bare erklære i jeres konstruktor.
Avatar billede ronaldowitch Nybegynder
25. november 2002 - 13:27 #7
Her kommer koden.....

/*
* WebnetMod3.java
*
* Created on 21. november 2002, 21:07
*/

/**
*
* @author  Ronald Dale Madsen
*/
import javax.swing.text.*;
import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;




public class WebnetMod3 extends JApplet implements Runnable, ActionListener
{
    Image warning;
  Thread runner=null;
  PrintWriter outStream=null;//use PrintWriter
  CommSemaphore tSemaphore;
  String dataStreamReceiver = null;
  Socket sock=null;
  BufferedReader inBuf=null;
  int portNum = 23;//Telnet port
  String hostAddr=null;
  String picVersionReceiver = null;
  String getPicVersionCommand = null;
  boolean picVersionReported = false, picVersionRequesting = false;
  JPanel row1=new JPanel();
  //ButtonGroup valg= new ButtonGroup();
  JButton startKnap = new JButton("Temp. START");
  JButton stopKnap = new JButton("Temp. STOP");
  int tempReadout=0, analogValue=0;
  String toprint=null;
  /////////////////////


 
  public void init()  // only called once by the webbrowser
  {
     
      Container felt=getContentPane();
        FlowLayout flo = new FlowLayout();
        startKnap.addActionListener(this);
        stopKnap.addActionListener(this);
        felt.setLayout(flo);
        felt.add(startKnap);
        felt.add(stopKnap);
        setContentPane(felt);
        warning=getImage(getCodeBase(),"stop.gif");
      JFrame f = new JFrame();
      JTextArea t = new JTextArea(8,20);
      f.getContentPane().add( t );
      f.pack();
      f.show();
        t.setText("");
      String val;
      Color background = null, rxColor, txColor, txtColor;

      //setLayout(null);

      background = getColorParameter("bgcolor");
      if (background!=null)  this.setBackground(background);
      txColor  = getColorParameter("txcolor");
      rxColor  = getColorParameter("rxcolor");
      txtColor = getColorParameter("textcolor");

      val = getParameter("upstreamreceiver");
      if (val != null)
        dataStreamReceiver = val;
 
      // Parameters used for getting the PIC software version
      val = getParameter("requestpicversion");
      if (val != null) getPicVersionCommand = val;
      val = getParameter("picversionreceiver");
      if (val != null) picVersionReceiver = val;

   

      tSemaphore=new CommSemaphore();
  }

  public Color getColorParameter(String paramName)
  {
      String val;
      Color theColor = null;
      val = getParameter(paramName);
      if (val != null) {
        if (val.compareTo("black") == 0)          theColor = Color.black;
        else if (val.compareTo("blue") == 0)      theColor = Color.blue;
        else if (val.compareTo("cyan") == 0)      theColor = Color.cyan;
        else if (val.compareTo("darkGray") == 0)  theColor = Color.darkGray;
        else if (val.compareTo("gray") == 0)      theColor = Color.gray;
        else if (val.compareTo("green") == 0)    theColor = Color.green;
        else if (val.compareTo("lightGray") == 0) theColor = Color.lightGray;
        else if (val.compareTo("magenta") == 0)  theColor = Color.magenta;
        else if (val.compareTo("orange") == 0)    theColor = Color.orange;
        else if (val.compareTo("pink") == 0)      theColor = Color.pink;
        else if (val.compareTo("red") == 0)      theColor = Color.red;
        else if (val.compareTo("white") == 0)    theColor = Color.white;
        else if (val.compareTo("yellow") == 0)    theColor = Color.yellow;
        else {
            try {
              theColor = Color.decode(val);
            }
            catch (java.lang.NumberFormatException excep) {
              theColor = null;
            }
            }
      }
      return theColor;
  }

  public void actionPerformed(ActionEvent event)
  {
      String kommando = event.getActionCommand();
      if (kommando =="Temp. START"){
          //her skal strengen til start af a/d konverteringen stå
          String command="<b";
          sendCmd(command);
      }
      if (kommando =="Temp. STOP"){
          //her skal stop kommandoen stå
          String command="<c";
          sendCmd(command);
      }
      // Coming up: String text = Integer.toHexString(value);
  }

  public String getAppletInfo()
  {
      return "Handles communication to/from a PIC that is attached to a WebNet.";
  }

  void status( String x )
  {
      if (x != null)
      showStatus(x);  // should apear in the "status window" of the browser
  }

//  public void paint(Graphics screen)
  //{
    //  tempReadout = analogValue*100/1024-25;//String.toString(toprint);
      //super.paint(screen);
      // Graphics2D screen2D=(Graphics2D) screen;
      // screen2D.setColor(Color.black);
      // screen2D.drawString("Temperatur i Celsius: " +tempReadout+" grader",5,50);
      // screen2D.drawString("(Dette vindue viser den aktuelle temperatur på WEBNET modul 3)",5,120);
      // screen2D.drawString("Copyright by: 3semit.dk  19/4-2002  rev.1.02)",5,140);
      // Her skal IF betingelsen for temperaturen indsættes(< -10 eller >+50)
      // if (tempReadout < -10) {
        //  screen2D.setColor(Color.red);
        //  screen2D.drawString("ADVARSEL!!! Temperaturen er for lav!!!",5,80);
        //    screen2D.drawImage(warning,500,50,this);
      // }
      // if (tempReadout > 50) {
      //    screen2D.setColor(Color.red);
      //    screen2D.drawString("ADVARSEL!!! Temperaturen er for høj!!!",5,80);
      //      screen2D.drawImage(warning,500,50,this);
      // }
      // screen2D.setColor(Color.black);
   
     
  // }

  public String getCommStatus()
  {
      if (sock != null)
        return "Ok!";
      else
        return "No connection";
  }

  public void sendCmd(String command)
  {
      if(runner==null) {
        startListener();
      }
      //      if (runner != null)
      {
        try
        {
            //meter.txOn(true);
            tSemaphore.lock();
            if (outStream != null && command != null) {
              outStream.print(command);
              outStream.flush();
              if (runner != null)  runner.sleep(20);
            }
            else {
              if (dataStreamReceiver != null)
                  doCallBack("No connection");
            }
            tSemaphore.unlock();
            //meter.txOn(false);
            // System.out.println("sendCmd: "+command );
        }
        catch( InterruptedException e ) {
            //meter.txOn(false);
            System.out.println("Exception in sendCmd():" + e.getMessage() );
            stopListener();
        }
      }
  }

  public
  synchronized
  void startListener()
  {
      if(runner==null) {
        runner = new Thread(this);
        if(runner!=null)  {
            tSemaphore.trylock();  // this will be released by run() procedure after init.
            runner.start();        // start running at run()
        }
      }
  }

  public synchronized void stopListener()
  {
      tSemaphore.unlock();
      runner = null;
  }

  public boolean reConnect()
  {
      boolean retVal=false;

      status("Connecting to host " + hostAddr );
      try { sock = new Socket( hostAddr, portNum);}
      catch (IOException e ) {
        if( e.getMessage()!=null )
            status("While opening connection: " + e.getMessage());
        sock = null;
      }
      if (sock != null) {
        try {
            sock.setSoTimeout( 2000 ); // timeout in [ms]
            inBuf = new BufferedReader( new InputStreamReader(sock.getInputStream()));
            outStream=new PrintWriter( sock.getOutputStream() );//use PrintWriter
            sock.setSoTimeout( 10000 ); // timeout in [ms]
            retVal = true;
            //if (meter != null) meter.enable(true);
        }
        catch( IOException e ) {
            if( e.getMessage()!=null ) {
              status("::start() while receiving upstream data: no data: " +
                      e.getMessage());
            }
            inBuf = null;
            outStream = null;
            sock = null;
        }
      }
      if (sock == null)
      {
        status("Connection refused by host" );
        //if (meter != null) meter.enable(false);
      }
      tSemaphore.unlock();
      return retVal;
  }

  public void requestPicSoftwareId()
  {
      if (!picVersionReported &&
          picVersionReceiver != null &&
          getPicVersionCommand != null)
      {
        try {runner.sleep(1000);}    // Wait for some time
        catch (InterruptedException slE) {}
        picVersionRequesting = true;
        sendCmd(getPicVersionCommand+"\n");
      }
  }
 

  public void start()
  {
      int retryCount = 3;
      boolean doRetry = true;
      String currentLine = getParameter("port");
      if (currentLine == null) portNum = 23;//telnet port******
      else                    portNum = Integer.parseInt(currentLine);
      hostAddr = getDocumentBase().getHost();

      sock = null;

      while (doRetry == true && retryCount-- > 0)
      {
        if (reConnect() == true)
            doRetry = false;
      }
      status("ok");

      if (!picVersionReported)
        requestPicSoftwareId();
  }

  public void stop()
  {
      if (sock != null) {
        try {sock.close();}
        catch ( IOException e ) {
            if( e.getMessage()!=null ) {
              System.out.println("sock.close() exception: " +
                                  e.getMessage());
            }
        }
      }
      outStream=null;
      inBuf = null;
      sock = null;
      stopListener();
      status("connection closed");
  }

  public void run()
  {
      int n=0;
      boolean replyUnknown=true;
      int fg, bg, grid, text;
      String currentLine;
      char charArray[];


      startListener();

      tSemaphore.unlock();
      //if (sock != null && meter != null) meter.enable(true);

      while ( runner != null && sock != null)
      {
        try {runner.sleep(20);}
        catch (InterruptedException slE) {}
        // meter.rxOn(false);
        if (inBuf != null)
        {
            try {
              currentLine = inBuf.readLine();
              // meter.rxOn(true);
            }
            catch (IOException e ) {
              currentLine = null;
              //meter.rxOn(false);
              status("No data available.");
            }
           
            if (currentLine != null)
              // her skal indsættes metode til udskrivning i text area
              t.append(currentLine+System.getProperty("line.separator"));
        }
      }
      stopListener();
  }
 
 
 
 

  /**
    * Returns parameters defined by this applet.
    * @return an array of descriptions of the receiver's parameters
    */

  // public java.lang.String[][] getParameterInfo()
  //{
      //String[][] info =
      //{
        //{"picversionreceiver", "String", "JavaScript function to receive PIC software version."},
        //{"requestpicversion", "String", "String with PIC command to request PIC software version."},
        // {"upstreamreceiver", "String", "JavaScript function to receive upstream data."},
        //{"port", "Number", "Telnet port number to connect."},
        //{"bgcolor", "Color", "Background color."},
        //{"rxcolor", "Color", "Color of the Rx LED."},
        //{"txcolor", "Color", "Color of the Tx LED."},
        //{"textcolor", "Color", "Color of the LED labels."}
    // };
    // return info;
  //}
//}

static int hexStringToInt(String line)
  {
      int value, index;
      char charArray[] = new char[256];
      if (line.charAt(0) == '<')
        line.getChars(2,5,charArray,0);
      else
        line.getChars(3,6,charArray,0);
      for (index = 0, value = 0; index<3; index++)
      {
        value *= 16;
        if (charArray[index] >= '0' && charArray[index] <= '9')
            value += charArray[index]-'0';
        else if (charArray[index] >= 'a' && charArray[index] <= 'f')
            value += charArray[index]-'a'+10;
        else if (charArray[index] >= 'A' && charArray[index] <= 'F')
            value += charArray[index]-'A'+10;
      }
      return value;
  }
 
 
 
  class CommSemaphore
{
  boolean locked;

  public CommSemaphore()
  {
      locked=false;
  }
   
  public synchronized  void lock()
      throws IllegalMonitorStateException, InterruptedException
  {
      if(locked) wait();
      locked=true;
  }

  public synchronized  boolean trylock()
  {
      boolean r=true;
      if(locked) {
        try {
            wait();
            locked=true;
        }
        catch ( Exception e ) {
            System.out.println("Semaphore::Exception:" + e.getMessage() );
            r=false;
        }
      }
      else
        locked=true;
      return r;
  }

  public synchronized void unlock()
  {
      locked=false;
      notify();  // will only start one waiting thread.
  }
}

 
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
private void initComponents() {
   
    setFont(new java.awt.Font("Arial", 0, 12));
}

     


// Variables declaration - do not modify
// End of variables declaration

}
Avatar billede carstenknudsen Nybegynder
25. november 2002 - 13:50 #8
Jeg har tilføjet det nødvendige herunder;
der står //XXX hvor jeg har ændret noget.
Der mangler kun en ting, og det er at det
sted hvor I ved at nu skal i læse de syv
tal skal der stå t.setText("");
Jeg kender ikke logikken i programmet, så
I må selv tilføje det hvor det er nødvendigt.
Nu bliver der skrevet udover de syv linier,
men det virker forhåbentlig alligevel.
/*
* WebnetMod3.java
*
* Created on 21. november 2002, 21:07
*/

/**
*
* @author  Ronald Dale Madsen
*/
import javax.swing.text.*;
import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;




public class WebnetMod3 extends JApplet implements Runnable, ActionListener
{
    Image warning;
  Thread runner=null;
  PrintWriter outStream=null;//use PrintWriter
  CommSemaphore tSemaphore;
  String dataStreamReceiver = null;
  Socket sock=null;
  BufferedReader inBuf=null;
  int portNum = 23;//Telnet port
  String hostAddr=null;
  String picVersionReceiver = null;
  String getPicVersionCommand = null;
  boolean picVersionReported = false, picVersionRequesting = false;
  JPanel row1=new JPanel();
  //ButtonGroup valg= new ButtonGroup();
  JButton startKnap = new JButton("Temp. START");
  JButton stopKnap = new JButton("Temp. STOP");
  JTextArea t; //XXX
  int tempReadout=0, analogValue=0;
  String toprint=null;
  /////////////////////



  public void init()  // only called once by the webbrowser
  {
   
      Container felt=getContentPane();
        FlowLayout flo = new FlowLayout();
        startKnap.addActionListener(this);
        stopKnap.addActionListener(this);
        felt.setLayout(flo);
        felt.add(startKnap);
        felt.add(stopKnap);
        setContentPane(felt);
        warning=getImage(getCodeBase(),"stop.gif");
      //JFrame f = new JFrame(); //XXX
      t = new JTextArea(8,20);//XXX
      felt.add( t );//XXX
      //f.pack();//XXX
      //f.show();//XXX
        t.setText("");
      String val;
      Color background = null, rxColor, txColor, txtColor;

      //setLayout(null);

      background = getColorParameter("bgcolor");
      if (background!=null)  this.setBackground(background);
      txColor  = getColorParameter("txcolor");
      rxColor  = getColorParameter("rxcolor");
      txtColor = getColorParameter("textcolor");

      val = getParameter("upstreamreceiver");
      if (val != null)
        dataStreamReceiver = val;

      // Parameters used for getting the PIC software version
      val = getParameter("requestpicversion");
      if (val != null) getPicVersionCommand = val;
      val = getParameter("picversionreceiver");
      if (val != null) picVersionReceiver = val;

 

      tSemaphore=new CommSemaphore();
  }

  public Color getColorParameter(String paramName)
  {
      String val;
      Color theColor = null;
      val = getParameter(paramName);
      if (val != null) {
        if (val.compareTo("black") == 0)          theColor = Color.black;
        else if (val.compareTo("blue") == 0)      theColor = Color.blue;
        else if (val.compareTo("cyan") == 0)      theColor = Color.cyan;
        else if (val.compareTo("darkGray") == 0)  theColor = Color.darkGray;
        else if (val.compareTo("gray") == 0)      theColor = Color.gray;
        else if (val.compareTo("green") == 0)    theColor = Color.green;
        else if (val.compareTo("lightGray") == 0) theColor = Color.lightGray;
        else if (val.compareTo("magenta") == 0)  theColor = Color.magenta;
        else if (val.compareTo("orange") == 0)    theColor = Color.orange;
        else if (val.compareTo("pink") == 0)      theColor = Color.pink;
        else if (val.compareTo("red") == 0)      theColor = Color.red;
        else if (val.compareTo("white") == 0)    theColor = Color.white;
        else if (val.compareTo("yellow") == 0)    theColor = Color.yellow;
        else {
            try {
              theColor = Color.decode(val);
            }
            catch (java.lang.NumberFormatException excep) {
              theColor = null;
            }
            }
      }
      return theColor;
  }

  public void actionPerformed(ActionEvent event)
  {
      String kommando = event.getActionCommand();
      if (kommando =="Temp. START"){
          //her skal strengen til start af a/d konverteringen stå
          String command="<b";
          sendCmd(command);
      }
      if (kommando =="Temp. STOP"){
          //her skal stop kommandoen stå
          String command="<c";
          sendCmd(command);
      }
      // Coming up: String text = Integer.toHexString(value);
  }

  public String getAppletInfo()
  {
      return "Handles communication to/from a PIC that is attached to a WebNet.";
  }

  void status( String x )
  {
      if (x != null)
      showStatus(x);  // should apear in the "status window" of the browser
  }

//  public void paint(Graphics screen)
  //{
    //  tempReadout = analogValue*100/1024-25;//String.toString(toprint);
      //super.paint(screen);
      // Graphics2D screen2D=(Graphics2D) screen;
      // screen2D.setColor(Color.black);
      // screen2D.drawString("Temperatur i Celsius: " +tempReadout+" grader",5,50);
      // screen2D.drawString("(Dette vindue viser den aktuelle temperatur på WEBNET modul 3)",5,120);
      // screen2D.drawString("Copyright by: 3semit.dk  19/4-2002  rev.1.02)",5,140);
      // Her skal IF betingelsen for temperaturen indsættes(< -10 eller >+50)
      // if (tempReadout < -10) {
        //  screen2D.setColor(Color.red);
        //  screen2D.drawString("ADVARSEL!!! Temperaturen er for lav!!!",5,80);
        //    screen2D.drawImage(warning,500,50,this);
      // }
      // if (tempReadout > 50) {
      //    screen2D.setColor(Color.red);
      //    screen2D.drawString("ADVARSEL!!! Temperaturen er for høj!!!",5,80);
      //      screen2D.drawImage(warning,500,50,this);
      // }
      // screen2D.setColor(Color.black);
 
   
  // }

  public String getCommStatus()
  {
      if (sock != null)
        return "Ok!";
      else
        return "No connection";
  }

  public void sendCmd(String command)
  {
      if(runner==null) {
        startListener();
      }
      //      if (runner != null)
      {
        try
        {
            //meter.txOn(true);
            tSemaphore.lock();
            if (outStream != null && command != null) {
              outStream.print(command);
              outStream.flush();
              if (runner != null)  runner.sleep(20);
            }
            else {
              if (dataStreamReceiver != null)
                  doCallBack("No connection");
            }
            tSemaphore.unlock();
            //meter.txOn(false);
            // System.out.println("sendCmd: "+command );
        }
        catch( InterruptedException e ) {
            //meter.txOn(false);
            System.out.println("Exception in sendCmd():" + e.getMessage() );
            stopListener();
        }
      }
  }

  public
  synchronized
  void startListener()
  {
      if(runner==null) {
        runner = new Thread(this);
        if(runner!=null)  {
            tSemaphore.trylock();  // this will be released by run() procedure after init.
            runner.start();        // start running at run()
        }
      }
  }

  public synchronized void stopListener()
  {
      tSemaphore.unlock();
      runner = null;
  }

  public boolean reConnect()
  {
      boolean retVal=false;

      status("Connecting to host " + hostAddr );
      try { sock = new Socket( hostAddr, portNum);}
      catch (IOException e ) {
        if( e.getMessage()!=null )
            status("While opening connection: " + e.getMessage());
        sock = null;
      }
      if (sock != null) {
        try {
            sock.setSoTimeout( 2000 ); // timeout in [ms]
            inBuf = new BufferedReader( new InputStreamReader(sock.getInputStream()));
            outStream=new PrintWriter( sock.getOutputStream() );//use PrintWriter
            sock.setSoTimeout( 10000 ); // timeout in [ms]
            retVal = true;
            //if (meter != null) meter.enable(true);
        }
        catch( IOException e ) {
            if( e.getMessage()!=null ) {
              status("::start() while receiving upstream data: no data: " +
                      e.getMessage());
            }
            inBuf = null;
            outStream = null;
            sock = null;
        }
      }
      if (sock == null)
      {
        status("Connection refused by host" );
        //if (meter != null) meter.enable(false);
      }
      tSemaphore.unlock();
      return retVal;
  }

  public void requestPicSoftwareId()
  {
      if (!picVersionReported &&
          picVersionReceiver != null &&
          getPicVersionCommand != null)
      {
        try {runner.sleep(1000);}    // Wait for some time
        catch (InterruptedException slE) {}
        picVersionRequesting = true;
        sendCmd(getPicVersionCommand+"\n");
      }
  }


  public void start()
  {
      int retryCount = 3;
      boolean doRetry = true;
      String currentLine = getParameter("port");
      if (currentLine == null) portNum = 23;//telnet port******
      else                    portNum = Integer.parseInt(currentLine);
      hostAddr = getDocumentBase().getHost();

      sock = null;

      while (doRetry == true && retryCount-- > 0)
      {
        if (reConnect() == true)
            doRetry = false;
      }
      status("ok");

      if (!picVersionReported)
        requestPicSoftwareId();
  }

  public void stop()
  {
      if (sock != null) {
        try {sock.close();}
        catch ( IOException e ) {
            if( e.getMessage()!=null ) {
              System.out.println("sock.close() exception: " +
                                  e.getMessage());
            }
        }
      }
      outStream=null;
      inBuf = null;
      sock = null;
      stopListener();
      status("connection closed");
  }

  public void run()
  {
      int n=0;
      boolean replyUnknown=true;
      int fg, bg, grid, text;
      String currentLine;
      char charArray[];


      startListener();

      tSemaphore.unlock();
      //if (sock != null && meter != null) meter.enable(true);

      while ( runner != null && sock != null)
      {
        try {runner.sleep(20);}
        catch (InterruptedException slE) {}
        // meter.rxOn(false);
        if (inBuf != null)
        {
            try {
              currentLine = inBuf.readLine();
              // meter.rxOn(true);
            }
            catch (IOException e ) {
              currentLine = null;
              //meter.rxOn(false);
              status("No data available.");
            }
         
            if (currentLine != null)
              // her skal indsættes metode til udskrivning i text area
              t.append(currentLine+System.getProperty("line.separator"));
        }
      }
      stopListener();
  }





  /**
    * Returns parameters defined by this applet.
    * @return an array of descriptions of the receiver's parameters
    */

  // public java.lang.String[][] getParameterInfo()
  //{
      //String[][] info =
      //{
        //{"picversionreceiver", "String", "JavaScript function to receive PIC software version."},
        //{"requestpicversion", "String", "String with PIC command to request PIC software version."},
        // {"upstreamreceiver", "String", "JavaScript function to receive upstream data."},
        //{"port", "Number", "Telnet port number to connect."},
        //{"bgcolor", "Color", "Background color."},
        //{"rxcolor", "Color", "Color of the Rx LED."},
        //{"txcolor", "Color", "Color of the Tx LED."},
        //{"textcolor", "Color", "Color of the LED labels."}
    // };
    // return info;
  //}
//}

static int hexStringToInt(String line)
  {
      int value, index;
      char charArray[] = new char[256];
      if (line.charAt(0) == '<')
        line.getChars(2,5,charArray,0);
      else
        line.getChars(3,6,charArray,0);
      for (index = 0, value = 0; index<3; index++)
      {
        value *= 16;
        if (charArray[index] >= '0' && charArray[index] <= '9')
            value += charArray[index]-'0';
        else if (charArray[index] >= 'a' && charArray[index] <= 'f')
            value += charArray[index]-'a'+10;
        else if (charArray[index] >= 'A' && charArray[index] <= 'F')
            value += charArray[index]-'A'+10;
      }
      return value;
  }



  class CommSemaphore
{
  boolean locked;

  public CommSemaphore()
  {
      locked=false;
  }
 
  public synchronized  void lock()
      throws IllegalMonitorStateException, InterruptedException
  {
      if(locked) wait();
      locked=true;
  }

  public synchronized  boolean trylock()
  {
      boolean r=true;
      if(locked) {
        try {
            wait();
            locked=true;
        }
        catch ( Exception e ) {
            System.out.println("Semaphore::Exception:" + e.getMessage() );
            r=false;
        }
      }
      else
        locked=true;
      return r;
  }

  public synchronized void unlock()
  {
      locked=false;
      notify();  // will only start one waiting thread.
  }
}


    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
private void initComponents() {
 
    setFont(new java.awt.Font("Arial", 0, 12));
}

   


// Variables declaration - do not modify
// End of variables declaration

}
Avatar billede ronaldowitch Nybegynder
25. november 2002 - 14:38 #9
Tusind tak for din hjælp Carsten. Jeg tror godt jeg kan klare det nu. Men jeg lægger lige et indlæg igen hvis det bliver nødvendigt.

200 points til dig :-)
Avatar billede carstenknudsen Nybegynder
25. november 2002 - 15:10 #10
I skriver bare igen hvis der er noget,lige nu er layout'et jo
ikke så pænt (FlowLayout er lidt kedeligt, og man
bestemmer intet selv).
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester