Index of /~jpoial/java/naited

hundredcarriageSoftware and s/w Development

Nov 3, 2013 (3 years and 7 months ago)

363 views

Index of /~jpoial/java/naited



Parent Directory



Apples.java



Arv.java



Avaldis.java



Blah.java



Clock$1.class



Clock.class



Clock.htm
l



Clock.java



Collexample.java



Collexample5.java



ConsProd.java



ConsProd5.java



DirKlient.java



DirServer.java



Dklient.class



Dklient.html



Dklient.java



Dklient1.java



Dserver.class



Dserver.java



Erind.java



Erindi_kasutamine.java



Euclid.java



ExceptionUsage.java



Fact.java



Fail_massiiv.java



Failid.java



FileExamples.java



File_and_Array.java



Fnaide.java



FondiParameetrid.java



FondiParawt.java



For.java



Gr
aafika2.java



H8$1.class



H8.class



H8.htm
l



H8.java



Hanoi.java



HelloApple
t.java



HelloFrame.java



HelloJFrame$1.class



HelloJFrame.class



HelloJFrame.html



HelloJFrame.java



Hinne.java



HinneTest.java



Isort1.java



JRakend$1.class



JRakend$2.class



JRakend.class



JRakend.html



JR
akend.java



JUnit_with_Eclipse.pdf



Jarjesta.java



Joonis$1.class



Joonis$2.class



Joonis$3.class



Joonis.class



Joonis.html



Joonis.java



JuhuMaatriks.java



Juhumaatriks.java



Katsed.java



Kellad.java



Keskmin
e.java



Kjag.java



Kjag2.java



Kogum
id.java



Krypto.java



Kuu1.java



Kuud.
java



Kuusk.java



Lihtne.java



Lii
des1.java



Liides2.java



Liides3.java



Liides4.java



Liides5.java



Lineaarne.java



LoeMaatriks.java



Loomad.java



Loomad.pas



Loomad1.pas



Loomad_ClassCastException.java



Maatr.java



Maatriks.java



Massiiv1.java



Massiiv2.java



MassiivMax.java



Massiivid.java



Muster.java



MyThread.class



N2idisylesanded.html



NullideArv.java



Nullilugeja.java



P.java



P2.java



P33.java



P34.java



P35.java



P4.java



P5.java



P6.java



PersonMain.java



Pikkused.java



Pilt.java



Pipes.java



Preili.java



ProdConSelective.java



ProdConSelective5.java



Programming
-
Assembler.pdf



Rakend$1.class



Rakend.class



Rakend.html



Raken
d.java



Rong.java



RunnableCP.java



RunnableCP5.java



Ruutjuur1.java



Ruutjuur2.java



Ruutjuur3.java



Ruutvorrand.java



Ruutvorrand1.java



Sagedused.java



Skalaar.java



Soned.java



SqrtTab.java



Tabel1.java



Tegurid.java



Test



TextIO.class



TextIO.java



Threads.java



Torud.java



Uuskell$1.class



Uuskell.class



Uuskell.java



Vork.java



Wfreq.java



Wfreq5.java



Y.java



generics
-
tutorial.pdf



glossary.pdf



hellolnx.s



junit
-
4.7.jar



junit4x.pdf



pildid/

// <pre>

//
---------------------------------------------------------------------
-----------

// file: Apples.java


import java.io.*;


/** Example with different exceptions.


* @author Jaanus Poial


* @version 0.2 spring 2006


*/

public class Apples {



/** Main and only method. */


public static void main (String[] args) {


int n = 0;


int m = 0;


while (true) {


try {


BufferedReader inp

= new BufferedReader


(new InputStreamReader (System.in));


System.out.println ("Press ctrl
-
C to quit");


System.out.print ("Number of children (n): ");


String s = inp.readLine();


n = Inte
ger.parseInt (s);


if (n<0)


throw new IllegalArgumentException ("n = " +
String.valueOf (n));


System.out.print ("Number of apples (m): ");


s = inp.readLine();


m = Integer.parseInt (s);


if (m<0)


throw new IllegalArgumentException ("m = " +
String.valueOf (m));


System.out.println ("Each child got "


+ String.valueOf (m/n) + " apples and "


+ String.valueOf (m%n) + " remains");


}


catch (ArithmeticException e) {


System.out.println ("Caught arithmeticexception: " +
e.toString());


}


catch (Exception other) {


System
.out.println ("Problem: " + other.toString());


}


finally {


System.out.println ("n = " + n + " m = " + m);


}


}


} // main


} // Apples


// end of file

//
-------------------------------------------------------
--------------
----------------

// </pre>







import java.util.*;


/** N&auml;iteobjekt, mis sisaldab <code> int </code> t&uuml;&uuml;pi


* v&auml;lja. Isendid on v&otilde;rreldavad suuruse j&auml;rgi.


* @author Jaanus P&ouml;ial


* @since 1.5


*/

public class Arv implements Comparable<Arv> {



/** Isendimuutuja. */


private int sisu = 0;



/** Konstruktor uue objekti loomiseks. */


Arv (int i) {


sisu = i;


}



/** Teine konstruktor, mis loob objekti stringist. */


Arv (String s)

{


sisu = Arv.parseArv (s);


}



/** Avalik meetod andmete lugemiseks objektist. */


public int arvValue() {


return sisu;


}



/** Objekti esitus stringina. */


@Override


public String toString() {


return String.valueOf (this.arvValue());


}



/** Kas kaks objekti on sisu poolest v&otilde;rdsed. */


@Override


public boolean equals (Object o) {


int osisu = ((Arv)o).arvValue();


return this.arvValue() == osisu;


}



/** Li
idese Comparable kohustuslik meetod. */


public int compareTo (Arv o) {


int osisu = ((Arv)o).arvValue();


if (this.arvValue() == osisu)


return 0;


else


if (this.arvValue() > osisu)


return 1;


else


return
-
1;


}



/** Koopia tegemine. */


@Override


public Object clone() {


return new Arv (arvValue());


}



/** Vabrik. */


public static Arv valueOf (int i) {


return new Arv (i);


}



/** Teine vabrik stringist
loomiseks. */


public static Arv valueOf (String s) {


return new Arv (s);


}



/** Teisendus stringist arvuks. */


public static int parseArv (String s) {


return Integer.parseInt (s);


}



/** Kahe arvu liitmine. */


public Arv pl
uss (Arv a) {


return new Arv (this.arvValue() + a.arvValue());


}


// teised tehted tehakse analoogiliselt liitmisega



/** Peameetod. Rakenduse kohustuslik meetod. */


public static void main (String[] args) {


if (args.length > 0) {


int i = Arv.parseArv (args[0]);


System.out.println (args[0]);


System.out.println (Arv.valueOf (i).toString());


System.out.println (Arv.valueOf (args[0]).toString());


}


Arv a1 = new Arv (2);


Arv a2 = Arv
.valueOf (
-
1);


Arv a3 = (Arv)a2.clone();


System.out.println ("Peab olema true:");


System.out.println (a2.equals (a3));


System.out.println (a2 != a3);


System.out.println (a2.compareTo (a3) == 0);


System.out.println (a2.eq
uals (a2));


System.out.println (a2 == a2);


System.out.println (a2.compareTo (a2) == 0);


System.out.println (a1.compareTo (a2) > 0);


System.out.println (a2.compareTo (a1) < 0);


System.out.println (!a1.equals (a2));


System
.out.print (a1 + " + " + a2 + " = ");


System.out.println (a1.pluss (a2));


ArrayList<Arv> l = new ArrayList<Arv>();


for (int i = 0; i < 10; i++) {


l.add (new Arv ((int)(Math.random()*100.)));


}


System.out.println (l);


Collections.sort (l);


System.out.println (l);


}


}











/*


* @(#)Blah.java 1.82 99/03/18


*


* Copyright (c) 1994
-
1999 Sun Microsystems, Inc.


*/



package java.blah;


import java.blah.blahdy.BlahBlah;


/**


* Class description goes here. Even more explanations may follow.


*


* @version

1.82 18 Mar 1999


* @author

Firstname Lastname


* @since 1.2


*/

public class Blah extends SomeClass {



/** classVar1 documentation comment */


public static int cla
ssVar1;



/** instanceVar1 documentation comment */


public Object instanceVar1;



/**


* ...constructor Blah documentation comment...


*/


public Blah() {


// ...implementation goes here...


}



/**


* ...method doSom
ethingElse documentation comment...


* @param someParam description


* @return return value description


*/


public int doSomethingElse(Object someParam) {


// ...implementation goes here...


}


} // Blah





/ <pre>

//
---------------------------------------------------------------------
----------------------

// file: Clock.java


import java.applet.Applet; // our clock will be an applet

import java.awt.*;

import java.awt.event.*;

import java.util.Date; // new Dat
e() is used to return the current
time


/** Thread and Applet put together.


* @author Jaanus Poial


* @version 0.2 spring 2006


* @since 1.2


*/

public class Clock extends Applet implements Runnable {



/** clock thread */


private Thread thread = nul
l;



/** one tick in milliseconds */


int tick = 1000;



/** is the clock suspended? */


private boolean suspended;



/** our clock has to implement the Runnable interface */


public void run() {


while (true) { // run forever


try {


Thread.sleep (tick); // sleep time is in milliseconds


synchronized (this) {


while (suspended) {


wait();


}


} // end of critical section


}


ca
tch (InterruptedException e) {


}


repaint(); // renew the clock state


}


} // run



/** screen drawing to output the result */


public void paint (Graphics screen) {


screen.drawString (new Date().toString(), 50, 25);


}

// paint



/** Applet init */


public void init() {


if (thread == null) {


thread = new Thread (this);


thread.start();


}


} // init



/** Applet start */


public synchronized void start() {


suspended = false;


notifyAll();


} // start



/** Applet stop */


public synchronized void stop() {


suspended = true;


notifyAll();


} // stop



/** Applet destroy, hardly ever called */


public void destroy() {


if (thread != null) {



thread.interrupt();


thread = null;


}


} // destroy


//
------------------

end of important part
----------------------------
-




/** Applet appears to be Serializable */


private static final long serialVersionUID =
-
856437094452949
6313L;



/** Clock can be used also as an application */


public static void main (String[] param) {


Frame myFrame = new Frame ("I made this clock");


myFrame.setSize (350,80);


Clock myClock = new Clock(); // Runnable Applet


myFrame.add (myClock);


myFrame.setVisible (true);


myClock.init();


myClock.start();


myFrame.addWindowListener (new WindowAdapter () {


public void windowClosing (WindowEvent e) {


((Clock)((Frame)e.getWindow(
)).getComponent (0)).stop();


((Clock)((Frame)e.getWindow()).getComponent (0)).destroy();


System.exit (0);


}


} );


} // main


} // Clock


// end of file

//
------------------------------------------------------------
---------
--------------------

// </pre>




// <pre>

//
---------------------------------------------------------------------
-----

// file: Collexample.java


import java.util.*;


/**


* Using ArrayList and HashMap.


* @author Jaanus Poial


* @version 0.4 spring 2006


* @since 1.2


*/

public class Collexample {



/**


* Main method.


* @param parameters command line parameters.


*/


public static void main (String[] parameters) {



final int SIZE = 100;


ArrayList rand
omNumbers = new ArrayList (SIZE);


Random generator = new Random();


for (int i=0; i < SIZE; i++) {


randomNumbers.add (new Integer (generator.nextInt(1000)));


}


System.out.println (maximum (randomNumbers));



HashMap cou
rses = new HashMap();


courses.put ("I200", "Java");


courses.put ("I209", "Algorithms");


courses.put ("K402", "Programming II");


courses.put ("K022", "Applications: Internet");



Iterator codes = courses.keySet().iterator();


while (codes.hasNext()) {


System.out.println (codes.next());


}



String course = (String)courses.remove ("K022");


System.out.println (course);



codes = courses.keySet().iterator();


String code;


while (codes
.hasNext()) {


code = (String)codes.next();


System.out.println (code + " " + (String)courses.get (code));


}



System.out.println (randomNumbers);


Object tmp;


for (int i=0; i < randomNumbers.size()/2; i++) {


tmp = randomNumbers.get (i);


randomNumbers.set (i, randomNumbers.get (randomNumbers.size()
-
i
-
1));


randomNumbers.set (randomNumbers.size()
-
i
-
1, tmp);


}


System.out.println (randomNumbers);



System.out.println (maximum2 (ra
ndomNumbers));



} // main



/**


* Finding a maximal element of a list.


* @param a list


* (satisfies interface java.util.List,


* elements satisfy interface Comparable).


* @return maximal element.


* @throws IndexOutOfBoundsException if the list is empty.


*/


static public Comparable maximum (List a) {


Comparable maxelem;


if (a == null)


throw new IndexOutOfBoundsException (" maximum got a null
list");


if (a.size()

< 1)


throw new IndexOutOfBoundsException (" maximum got an empty
list");


maxelem = (Comparable)a.get (0);


for (int i=0; i < a.size(); i++) {


if (maxelem.compareTo ((Comparable)a.get (i)) < 0)


maxelem = (Comparable
)a.get (i);


}


return maxelem;


} // maximum



/**


* Finding a maximal element of a collection.


* @param a Collection, elements satisfy interface Comparable.


* @return maximal element.


* @throws NoSuchElementException if <
code> a </code> is empty.


*/


static public Comparable maximum2 (Collection a) {


Comparable maxelem;


if (a == null)


throw new IndexOutOfBoundsException (" maximum2 got a null
collection");


Iterator iter = a.iterator();



if (iter.hasNext())


maxelem = (Comparable)iter.next();


else throw new NoSuchElementException (" maximum2 got an empty
collection");


Comparable c;


while (iter.hasNext()) {


c = (Comparable)iter.next();


i
f (maxelem.compareTo (c)<0)


maxelem = c;


}


return maxelem;


} // maximum2


} // Collexample


// end of file

//
---------------------------------------------------------------------
--------------

// </pre>





// <pre>

//
---------------------------------------------------------------------
-----

// file: Collexample5.java


import java.util.*;


/**


* Using ArrayList and HashMap.


* @author Jaanus Poial


* @version 0.5 spring 2006


* @since 1.5


*/

public class Collexample5
{



/**


* Main method.


* @param parameters command line parameters.


*/


public static void main (String[] parameters) {



final int SIZE = 100;


ArrayList < Integer > randomNumbers = new ArrayList < Integer >
(SIZE);


Random
generator = new Random();


for (int i=0; i < SIZE; i++) {


randomNumbers.add (new Integer (generator.nextInt(1000)));


}


System.out.println (maximum (randomNumbers));



HashMap < String, String > courses = new HashMap < String,

String
>();


courses.put ("I200", "Java");


courses.put ("I209", "Algorithms");


courses.put ("K402", "Programming II");


courses.put ("K022", "Applications: Internet");



Iterator < String > codes = courses.keySet().iterator();


while (codes.hasNext()) {


System.out.println (codes.next());


}



String course = courses.remove ("K022");


System.out.println (course);



codes = courses.keySet().iterator();


String code;


while (codes.hasNext
()) {


code = codes.next();


System.out.println (code + " " + courses.get (code));


}



System.out.println (randomNumbers);


Integer tmp;


for (int i=0; i < randomNumbers.size()/2; i++) {


tmp = randomNumbers.get

(i);


randomNumbers.set (i, randomNumbers.get (randomNumbers.size()
-
i
-
1));


randomNumbers.set (randomNumbers.size()
-
i
-
1, tmp);


}


System.out.println (randomNumbers);



System.out.println (maximum2 (randomNumbers));



} // main



/**


* Finding a maximal element of a list.


* @param a list


* (satisfies interface java.util.List,


* elements satisfy interface Comparable).


* @return maximal element.


* @throws IndexOutOfBoundsException if the list

is empty.


*/


static public < T extends Object & Comparable < ? super T > > T


maximum (List < ? extends T > a) {


T maxelem;


if (a == null)


throw new IndexOutOfBoundsException (" maximum got a null
list");


if (a.size() < 1)


throw new IndexOutOfBoundsException (" maximum got an empty
list");


maxelem = a.get (0);


for (int i=0; i < a.size(); i++) {


if (maxelem.compareTo (a.get (i)) < 0)


maxelem = a.get (i)
;


}


return maxelem;


} // maximum



/**


* Finding a maximal element of a collection.


* @param a Collection, elements satisfy interface Comparable.


* @return maximal element.


* @throws NoSuchElementException if <code> a <
/code> is empty.


*/


static public < T extends Object & Comparable < ? super T > > T


maximum2 (Collection < ? extends T > a) {


T maxelem;


if (a == null)


throw new IndexOutOfBoundsException (" maximum2 got
a null
collection");


Iterator < ? extends T > iter = a.iterator();


if (iter.hasNext())


maxelem = iter.next();


else throw new NoSuchElementException (" maximum2 got an empty
collection");


for (T c : a) {


if
(maxelem.compareTo (c) < 0)


maxelem = c;


}


return maxelem;


} // maximum2


} // Collexample5


// end of file

//
---------------------------------------------------------------------
--------------

// </pre>


// <pre>


// Fail Joo
nis.java


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


/**


* Joonistamine rakendis hiire kuulamisega.


* @author Jaanus Poial


* @version 0.1 sygis 2004


* @since 1.2


*/

public class Joonis extends JApplet {



/** Peameetod rakenduse jaoks, mis omakorda ka"ivitab rakendi.


*/


public static void main (String[] parameetrid) {



// konteiner graafikaelementide paigutamiseks


JFrame raam = new JFrame ("Joonis");



// JApplet isend (rakend) si
nna raami sisse panemiseks


Joonis rakend = new Joonis();



// raami suuruse m22ramine


raam.setSize (210, 230); // ca 200x200 sisu jaoks



// rakendi paigutamine raami sisse


raam.getContentPane().add (rakend); // swing erip2ra



// p66rdume rakendi initsialiseerimiseks


rakend.init();



// p66rdume rakendi k2ivitamiseks


rakend.start();



// raami ekraaniletoomine


raam.setVisible (true);



// raami k2itumise kirjeldus (kuidas reageerib syndmust
ele)


raam.addWindowListener (new WindowAdapter() {


public void windowClosing (WindowEvent e) {


((Joonis)


((JFrame)e.getWindow()).getContentPane().getComponent
(0)).


stop();


((Joonis)



((JFrame)e.getWindow()).getContentPane().getComponent
(0)).


destroy();


System.exit (0);


}


public void windowActivated (WindowEvent e) {


e.getWindow().repaint();


}


} );


}
// main




/** Rakendi initsialiseerimine (yks kord alguses).


*/


public void init() {


Container sisu = getContentPane();


sisu.setLayout (new BorderLayout());



JPanel tahvel = new JPanel();


sisu.add (tahvel, BorderLayout.CENTER);


tahvel.addMouseListener (new MouseAdapter() {


public void mouseClicked (MouseEvent e) {


int x = e.getX();


int y = e.getY();


JPanel t = (JPanel)e.getSource();



int m = Math.min (t.getWidth()
-
x
-
1, t.getHeight()
-
y
-
1);


int r = (int)(Math.random()*Math.min (m, Math.min (x, y)));


// int r = Math.min (m, Math.min (x, y));


Graphics gk = t.getGraphics();


gk.drawO
val (x
-
r, y
-
r, 2*r, 2*r);


} // mouseClicked


});



JButton nupp = new JButton ("Puhasta");


sisu.add (nupp, BorderLayout.SOUTH);


nupp.addActionListener (new ActionListener() {


public void actionPerformed (ActionEvent
e) {


Joonis see = (Joonis)((JRootPane)(((JLayeredPane)(((JPanel)


(((JButton)e.getSource()).getParent())).getParent())).


getParent())).getParent();


see.repaint();


} // actionPerformed lopp



} // kuulariklassi lopp


);



JLabel silt = new JLabel ("Klikka siia alla ");


sisu.add (silt, BorderLayout.NORTH);


} // init



/** Rakendi aktiviseerimisel t2idetakse see meetod. */


public void start() {


} // start



/** Rakendi passiivseks muutumisel t2idetakse see meetod. */


public void stop() {


} // stop



/** Rakendi h2vitamisel saab clean
-
up teha selles meetodis. */


public void destroy() {


} // destroy



private static final long serialVersionUI
D =
-
8564370944529496313L;



} // Joonis lopp


// faili l6pp


// </pre>