Tips&Tricks | I trucchi del mestiere |
![]() |
Come leggere la data corrente |
public class my_data { private
SimpleDateFormat formatter; public my_data()
{ |
![]() |
Come ordinare per colonna una JTable |
import javax.swing.table.TableModel; import java.awt.event.MouseAdapter;
public TabellenModel
(int columnCount)
public void
mausHorchtAufTabelle(JTable table) public void
setValues (Collection src) public String
getColumnName(int columnIndex) public void
setValues (String [] [] src)
for (int
i = 0; i < columnCount; ++i) rows.insertElementAt
(newRow, index); /** /**
/** // Einlesen
der Tabelle und in tempVariablen hauen // sortieren
des String[] // löschen
der Tabelle // neu füllen
der Tabelle, je nach dem, welche Richtung public Object
getValueAt (int rowIndex, int colIndex)
public int
getRowCount ()
/** |
![]() |
Come leggere un file di testo zippato |
public String
readZippedFile(String textFilename, String zipFilename) throws Exception |
![]() |
Come fare la copia profonda di un qualsiasi oggetto |
public class ObjectCloner private ObjectCloner(){} // returns
a deep copy of an object ObjectOutputStream
oos = null; // serialize
and pass the object ByteArrayInputStream
bin = // return
the new object } |
![]() |
Come realizzare uno sniffer |
import java.io.*; public class
jps private
static void main(String[] args) Socket connect=null; showHeader(); if (numofparams
== 1) { //if they only put in a host name } private
static void showHeader() { System.out.println(""); } |
![]() |
Come fare calcoli in RPN |
import java.io.*; public class
Revpol String ans=new String(); Stack numbers; elements=words(args.trim()); try{ if(elements[i].equals("+"))numbers.push(String.valueOf(a+b)); for(int
i=0;i<line.length();i++) boolean
isNumber(String testdata) } for(int
j=(ntestdata.length)-1;j>0;j--) if(ntestdata[0]=='-')k=k*-1; return k; } |
![]() |
Come cambiare il colore delle scroll-bar di una finestra |
<html> <script> </html> |
![]() |
Come richiamare la funzione "Salva con nome" di Internet Explorer |
<html> function
Richiama_SaveAS() <body
onload="avviata=true"> |
![]() |
Come ridimensionare un'immagine dinamicamente |
<html> minimumXsize
= 50; maximumXsize
= 250; App_avviata = false; function
Ridimensiona(dragEvent,which) function
Ripristina_Dimensioni(which){ </script> <title>Ridimensionamento
dinamico delle immagini</title> <img src="0.jpg" <img src="1.jpg" </center> |
![]() |
Come creare un menu riposizionabile nella pagina |
<html> <script> function
Setta_variabili() function
setObject(a) function
getObject(){ function
releaseObject() function
SpostaOB() var isNav
= (navigator.appName.indexOf("Netscape") !=-1) function
MoveHandler(e) if (isNav) <BODY
onload="Test_browser();"> |
![]() |
Come utilizzare i socket |
namespace
SaurabhNet { //Class
which shows the implementation of the TCP Date server //This method
Accepts new connection and
namespace
SaurabhNet { //Main Entry
point of the client class |
![]() |
Come implementare una coda |
|
![]() |
Come passare ad una funzione un numero variabile di argumenti |
class ParamsTest |
![]() |
Come utilizzare la struttura DateTime |
class DOB{ private
DateTime dtDob; /* legge
la data di nascità */ Console.Write("inserisci
il giorno incui sei nato : " ); catch (Exception
e) { /* calcola
lìetà in mesi */ /* calcola
lìetà in giorni */ for (int
i=dtDob.Year+1;i < dtNow.Year;i++) { intAgeDays+=dtNow.DayOfYear; return intDayTemp1-intDayTemp2; |
![]() |
Come manipolare le stringhe in C# |
using System; class MyString Console.WriteLine("String
Value: {0}",strData); // Convert
string to LowerCase //Convert
String to UpperCase //Convert
String to ProperCase for(int
iIndex=0;iIndex < strParam.Length;iIndex++) // Function
to Reverse the String // Function
to Test for Palindrome // Function to get string from beginning. public static
String Left(String strParam,int iLen) //Function
to get string from end //Function
to count no.of occurences of Substring in Main string //Not available
in C# //Useful
Function can be used whitespace stripping programs //Function Replace string function. // Currently
Not Available in C#
|
![]() |
Come implementare un visualizzatore di immagini |
csc /target:winexe /reference:System.dll /reference:System.Winforms.dll myHelpItem.MenuItems.Add(new
MenuItem("&About" , new EventHandler(OnAbout) , Shortcut.CtrlA)); protected override
void OnPaint(PaintEventArgs myArgs) private void OnAbout(Object
mySender , EventArgs myArgs) private void checkMenus(Object
mySender , EventArgs myArgs) private void ShowNative(Object
mySender , EventArgs myArgs) private void OnClose(Object
mySender , EventArgs myArgs) private void OnExit(Object
mySender , EventArgs myArgs) private void OnOpen(Object
mySender , EventArgs myArgs) if (myDialog.ShowDialog()
== DialogResult.OK) public static void
Main(string[] args) |
![]() |
Come utilizzare l'overload |
using System; class Rectangle public Rectangle() public int
Width public int
Area /* OverLoading == */ public static
bool operator==(Rectangle a,Rectangle b) /* OverLoading != */ public static
bool operator!=(Rectangle a,Rectangle b) /* Overloding > */ public static
bool operator>(Rectangle a,Rectangle b) /* Overloading
< */ /* Overloading >= */ public static
bool operator >= (Rectangle a,Rectangle b) /* Overloading <= */ public static
bool operator <= (Rectangle a,Rectangle b) public override
String ToString() if(objRect1==objRect2) if(objRect1==objRect3) |
![]() |
Come utilizzare gli array |
using System; public class
ArrayMembers Console.WriteLine("\n\n"); //Declare
array strNames //Iterate
through the items of array strNames |
![]() |
Come manipolare le stringhe in C# |
using System; class MyString Console.WriteLine("String
Value: {0}",strData); // Convert
string to LowerCase //Convert
String to UpperCase //Convert
String to ProperCase for(int
iIndex=0;iIndex < strParam.Length;iIndex++) // Function
to Reverse the String // Function
to Test for Palindrome // Function to get string from beginning. public static
String Left(String strParam,int iLen) //Function
to get string from end //Function
to count no.of occurences of Substring in Main string //Not available
in C# //Useful
Function can be used whitespace stripping programs //Function Replace string function. // Currently
Not Available in C# |
![]() |
Come ottenere l'allineamento a destra |
#include <iostream> |
![]() |
Come emettere un beep |
const char BEEP = '\a'; |
![]() |
Come calcolare una radice quadrata da record |
union FastSqrtUnion{ float d; unsigned long i;}; |
![]() |
Come effettuare le conversioni di temperatura |
#include <iostream.h> class TempConversions void c2f(void)
{ cout << (temp * 1.8 + 32) << " degrees Fahrenheit"
<< endl << endl; }; void k2f(void)
{ cout << ((temp - 273.15) * 1.8 + 32) << " degrees Fahrenheit"
<< endl << endl; }; double temp; int main(void) short int
choice; system("cls");//clears
the screen each time to make it neat do do cout <<
"Please enter the temperature: "; switch(choice) do cout <<
endl; return 0; |
![]() |
Come trovare numeri primi |
#include <math.h> using namespace
std; // specify that everything in the std namespace // Increase
this constant and enlarge the factor wheel to speed up testing of // Used in
our wheel factorization // isprime() // Here
we must check the divisors our wheel is based upon. In this case if ((thenumber
% 2 == 0) || (thenumber % 3 == 0) || (thenumber % 5 == 0) //If the
number is <50 it was covered above, exit it's prime. // if thenumber
has a divisor <= its square root, if ((div
= factorwheel[loop] + mult) > sqroot) if (thenumber
% div == 0) // if no
divisor has been found, it is a prime
// open
the output file // for each
number between startnumber and endnumber inclusive, if (startnumber
< 4) switch (start)
for (register
int smallnumber = start; smallnumber < 4 && smallnumber <
endnumber; smallnumber++) if (start
< 6) for (register
long int number = start; number - 1 <= endnumber ; number += 6) if ((number
+ 1 >= startnumber) && (number + 1 <= endnumber) &&
isprime(number + 1)) // report
how many primes // end the
program |
![]() |
Come scoprire se una stringa contiene numeri |
// str must be \0-terminated // Using
std::string::c_str() is less efficient if( *si=='-'
|| *si=='+' ) ++si;
|
![]() |
Come realizzare un token |
#include <string.h> class cToken public: char* NextToken(char*
NewDelimiter=NULL){ int MoreTokensExists(){return strlen(strNextToken);} SetNew(char
*Token,char *Delimit){ ~cToken(){ |
![]() |
Come eliminare gli spazi vuoti in una stringa |
Private Function Pack(str As String) As String words = Split(str,
" ") |
![]() |
Come stampare una pagina Web |
Public Sub StampaWeb(URL As String) |
![]() |
Come nascondere l'applicazione dai task attivi |
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long Public Const
RSP_SIMPLE_SERVICE = 1 ' Per nascondere l'applicazione invocare la seguente procedura: Public Sub
MakeMeService() pid = GetCurrentProcessId() ' Per far riapparire l'applicazione nella lista dei task attivi: Public UnMakeMeService() pid = GetCurrentProcessId() |
![]() |
Come reperire la velocità del processore |
function GetCPUSpeed: Double; SetPriorityClass(GetCurrentProcess,
REALTIME_PRIORITY_CLASS); Sleep(10);
SetThreadPriority(GetCurrentThread,
Priority); Result :=
TimerLo / (1000.0 * DelayTime); // Per utilizzare la funzione: Caption:=Format('%f MHz', [GetCPUSpeed]); |
![]() |
Come aggiungere un file al menu documenti di Start |
uses ShellAPI, ShlOBJ; procedure
StartDocumentsMenu( FlePath : string ); // Ecco come utilizzare la procedura appena proposta: StartDocumentsMenu( 'c:\temp\readme.txt' ); |
![]() |
Come realizzare uno screen-saver |
Procedure TForm1.ScreenShot(x : integer; y : integer; Width : integer; Height : integer; bm : TBitMap); begin bm.Width
:= Width; if (GetDeviceCaps(dc,
RASTERCAPS) AND RC_PALETTE = RC_PALETTE) then |
![]() |
Coma analizzare il contenuto di una cartella |
function Cartella(nomeCartella) { |
![]() |
Come effettuare lo streaming di un file . mp3 |
<a href="http://www.xxxx/mp3.asp?play=file.mp3"> Play di un file MP3 </a> |
![]() |
Come evitare la memorizzazione delle pagine in cache |
<% |