[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Vis indhold af fil i Java



Anders Misfeldt wrote:

On Mon, 08 Mar 2004 16:01:18 +0100
Daniel Löfquist <sslug@sslug> wrote:



Du skulle kunna ha en tråd som med jämna mellanrum kontrollerar en fil och sedan uppdaterar din JLabels innehåll.




Kan du give et eksempel koden for det?


Jeg har prøvet:


File status = new File("/tmp/", "status"); stat = new JLabel(status);

Men det giver følgende:

Test.java:161: cannot resolve symbol
symbol  : constructor JLabel (java.io.File)
location: class javax.swing.JLabel
       picture = new JLabel(status);


Mvh


Anders




Följande metod borde(jag har inte provkört koden) returnera en sträng som innehåller första raden i din textfil:

public String readLineFromFile(File f){
	String lineStr;
	try{
		if(f.exists()){
			BufferedReader inFile = new BufferedReader(new FileReader(f));
			lineStr=inFile.readLine();
			inFile.close();
		}
		
	}catch(Exception ioe){
		System.out.println("PC LOAD LETTER");
	}
	return lineStr;
}

Att sedan stoppa in denna i din JLabel skulle kunna se ut så här ungefär:

File status= new File(sökväg, etc.);
JLabel minJLabel=new JLabel(readLineFromFile(status));

Om det du skriver är en applet eller nåt sånt som skall uppdateras i realtid får du skriva en tråd som kollar textfilen med jämna mellanrum och uppdaterar minJLabel med

minJLabel.setText(readLineFromFile(status));

eller något liknande. Det borde funka.

//Daniel


-- Excuse me, I believe you have my stapler...?



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *