Posts

Showing posts from November 6, 2011

mouseevent in java

-program based on mouseevent in  java----- - import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="mouse" width=600 height=500> </applet> */ public class mouse extends Applet implements MouseListener,MouseMotionListener { int X=10,Y=50; String msg="MouseEvents"; public void init() { addMouseListener(this); addMouseMotionListener(this); setBackground(Color.yellow); setForeground(Color.red); } public void mouseEntered(MouseEvent m) { setBackground(Color.blue); showStatus("Mouse Entered"); repaint(); } public void mouseExited(MouseEvent m) { setBackground(Color.black); showStatus("Mouse Exited"); repaint(); } public void mousePressed(MouseEvent m) { X=20; Y=40; msg="GTBIT"; setBackground(Color.pink); repaint(); } public void mouseReleased(MouseEvent m) { X=20; Y=40; msg="Engineering"; se

paintbrush applet from jdk

Image
this applet was taken from java development kit to give a java developer an innovative idea.... an applet for paint brush: import java.awt.*; import java.applet.*; import java.util.Vector; public class DrawTest extends Applet {     public void init() { setLayout(new BorderLayout()); DrawPanel dp = new DrawPanel(); add("Center", dp); add("South",new DrawControls(dp));     }     public boolean handleEvent(Event e) { switch (e.id) {  case Event.WINDOW_DESTROY:    System.exit(0);    return true;  default:    return false; }     }     public static void main(String args[]) { Frame f = new Frame("DrawTest"); DrawTest drawTest = new DrawTest(); drawTest.init(); drawTest.start(); f.add("Center", drawTest); f.resize(300, 300); f.show();     } } class DrawPanel extends Panel {     public static final int LINES = 0;     public static final int POINTS = 1;     int   mode = LINES;     Vector

datagrampacket datagramsocket

Image
program based on client-server in java. server program save in one file: import java.net.*; class hi_server { public static DatagramSocket ds; public static byte buffer[]=new byte[1024]; public static void Myserver() throws Exception { int pos=0; while(true) { int c=System.in.read(); switch(c) { case -1: System.out.println("Server quits"); return; case '\r':break; case '\n':ds.send(new DatagramPacket(buffer,pos,InetAddress.getLocalHost(),777));           pos=0; break; default: buffer[pos++]=(byte) c; } } } public static void main(String args[]) throws Exception { System.out.println("Server ready..\n Please type here"); ds=new DatagramSocket(888); Myserver(); } } client program save in as different java file import java.net.*; class hi_client { public static DatagramSocket ds; public static byte buffer[]=new byte[1024]; public static v

notepad in java

Image
//notepad or text-editor in java with source code import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.util.*; public class notepad extends JFrame implements ActionListener { MenuBar mbar; Menu file,edit,format,font,font1,font2; MenuItem itm1,itm2,itm3,itm4; MenuItem itm5,itm6,itm7,itm8,itm9,itm10; MenuItem fnam1,fnam2,fnam3,fnam4; MenuItem fstyle1,fstyle2,fstyle3,fstyle4; MenuItem fsize1,fsize2,fsize3,fsize4; JPanel mainpanel; TextArea text; Font f; String months[]={ "Jan","Feb","Mar","Apr", "May","Jun","Jul","Aug", "Sep","Oct","Nov","Dec"}; GregorianCalendar gcalendar; String command=" "; String str=" "; String str1=" ",str2=" ",str3=" "; String str4=" "; String str6=" "; String str7=" ",str8=" ",s

url in java

To understand url-uniform resource locator operations in java just run this program ... import java.net.*; import java.io.*; class url { public static void main(String args[]) throws Exception {                URL p1=new URL("http://www.oracle.com:80/docs/path#up"); System.out.println("Protocol:"+p1.getProtocol()); System.out.println("Host :"+p1.getHost()); System.out.println("File Name :"+p1.getFile()); System.out.println("Port :"+p1.getPort()); System.out.println("Reference :"+p1.getRef()); } }