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");
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.
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"); } }
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; }
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
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 */
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"); } }
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; }
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
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).
Synes godt om
Ny brugerNybegynder
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.