Your SlideShare is downloading. ×
Java Week12(B)   Notepad
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Java Week12(B) Notepad

337
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
337
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. JAVA WEEK12(B) /* Week 12 : b) Write a Java program that allows the user to draw lines, rectangles and ovals. */ import java.awt.*; import java.awt.event.*; import java.applet.*; /* < applet code=shape width=300 height=300> < /applet> */ public class LabPro19 extends Applet implements MouseListener,ActionListener,MouseMotionListener { Button lines,ovals,rect,free; int ch; int x,y,x2,y2,k; public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) { x=e.getX(); y=e.getY(); } public void mouseReleased(MouseEvent e) { x2=e.getX(); y2=e.getY(); repaint(); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseDragged(MouseEvent e) { } public void mouseMoved(MouseEvent e) {if(k==1){ x2=e.getX(); y2=e.getY(); repaint();} } public void init() { lines=new Button("line"); ovals=new Button("oval"); rect =new Button("rect"); free=new Button("free hand"); add(lines);add(ovals);add(rect);add(free); lines.addActionListener(this); Page 1
  • 2. JAVA WEEK12(B) ovals.addActionListener(this); rect.addActionListener(this); free.addActionListener(this); addMouseListener(this); addMouseMotionListener(this); } public void actionPerformed(ActionEvent ki) { if(ki.getSource()==lines) { ch=1; k=0;} else if(ki.getSource()==ovals) { ch=2; k=0;} else if(ki.getSource()==rect) {ch=3; k=0;} else if(ki.getSource()==free) { ch=4; k=1;} } public void paint(Graphics g) { switch (ch) { case 1:g.drawLine(x,y,x2,y2); break; case 2:g.drawOval(x,y,(x2-x),(y2-y)); break; case 3:g.drawRect(x,y,(x2-x),(y2-y)); break; case 4:repaint(); break; } } /*public void update(Graphics g) { paint(g); }*/ } Page 2