Caricare documenti e articoli online 
INFtub.com è un sito progettato per cercare i documenti in vari tipi di file e il caricamento di articoli online.


 
Non ricordi la password?  ››  Iscriviti gratis
 

LEGGERE DA TASTIERA

informatica




LEGGERE DA TASTIERA


System.in // import java.io.InputStream

InputStreamReader lettore = new InputStremReader ( System.in ) // import java.io.InputStreamReader



BufferedReader console = new BufferedReader ( lettore )    // import java.io.BufferedReader


ConsoleReader console = new ConsoleReader ( System.in )

- readInt()

- readDouble()

- readLine()


String input = console.nextLine()

StringTokenizer word = new StringTokenizer ( input ) // import java.util.StringTokenizer

while (word.hasMoreToken () )



Scanner in = new Scanner ( System.in ) // import java.util.Scanner

- nextInt()

- nextDouble()

- nextLine()

- next()

- hasNext()

- hasNextInt()

- hasNextDouble()












STRING // import java.lang.String


- charAt ( posizione )

- length()

- toUpperCase()

- toLowerCase()

- subString( da, a ) / ( da )

- trim() // elimina spazi


- concat ( String )

- replace ( questiCaratteri, conQuestiAltri)



SUDDIVISIONE DI STRINGHE // import java.util.StringTokenizer


StringTokenizer tokenizer = new StringTokenizer ( " stringa " / console.readLine() )

- hasMoreToken ()

- nextToken ()



CHARACTER // import java.lang.Character


Character.isUpperCase( char )

.isLowerCase ( char )

.isLetter ( char )

.isDigit ( char )




STRING <--> INTEGER // java.lang.Integer / Double


int n = Integer.parseInt ( Stringa )

double n = Double.parseDouble ( Stringa )


String str = Integer.toString ( n )




SCRITTURA FILE


File doc = new File ( nomeDelFile ) // import java.io.File

- delete()

- renameTo ( refernceAdUnOggetoFile )


FileOutputStream out = new OutputStream ( doc ) // import java.io.FileOutputStream


PrintStream output = new PrintStream ( out ) // import java.io.PrintStream


PrintStream output = new PrintStream ( new FileOutputStream ( new File ( nomeFile ) ) )

- print ( stringa )

- println ( stringa )

- printf ( stringaFormatted , oggetti stringa )


//OPPURE


PrintWriter output = new PrintWriter ( "nomefile" ) // import java.io.PrintWriter

-print...


N.B

nomefile.close()



LETTURA FILE


FileInputStrem inp = new FileInputStream ( doc ) // import java.io.FileInputStream


InputStreamReader ( inp ) // import java.io.InputStreamReader


BufferedReader input = new BufferedReader ( inp ) // import java.io.BufferedReader

- readLine()


N.B

nomefile.close()




FINESTRE DI DIALOGO // import javax.swing.JOPtionPane


String input = JOPtionPane.ShowInputDialog ( prompt )

JOPtionPane.showMessageDialog ("Testo")

System.exit (0)



FORMATTAZIONE NUMERI // import java.text.NumberFormat


NumberFormat formatter = NumberFormat.getNumberIstance()

formatter.setMaximumFractionDigit ( int n )

formatter.setMinimumFractionDigit ( int n )


Double dato

dato = formatter.format ( dato )



GENERATORE NUMERI // import java.util.Random


import java.util.Random

Random generatore = new Random();

generatore.nextInt ( n ); // 0 <= x < n

generatore.nextDouble ();   // 0 <= x < 1



CONFRONTI


tra numeri in virgola mobile


final Double EPSILON = 1E-14;

if ( Math.abs ( x - y ) <= EPSILON )

// x è approssimativamente vicino a y



tra stringhe


String input


input == "y" // verifica l'identità dei riferimenti

input.equals("y)    // verifica l'identità delle stringhe

input.equals.IgnoreCase("y")


input.compareTo("y") < 0 (> = ) // verifica se input precede o segue "y" lessicograficamente



tra oggetti


// verifica identità riferimenti e il null

.equals(obj) // verifica identità oggetti, deve essere definita per la classe che lo usa



LISTA A PUNTATORI


class Node


Node link;

Object data;



Node list = new Node ( x, null );

list = new Node ( y, list );

list = new Node ( z, list );










CONTARE ITERAZIONI


for ( i = a; i < b; i++)


incremento = 1

- limiti asimmetrici n = b - a;

- limiti simmetrici n = b - a +1;


incremento > 1

- limiti asimmetrici n = b - a / c;

- limiti simmetrici n = b - a / c + 1


CLASSI INVOLUCRO


Byte, Boolean, Character, Double, Float, Integer, Long, Short


(versione java5.0)   (versioni precedenti)


Double d = 29.95  Double d = new Double ( 29.95 ) // WRAPPING


double x = d double x = d.doubleValue () // UNBOXING



FRAME // import javax.swing


JFrame frame = new JFrame()

- setSize ( pixel, pixel)

- setTitle ( String )

- setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE )

- setVisible ( true )

- pack()


- add ( component )

- setJMenuBar ( menuBar )





COMPONENTI GRAFICI // import


public class nuovoComponente extends JComponent




colore


g2.setColor ( Color.X )

g2.setColor ( 1.0F-0.0F(rosso), verde, blu)


g2.draw( disegno )

g2.fill ( disegno )


Color.BLACK

.BLUE

.CYAN

.GRAY

.GREEN

.ORANGE

.PINK

.RED

.WHITE

.YELLOW




rettangoli // import java.awt.Rectangle


new Rectangle (x, y, width, heigth)

- translate(x, y)


ellissi // import java.awt.geom.Elipse2D


new Ellipse2D.Double ( x, y, width, height )


segmenti // import java.awt.geom.Line2D


new Line2D.Double ( x1, y1, x2, y2)

new Line2D.Double ( Point2D, Point2D )


punti // import java.awt.geom.Point2D


new Point2D.Double ( x1, y1)



APPLET // import javax.swing.JApplet


public class MyApplet extends JApplet



NB vantaggio: nn richiede frame e componenti, si può visualizzare in un browser






visualizzazione applet in file.html



<applet code= "nomeMioApplet.class" width = "300" heigth="300">

</applet>



<html>

<head>

<title>inserirequiilnomedellapagina</title>

</head>

<body>

<p>inserirequiilnomedelmioapplet</p>

<applet code="nomeMioApplet.class" width="300" heigth="300" >

</applet>

<body>

</html>



TEMPORIZZATORE // import javax.swing.Timer


class MioRicavitore implements ActionListener




MioRicevitore listener new MioRicevitore()

Timer t = new Timer ( interval, listener);

t.start();







INTERFACCIA UTENTE


pulsanti


JButton button = new JButton ( String )

- addActionListener ( listener )

- isSelected ()


// mutuamente esclusivi

JRadioButton button = new JRadioButton ( String )

ButtonGroup group = new ButtonGroup()

group.add ( button )


// non esclusivi

JCheckBox casellaDiControllo = new JCheckBox ( String )


// molte scelte mutuamente esclusive

JComboBox caselleCombinata = new JComboBox ()

- addItem ( String )

- setEditable ()

- getSelectedItem ()



label


JLabel label = new JLabel ( String )

- setText ( String )


immagini


ImageIcon immagine = new ImageIcon(nomefileimmagine)


pannelli


JPanel panel = new JPanel()

-add ( componente )

-setLayout ( layout manager )

-setBorder ( new EtchedBorder () )

-setBorder ( new TitledBorder ( new EtchedBorder (), " Titolo ")


campi di testo


JTextField campo = new JTextField ( numero caratteri )

- getText


JTextArea textArea = new JTextArea ( rows, columns )

- setEdotable ( boolean )


JScrollPane barreDiScorrimento = new JScrollPane ( textArea )

textArea.setContentPane( barreDiScorrimento )



layout manager


panel.setLayout ( new FlowLayout() )

BorderLayout()

panel.add ( component , BorderLayout.NORTH

WEST

CENTER

EAST

SOUTH

new GridLayout( nRighe, nColonne)


EVENTI DEL MOUSE


public interface MouseListener



component.addMouseListener ()

event.getX()

event.getY()


public interface MouseAdapter



EXCEPTIONS


ClassNotFoundException


Thrown when an application tries to load in a class

through its string name using:

- the forName method in class Class

- the findSystemClass method in class ClassLoader

- the loadClass method in class ClassLoader

but no definition for the class with the specified name

could be found.


CloneNotSuportedException


Thrown to indicate that the clone method in class Object

has been called to clone an object, but that the object's

class does not implement the Cloneable interface.


DataFormatException


Signals that a data format error has occurred



IOException



EOFException


Signals that an end of file or end of stream has been

reached unexpectedly during input




FIleNotFoundException


Signals that an attempt to open the file denoted by

a specified pathneme has failed



RuntimeException



ArithmeticException


Thrown when an exceptional arithmetic condition

has occurre.For example, an integer "divide by zero"


ArrayStoreException


Thrown to indicate that an attempt has been made to

store the wrong type of object into an array of objects

Object x [ ] = new String [ 3 ];

x [ 0 ] = new Integer ( 0 );


ClassCastException


Thrown to indicate that the code has attempted to cast

an object to a subclass ofwhich it is not an istance.

Object x = new Integer ( 0 );

System.out.println ( ( String ) x ) ;


IllegalArgumentException


Thrown to indicate that a method has passed an illegal

or inappropriate argument


NumberFormatException

IllegalFormatException




IllegalStateException


Signals that a method has been invoked at an illegal

or inappropriate time. In other words, the Java

environment or Java application is not in an appropriate

state for the requested operation.


IndexOutBoundsException


Thrown to indicate that an index of some sort ( such as

to an array, to string, or to a vector )is out of range.


NullPointerException


Thrown when an application attemps to use null in a case

where an object is required. These include:

- Calling the instance method of a null object

- Accessing or modifing the field of a null object

- Taking the length of null as if it were an array

- Throwing null as if it were a Throwable value

Aplications should throw instance of this class to indicate

other illegal uses of the null object





Privacy




Articolo informazione


Hits: 2418
Apprezzato: scheda appunto

Commentare questo articolo:

Non sei registrato
Devi essere registrato per commentare

ISCRIVITI



Copiare il codice

nella pagina web del tuo sito.


Copyright InfTub.com 2024