SlideShare une entreprise Scribd logo
1  sur  2
Télécharger pour lire hors ligne
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
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

Contenu connexe

Plus de Chaitanya Rajkumar Limmala (16)

Java Week9(B) Notepad
Java Week9(B)   NotepadJava Week9(B)   Notepad
Java Week9(B) Notepad
 
Java Week6(B) Notepad
Java Week6(B)   NotepadJava Week6(B)   Notepad
Java Week6(B) Notepad
 
Java Week4(B) Notepad
Java Week4(B)   NotepadJava Week4(B)   Notepad
Java Week4(B) Notepad
 
Java Week8(A) Notepad
Java Week8(A)   NotepadJava Week8(A)   Notepad
Java Week8(A) Notepad
 
Java Week3(A) Notepad
Java Week3(A)   NotepadJava Week3(A)   Notepad
Java Week3(A) Notepad
 
Java Week10 Notepad
Java Week10   NotepadJava Week10   Notepad
Java Week10 Notepad
 
Java Week9(A) Notepad
Java Week9(A)   NotepadJava Week9(A)   Notepad
Java Week9(A) Notepad
 
Java Week7 Notepad
Java Week7   NotepadJava Week7   Notepad
Java Week7 Notepad
 
Java Week6(A) Notepad
Java Week6(A)   NotepadJava Week6(A)   Notepad
Java Week6(A) Notepad
 
Java Week4(A) Notepad
Java Week4(A)   NotepadJava Week4(A)   Notepad
Java Week4(A) Notepad
 
Java Week4(C) Notepad
Java Week4(C)   NotepadJava Week4(C)   Notepad
Java Week4(C) Notepad
 
Java Week1(B) Notepad
Java Week1(B)   NotepadJava Week1(B)   Notepad
Java Week1(B) Notepad
 
Java Week2(C) Notepad
Java Week2(C)   NotepadJava Week2(C)   Notepad
Java Week2(C) Notepad
 
Java Week2(B) Notepad
Java Week2(B)   NotepadJava Week2(B)   Notepad
Java Week2(B) Notepad
 
Java Week1(A) Notepad
Java Week1(A)   NotepadJava Week1(A)   Notepad
Java Week1(A) Notepad
 
Java Week2(A) Notepad
Java Week2(A)   NotepadJava Week2(A)   Notepad
Java Week2(A) Notepad
 

Dernier

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 

Dernier (20)

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

Java Week12(B) Notepad

  • 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