Home Discussion Discuss: Java - Event Listeners Example in Java Applet

  • plz give me output of this java listeners programsrj September 21, 2011 at 8:31 PM

    import java.awt.*; import java.awt.event.*; public class ls5 extends frame implements ActionListener { int cx=100,hx,hy; int i=1; boolean selected; MenuBar md; Menu sh; MenuItem rect,sqr,crcle; ls5(String s) { super(s); mb=new MenuBar(); setSize(300,300); setVisible(true); setLayout(new flowLyout(flowLayout(floeayout.LEFT))); ret=new MenuItem("RECTANGLE"); crcle=new MenuItem("CIRCLE"); sqr=new MenuItem("SQURE"); sh=new MenuItem("SELECT"); sh.add(rect); sh.add(sqr); sh.add(crcle); Mb.add(sh); setMenuBar(mb); rect.addActionListener(this); crcle.addACtionListner(this); sqr.addActionListner(this); addWindowListener(new windowAdaptor() { public class windowClosing(WindowEvent w) { System.exit(0); }; }); addKeyListener(new KeyAdaptor() { public void KeyPressed (KeyEvent ke) { if(ke.getKeyCode()==key.vk_DOWN) { cy+=10; repaint(); } if(ke.getKeyCode()==ke.vk_UP) { cx-=10; repaint(); } if(ke.getKeyCode()==ke.vk_LEFT) { cx-=10; repaint(); } if(ke.getKeyCode()==ke.vk_RIGHT) { cx+=10; repaint(); } } }); addMouseListener(new MouseAdaptor() { public void mousePressed(MouseEvent me) { int x=me.getx(); int y=me.gety(); if(x>c && (x<=(cx+80))&&(y>cy&&y<=(cy+60))) { selected=true; hx=x; hy=y; } else selected=false; } }); addMouseMotionListener(new MouseMotionAdaptor() { public class mouseDragged(MouseEvent me) { int x=me.getx(); int y=me.gety(); if(selected) { cx=cx+(x-hx); cy=cy+(y-hy); hx=x; hy=y; repaint(); } } }); } public void actionPreformed(ActionEvent e) { if(e.getSource()==rect) { c=1; setTittle("DragRectsngle"); repaint(); } if(e.getSource()==sqr) { i=2; setTittle("DragSquare"); repaint(); } if(e.gertSource()==crcle) { i=3; steTittle("Drag Cirle"); repaint(); } } public void paint() { if(i==1) { g.setColor(color.black); g.fillRect(cx,cy,80,60); } else if(i==2) { g.setcolor(color.black); g.fillRect(cx,cy,80,80); } else { g.setcolor(color.red); g.setOval(cx,cy,80,80); } } public static void main(String args[]) { ls5 apptt=new ls5("Drag Shape"); } }

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Java Beginners

Listeners - Java Beginners
://www.roseindia.net/java/example/java/swing/ Thanks 

Java Tips and Examples

This file defines an applet.
Java NotesExample - Generic Applet This file defines an applet. This template is a reasonable way to start an applet, where GenericPanel is a subclass of JPanel and it contains the code to build a GUI with the appropriate listeners 

Applet Questions

applet - Applet
: http://www.roseindia.net/java/example/java/applet/ Thanks... in Java Applet.",40,20); } } 2) Call this applet with html code...applet   i want a simple code of applet.give me a simple example 

Applet Questions

Applet - Applet
in details to visit.... http://www.roseindia.net/java/example/java/applet/index.shtml http://www.roseindia.net/java/example/java/swing/index.shtml..., Applet Applet is java program that can be embedded into HTML pages. Java applets 

Applet Questions

applet - Applet
information,visit the following link: http://www.roseindia.net/java/example/java/applet/ Thanks...*; import java.awt.*; public class CreateTextBox extends Applet implements 

Applet Questions

java - Applet
java  what is applet?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/example/java/applet/ Thanks 

Java Tips and Examples

Anonymous Listeners
Java NotesAnonymous Listeners   Using anonymous inner class listeners - a common idiom   In this example you will learn how to use anonymous inner class listeners.   We have also given the complete code example so 

Applet Questions

Applet query - Applet
link: http://www.roseindia.net/java/example/java/applet/ Thanks...Applet query  i want to knw d complete detail of why does applet... with their container.It runs under the control of a Java-capable browser.The java-capable browser 

Applet Questions

how to run applet - Applet
://www.roseindia.net/java/example/java/applet/ http://www.roseindia.net/java/example/java/applet/FirstApplet.shtml Hope that it will be helpful for you.Even... in applet program. this is executed successfully with appletviewer command > 

Applet Questions

methods in the applet - Applet
(Graphics g) { g.drawString(m,10,10); } } The init() method used in the java applet is simular to the contructor defined in a java application. The purpose...; public class applet1 extends Applet { String m; public void init 

Applet Questions

drawing shapes in applet - Applet
drawing shapes in applet  hi, i need a single applet prgm which draws cone,cube and square in circle.  Hi manju, This is cube example... java.applet.Applet; public class CubeExample extends Applet { Stroke 

Java Beginners

Applet
or restarted. For Example if the user wants to return to the Applet, in this situation...Applet  Explain the start() and stop() methods of applet life cycle.   Start and Start method of Applet Life Cycle Start () method 

Swing AWT

Applet
Applet  I have a java applet that has a button. On clicking the button it should disappear and another applet should appear. How to write this code???? Also in login applet after successful login it should display admin applet 

General

Applet
"Welcome in Passing parameter in java applet example." message. Here...; Introduction Applet is java program that can be embedded into HTML pages. Java applets... Disadvantages of Java Applet: Java plug-in is required to run applet Java 

Java Beginners

Applet
Applet  Draw the class hierarchy of an Applet class. Also explain how to set background and forground colors in java 

Applet Questions

java - Applet
://www.roseindia.net/java/example/java/swing/graphics2D/index.shtml Thanks 

Java Beginners

applet
applet  what is applet in java   An applet is a small program that can be sent along with a Web page to a user. Java applets can perform... the following link: Applet Tutorials 

Applet Questions

Creating an Applet
your concerned queries in this regards. http://www.roseindia.net/java/example/java/applet/firstapplet.shtml Thanks... an Applet using all Layout Manager, can anyone help me in this regard. I donā??t know 

Java Beginners

Applet
Applet  Write a Java applet that drwas a line between 2 points. The co-ordinates of 2 points should be passed as parametrs from html file. The color of the line should be red 

Java-Tutorials

Java Applet - Creating First Applet Example
Java Applet - Creating First Applet Example   ... the applet. An applet is a program written in java programming language... an applet program. Java source of applet is then compiled into java class file and we 

Java-Tutorials

Applet - Passing Parameter in Java Applet
;Welcome in Passing parameter in java applet example."> <... like Welcome in Passing parameter in java applet example. Alternatively you... Applet - Passing Parameter in Java Applet    

Applet Questions

Java Program - Applet
Java Program  A java program to move a text in applet from right to left.  Hi Friend, Please visit the following link: http://www.roseindia.net/java/example/java/applet/SampleBanner.shtml Thanks 

Applet Questions

unable to see the output of applet. - Applet
unable to see the output of applet.  Sir, I was going through the following tutorial http://www.roseindia.net/java/example/java/applet...://www.roseindia.net/java/example/java/applet/FirstApplet.html but the problem 

Java Beginners

applet code - Java Beginners
://www.roseindia.net/java/example/java/applet/ Hope that it will be helpful...applet code  hi friends.. i have to oen one applet, in that applet code should be apper what we have written for the applet... this is my 

Java Beginners

adding mouse listeners to drop target
adding mouse listeners to drop target  import java.awt.*; import... with adding mouse listeners to "table" which is drop target, to accept drop...; Here is a drag and drop application of Java Swing. import java.awt.*; import 

Applet Questions

applet images sleeping programme - Applet
/example/java/applet/ Thanks...applet images sleeping programme  Dear Sir,         I shall be much tankful to you, if u can kindly give me the programe for    In a Applet how 

Applet Questions

Swings - Applet
to call that class in applet. is it possible. or otherwise is there any way to deploy java class in browser. Give an example... Thanks in advance...  Hi... extends Applet{ CountCharacters c=new CountCharacters(); Label l1,l2,l; TextField 

Java Tips and Examples

Inner-class Listeners
Java NotesInner-class Listeners Named inner class Defining an inner class... class. In the example below, the myGreetingField can be referenced by the listener class. Because simple program listeners typically get or set 

Applet Questions

Applet program for drawing picture and graph - Applet
, Please visit the following links: http://www.roseindia.net/java/example/java/applet/ http://www.roseindia.net/tutorial/java/swing/createHumanFace.html Hope...Applet program for drawing picture and graph  Please send me 

Java Tips and Examples

Java - Applet Hello World
Java - Applet Hello World       This example introduces you with the Applet in Java... graphics on the web. This example creates a simple applet that displays Hello 

DMCA.com