Saturday, 1 February 2014

Event Classes:The AdjustmentEvent Class

AdjustmentEvent:BLOCK-DECREMENT,TRACK,INTEGER CONSTANT

The AdjustmentEvent Class

An AdjustmentEvent is generated by a scroll bar.

Adjustment events.


  • BLOCK_DECREMENT :

             The user clicked inside the scroll bar to decrease its value.

  • BLOCK_INCREMENT:

            The user clicked inside the scroll bar to increase its value.

  • TRACK:

         The slider was dragged.

  • UNIT_DECREMENT :

        The button at the end of the scroll bar was clicked to decrease its value.

  • UNIT_INCREMENT :

         The button at the end of the scroll bar was clicked to increase its value.

Event classes:The ActionEvent Class

The ActionEvent Class


An ActionEvent is generated when a button is pressed, a list item is double-clicked, or a menu item is selected.

The ActionEvent class defines four integer constants that can be used to identify any modifiers associated with an action event: 


  • ALT_MASK
  • CTRL_MASK
  • META_MASK
  • SHIFT_MASK
  • ACTION_PERFORMED

Event Handling

The event. Event handling is fundamental to Java programming because it is integral to the creation of applets and other types of GUI-based programs. 


The Delegation Event Model

The modern approach to handling events is based on the delegation event model, which defines standard and consistent mechanisms to generate and process events. Its concept is quite simple:a source generates an event and sends it to one or more listeners.In this scheme, the listener simply waits until it receives an event. Once an event is received, the listener processes the event and then returns.
                         In the delegation event model, listeners must register with a source in order to receive an event notification. This provides an important benefit: notifications are sent only to listeners that want to receive them.an event was propagated up the containment hierarchy until it was handled by a component. 

APPLET FUNDAMENTALS IN JAVA

APPLET PROGRAMMING
How to Build a java applet...

An applet is a small Java program that is embedded and ran in some other Java interpreter program such as 

  •  a Java technology-enabled browser
  •  Sun’s applet viewer program called appletviewer
Applets do not use the main() method for initiating the execution of the code.Applets,when loaded,automatically call certain methods of Applet class to start and execute the applet code.
Applets cannot run any program from the local computer and they are restricted from using libraries from other languages such as C or C++.

Monday, 27 January 2014

Reading and Writing Files in java

how to use reading and  writing file :fileInputStream:FileOutputStream.....


Reading and Writing Files



Java provides a number of classes and methods that allow you to read and write files. In Java, all files are byte-oriented, and Java provides methods to read and write bytes from and to a file Two of the most often-used stream classes are FileInputStream and FileOutputStream, which create byte streams linked to files.

Sunday, 26 January 2014

PrintWriter class in java

how to use printwriter class..

The PrintWriter Class


Although using System.out to write to the console is acceptable, its use is recommended mostly for debugging purposes or for sample programs. Java is through a PrintWriter stream. PrintWriteris one of the character-based classes.Using a character-based class for console output makes it easier to internationalize your program. PrintWriter supports the print( ) and println( ) methods for all types including Object.

READING CONSOLE INPUT

READ INPUT FROM  CONSOLE-JAVA

How to Read Input From Console in java

Reading console input in simple java console applications is a very straight forward process. Java provides developers two predefined streams in the java.lang.System class to read and write data to and from standard input and output devices. System.out is a standard output stream which is Console by default and System.in is predefined input stream which is Keyboard by default. To read user input in a console window we connect system.in with other stream classes available in java.io package.

Writing Console Output in java

how to work writing console output

Writing Console Output


Console output is most easily accomplished with print( ) and println( ). These methods are defined by the class PrintStream (which is the type of object referenced by System.out). Even though System.out is a byte stream, using it for simple program output is still acceptable.Because PrintStream is an output stream derived from OutputStream, it also implements the low-level method write( ). Thus, write( ) can be used to write to the console.

General form of writing console output

void write(int byteval)

This method writes to the stream the byte specified by byteval. Although byteval is declared as an integer, only the low-order eight bits are written.

Example for writing console output

// Demonstrate System.out.write().
class WriteDemo
 {
public static void main(String args[])
 {
int b;
b = 'A';
System.out.write(b);
System.out.write('\n');
}
}

You will not often use write( ) to perform console output (although doing so might be useful in some situations), because print( ) and println( ) are substantially easier to use.

I/O Basics in java

i/o basics,streams,byte streams:character stream..


I/O Basics

 Java’s support for console I/O is limited and somewhat awkward to use—even in simple example programs. Text-based console I/O is just not very important to Java programming.g, Java does provide strong, flexible support for I/O as it relates to files and networks. Java’s I/O system is cohesive and consistent. In fact, once you understand its fundamentals, the rest of the I/O system is easy to master.


Streams


Java programs perform I/O through streams. Astream is an abstraction that either produces or consumes information. A stream is linked to a physical device by the Java I/O system.All streams behave in the same manner, even if the actual physical devices to which they are linked differ. Thus, the same I/O classes and methods can be applied to any type of device.