Thursday, March 19, 2009

helloOBJECT
/*Exercise 5
 **Name of Program:helloObject
 *Programmer name:Tomarocon, Rolando
 *Date:March 19,2009
 *Purpose:To enter words then it will reverse.


import java.util.Scanner; 
public class helloObject 

  public static void main(String[] args)  
  { 
  String greetings; // Used for the input string. 
  Scanner input=new Scanner(System.in); 
  System.out.println("pls.........Enter ur Greeting:"); 
  greetings=input.nextLine(); 
  System.out.println(greetings); 
  } 
}
*/OUTPUT:

heloo

heloo

*/
===================================================================
NAME ECHO
/*Exercise 4
 **Name of Program:nameEcho
 *Programmer name:Tomarocon, Rolando
 *Date:March 19,2009
 *Purpose:Enter 2 words then the second word will be capital letter.

import java.util.Scanner;
import javax.swing.*;
import java.io.*;


public class nameEcho{
public static void main(String[] args) throws IOException// main method using catch Exceptions
{
String b;//first input string 
String c;//second input string

String a=JOptionPane.showInputDialog("Enter your Name: ");//ask input from the user

b=a.substring(a.indexOf(" "),a.length()).toUpperCase();// uppercase method
c=a.substring(0,a.indexOf(" "));

System.out.println("Input in normal form : " + a);// Print the normal string
System.out.println("Output: " +c+ " "+b);// Print string in normal and Uppercase

}
}


*/OUTPUT:

rolando tomarocon

rolando TOMAROCON

*/

==================================================================

WORD REVERSE
/*Exercise 1
 **Name of Program:Word Reverse
 *Programmer name:Tomarocon, Rolando
 *Date:March 19,2009
 *Purpose:To enter a word that will reverse from the first index to last.
 */

 
public class wordReverse
{
  public static void main(String[] args)
  {
  // The normal sentence that is going to be reversed.
  String words = "Tomarocon, Rolando";
   
  // To reverse the string we can use the reverse() method in the 
  // StringBuffer class. The reverse() method returns a StringBuffer so
  // we need to call the toString() method to get a string object.
  String reverse = new StringBuffer(words).reverse().toString();
   
  // Print the normal string
  System.out.println("Normal : " + words);
  // Print the string in reversed order
  System.out.println("Reverse: " + reverse);
  }
}
 
/* OUTPUT:

Normal : Tomarocon, Rolando
Reverse: odnaloR ,nocoramoT
*/

------------------------------------------------------------------------------
COLOR CYCLE
/*Exercise 2
 *Name of Program:Color Cycle
 *Programmers name:Tomarocon, Rolando
 *Date:March 19,2009
 *Purpose:When you enter the button then the color of the background will change.depend to the color
 */

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class colorcycle extends JPanel implements ActionListener {
private static boolean USE_CROSS_PLATFORM_UI = false;
int buttonLabelIndex = 0;
String buttonLabels[] = { "green", "yellow", "pink", "Red", "gray","black","white","orange","blue"};
Color buttonColors[] = { Color.GREEN, Color.YELLOW, Color.PINK, Color.RED,Color.GRAY,Color.BLACK,Color.WHITE,Color.ORANGE,Color.BLUE,};

JButton button;
public colorcycle() {
super(new BorderLayout());

button = new JButton(buttonLabels[buttonLabelIndex]);
// for buttons since it is designed to match the OS X UI.
if(USE_CROSS_PLATFORM_UI) {
button.setBackground(buttonColors[buttonLabelIndex]);
} else {
button.setForeground(buttonColors[buttonLabelIndex]);
}
button.addActionListener(this);
this.add(button, BorderLayout.CENTER);
this.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
}

public void actionPerformed(ActionEvent e) {
buttonLabelIndex = ++buttonLabelIndex < frame =" new" contentpane =" new">

No comments:

Post a Comment