46. An example for free hand drawing –

import java.awt.*; import java.lang.Math; import java.awt.event.*; import java.awt.Graphics; import java.applet.Applet; public class Draw extends Applet implements ActionListener,MouseListener,MouseMotionListener {                 Button bDraw,bLine,bOval,bRect,bRounded;                 Point dot[]=new Point[1000];                 Point start,end;                 int dots=0;                 boolean mouseUp=false;                 boolean draw=false;                 boolean line=false;                 boolean oval=false;                 boolean rectangle=false;                 boolean rounded=false;                 public void init()                 { … Continue reading 46. An example for free hand drawing –

Advertisements

45. An example to draw an image. We just need to press the mouse at one point and release it at another. Resize an image –

import java.awt.*; import java.lang.Math; import java.awt.event.*; import java.applet.Applet; public class Resize extends Applet implements MouseListener {                 Image image;                 boolean mouseUp=false;                 Point start,end;                 public void init()                 {                                 image=getImage(getDocumentBase(),"Image.png");                                 addMouseListener(this);                 }                 public void mousePressed(MouseEvent e)                 {                                 mouseUp=false;                                 start=new Point(e.getX(),e.getY());                 }                 public void mouseReleased(MouseEvent … Continue reading 45. An example to draw an image. We just need to press the mouse at one point and release it at another. Resize an image –

44. An example of displaying an image –

import java.awt.*; import java.applet.*; public class Images extends Applet {                 Image image;                 public void init()                 {                                 image=getImage(getDocumentBase(),"Image.png");                 }                 public void paint(Graphics g)                 {                                 g.drawImage(image,10,10,this);                 } }   <HTML>                 <APPLET                                 CODE=Images.class                                 width=320                                 height=320>                 </APPLET> </HTML>

43. An example to add menu in the menu bar, add menu item in the menu option and handled these menus options.

import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class Menu2 extends Applet implements ActionListener {                 Button b1;                 frame menuWindow;                 public void init()                 {                                 b1=new Button("Display the menu window");                                 add(b1);                                 b1.addActionListener(this);                                 menuWindow=new frame("Menus");                                 menuWindow.setSize(200,200);                 }                 public void actionPerformed(ActionEvent event)                 {                                 if(event.getSource()==b1)                                 {                                                 … Continue reading 43. An example to add menu in the menu bar, add menu item in the menu option and handled these menus options.

42. an example of creating menu inside the main window –

import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class menu extends Applet implements ActionListener {                 Button b1;                 frame menuWindow;                 public void init()                 {                                 b1=new Button("Display the menu window");                                 add(b1);                                 b1.addActionListener(this);                                 menuWindow=new frame("Menus");                                 menuWindow.setSize(200,200);                 }                 public void actionPerformed(ActionEvent event)                 {                                 if(event.getSource()==b1)                                 {                                                 … Continue reading 42. an example of creating menu inside the main window –

41. an example in which we handle mouse event in the frame window adopted over the previous window by the implementing the methods in the MouseListener interface and display what the mouse is doing with the message in the label in that window.

import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Frames extends Applet implements ActionListener {                 Button b1,b2;                 labelFrame window;                 public void init()                 {                                 b1=new Button("Display the window");                                 add(b1);                                 b1.addActionListener(this);                                 b2=new Button("Hide the window");                                 add(b2);                                 b2.addActionListener(this);                                 window=new labelFrame("Java window");                                 window.setSize(400,300);                 }                 public void … Continue reading 41. an example in which we handle mouse event in the frame window adopted over the previous window by the implementing the methods in the MouseListener interface and display what the mouse is doing with the message in the label in that window.

40. An example of a java program for font class –

import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Fonts extends Applet implements ActionListener,KeyListener {                 String text="";                 Button boldbutton,italicbutton,largebutton;                 boolean bold=false;                 boolean italic=false;                 boolean large=false;                 public void init()                 {                                 boldbutton=new Button("Bold Font");                                 italicbutton=new Button("Italic Font");                                 largebutton=new Button("Large Font");                                 boldbutton.addActionListener(this);                                 italicbutton.addActionListener(this);                                 largebutton.addActionListener(this);                                 add(boldbutton); … Continue reading 40. An example of a java program for font class –

39. An example for creating window –

import java.awt.Color; import java.awt.Component; import java.awt.Frame; import java.awt.Graphics; import java.awt.image.VolatileImage; public class Windows extends Component {                 public VolatileImage buffer=null;                 void createBackBuffer()                 {                                 if(buffer!=null)                                 {                                                 buffer.flush();                                                 buffer=null;                                 }                                 buffer=createVolatileImage(getWidth(),getHeight());                 }                 public void paint(Graphics g)                 {                                 if(buffer==null)                                 {                                                 createBackBuffer();                                 }                                 … Continue reading 39. An example for creating window –

38. An example of applet with three button and text button with the scroll bar –

import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class MButton extends Applet implements FocusListener,MouseWheelListener {                 TextArea text1;                 Button button1,button2,button3;                 public void init()                 {                                 text1=new TextArea("",8,18);                                 add(text1);                                 button1=new Button("Press Tab1!");                                 button2=new Button("Press Tab2!");                                 button3=new Button("Press Tab3!");                                 add(button1);                                 add(button2);                                 add(button3);                                 button1.addFocusListener(this);                                 button2.addFocusListener(this);                                 button3.addFocusListener(this); … Continue reading 38. An example of applet with three button and text button with the scroll bar –

37. An example of applet for input and output text box –

import java.awt.*; import java.applet.*; public class UserIn extends Applet {                 TextField text1,text2;                 public void init()                 {                                 text1=new TextField(8);                                 text2=new TextField(8);                                 add (text1);                                 add (text2);                                 text1.setText("0");                                 text2.setText("0");                 }                 public void paint(Graphics g)                 {                                 int x=0,y=0,z=0;                                 String s1,s2,s;                                 g.drawString("Input A Number In … Continue reading 37. An example of applet for input and output text box –