12/23/2011
12/22/2011
Java applet (mouse events)
Java applet (mouse events) |
/*Java applet (mouse events)*/ import java.applet.*; import java.awt.*; import java.awt.event.*; public class MouseActions extends Applet implements MouseListener,MouseMotionListener { int mouseX=0,mouseY=0; //Coordinates String msg=""; public void init() { addMouseListener(this); addMouseMotionListener(this); setBackground(Color.blue); setForeground(Color.yellow); } public void mouseClicked(MouseEvent me) { //mouseX=30; //mouseY=30; mouseX=me.getX(); mouseY=me.getY(); msg="Mouse is clicked"; repaint(); } public void mouseEntered(MouseEvent me) { mouseX=30; mouseY=30; msg="Mouse is entered"; repaint(); } public void mouseExited(MouseEvent me) { mouseX=30; mouseY=30; msg="Mouse exited"; repaint(); } public void mousePressed(MouseEvent me) { //mouseX=me.getX(); //Mouse event //mouseY=me.getY(); mouseX=30; mouseY=30; msg="Mouse is pressed"; repaint(); } public void mouseReleased(MouseEvent me) { mouseX=me.getX(); //Mouse event mouseY=me.getY(); msg="Mouse is Released"; repaint(); } public void mouseDragged(MouseEvent me) { mouseX=me.getX(); //Mouse event mouseY=me.getY(); msg="*"; showStatus("Mouse is dragged at X: " + mouseX + " , Y: " + mouseY); repaint(); } public void mouseMoved(MouseEvent me) { showStatus("Mouse is moving at X: " + me.getX() + " , Y: " + me.getY()); } public void paint(Graphics g) { Font f = new Font("Arial",Font.BOLD,25); g.setFont(f); g.drawString(msg,mouseX,mouseY); } } //<applet code="MouseActions.class" height=500 width=500></applet>
Java applet (marquee text)
/* Java applet (marquee text) */ import java.applet.*; import java.awt.*; import java.awt.event.*; public class MovingBanner extends Applet implements Runnable { public String str=" Moving Banner "; Thread t=null; boolean stopflag; public void init() { setBackground(Color.cyan); setForeground(Color.blue); } public void start() { // str=getParameter("msg"); // if(str==null) // str=" Message not found "; // str=" " +str; t= new Thread(this); stopflag=false; t.start(); } public void stop() { stopflag=true; t=null; } public void run() { char ch; for(;;) { try{ repaint(); Thread.sleep(150); ch=str.charAt(0); str=str.substring(1,str.length()); str+=ch; if(stopflag) break; }//try catch(InterruptedException e){} }//for loop } public void paint(Graphics g) { Font f = new Font("Arial",Font.BOLD,25); g.setFont(f); g.drawString(str,50,30); } } //<applet code="MovingBanner.class" height=500 width=500></applet>
8/01/2011
C# Star Pattern (9)
C# Star Pattern (9) |
/* C# program to print the following pattern * * * * * * * * * * * * * * * * */ namespace Patterns { class Program { static void Main(string[] args) { int i, j; for (i = 1; i <= 5; i++) { for (j = 5; j > i; j--) { Console.Write(" "); } Console.Write("*"); for (j = 1; j < (i - 1) * 2; j++) { Console.Write(" "); } if (i == 1) Console.WriteLine(); else Console.WriteLine("*"); } for (i = 4; i >= 1; i--) { for (j = 5; j > i; j--) { Console.Write(" "); } Console.Write("*"); for (j = 1; j < (i - 1) * 2; j++) { Console.Write(" "); } if (i == 1) Console.WriteLine(); else Console.WriteLine("*"); } } } }
C# Star Pattern (8)
C# Star Pattern (8) |
/* C# program to print the following pattern * *** ***** ******* ********* ******* ***** *** * */ namespace Patterns { class Program { static void Main(string[] args) { int i, j, k; for (i = 1; i <= 5; i++) { for (j = i; j < 5; j++) { Console.Write(" "); } for (k = 1; k < (i * 2); k++) { Console.Write("*"); } Console.WriteLine(); } for (i = 4; i >= 1; i--) { for (j = 5; j > i; j--) { Console.Write(" "); } for (k = 1; k < (i * 2); k++) { Console.Write("*"); } Console.WriteLine(); } } } }
C# Star Pattern (7)
C# Star Pattern (7) |
/* C# program to print the following pattern ********** **** **** *** *** ** ** * * ** ** *** *** **** **** ********** */ namespace Patterns { class Program { static void Main(string[] args) { int i, j, k; for (i = 1; i <= 5; i++) { for (j = 1; j <= 6 - i; j++) { Console.Write("*"); } for (k = 1; k < i; k++) { Console.Write(" "); } for (j = 1; j <= 6 - i; j++) { Console.Write("*"); } Console.Write("\n"); } for (i = 2; i <= 5; i++) { for (j = 1; j <= i; j++) { Console.Write("*"); } for (k = 1; k <= 5 - i; k++) { Console.Write(" "); } for (j = 1; j <= i; j++) { Console.Write("*"); } Console.WriteLine(); } } } }
C# Star Pattern (6)
C# Star Pattern (6) |
/* C# program to print the following pattern ********* ******* ***** *** * */ namespace Patterns { class Program { static void Main(string[] args) { int i, j, k; for (i = 5; i >= 1; i--) { for (j = 5; j > i; j--) { Console.Write(" "); } for (k = 1; k < (i * 2); k++) { Console.Write("*"); } Console.WriteLine(); } } } }
C# Star Pattern (5)
C# Star Pattern (5) |
/* C# program to print the following pattern * *** ***** ******* ********* */ namespace Patterns { class Program { static void Main(string[] args) { int i, j, k; for (i = 1; i <= 5; i++) { for (j = i; j < 5; j++) { Console.Write(" "); } for (k = 1; k < (i * 2); k++) { Console.Write("*"); } Console.WriteLine(); } } } }
C# Star Pattern (3)
C# Star Pattern (3) |
/* C# program to print the following pattern ***** **** *** ** * */ namespace Patterns { class Program { static void Main(string[] args) { int i, j, k; for (i = 5; i >= 1; i--) { for (j = 5; j > i; j--) { Console.Write(" "); } for (k = 1; k <= i; k++) { Console.Write("*"); } Console.WriteLine(); } } } }
C# Star Pattern (1)
C# Star Pattern (1) |
/* C# program to print the following pattern * ** *** **** ***** */ namespace Patterns { class Program { static void Main(string[] args) { int i, j, k; for (i = 5; i >= 1; i--) { for (j = 1; j < i; j++) { Console.Write(" "); } for (k = 5; k >= i; k--) { Console.Write("*"); } Console.WriteLine(); } } } }