પોસ્ટ્સ

2018 માંથી પોસ્ટ્સ બતાવી રહ્યું છે

Write an applet that uses the mouse listener, which overrides only two methods which are mousePressed and mouseReleased

છબી
Experiment : 12 આપણે આ practical માં mouse event નો ઉપયોગ કરવા નો છે. Mouse event માં પણ mouse press અને mouse release. Code = Exp12.java import java.awt.*; import java.awt.event.*; public class Exp12 extends Frame implements MouseListener {    TextField t1,t2;    Exp12()    {        setVisible(true);        setSize(500,500);        setLayout(new FlowLayout());        t1=new TextField(20);        t2=new TextField(20);        add(t1);        add(t2);        addMouseListener(this);    }    public void mouseReleased(MouseEvent e)    {        System.out.println("Mouse is released");        t1.setText("Mouse is released");    }    public void mousePressed(MouseEvent e)    {        System.out.println("Mouse is pressed");        t1.setText("Mouse is pressed");    }    public void mouseEntered(MouseEvent e)    {      t2.setText("Mouse is In");    }    public void mouseExited(MouseEvent e)    {      t2.setText("Mouse is Exite");

Write an applet that display the position of the mouse at the upper left corner of the applet when it is dragged or moved. draw a 10x10 pixel rectangle filed with black at the current mouse position

છબી
Experiment : 10 આ practical માં આપણે applet માં mouse ની movement હલન ચલન કે drag ના આધાર પર જ્યાં mouse નું pointer હોય ત્યાં 10*10 નુ box થવું જોઈએ. Code = Exp10.java import java.applet.Applet; import java.awt.event.*; import java.awt.*; /*<applet code="Exp10.class" height=500 width=500> </applet>*/ public class Exp10 extends Applet implements MouseMotionListener {     int x,y;     public void init()     {         addMouseMotionListener(this);     }     public void mouseDragged(MouseEvent e)     {         x=e.getX();         y=e.getY();         repaint();             }     public void mouseMoved(MouseEvent e)     {         x=e.getX();         y=e.getY();         repaint();     }     public void paint(Graphics g)     {         g.fillRect(x,y,10,10);     } } Output : માઉસ ડ્રેગ (Mouse Dragged) અને માઉસ મૂવ્ડ (Mouse Moved) ઇવેન્ટ બધા માઉસના સ્થાન બદલાવ સંબંધિત છે, પરંતુ તેમમાં ફરક છે કે માઉસ ની ક્યારેય એક છક્કો માંથી પાસે જવું શું છે. 1. માઉસ ડ્રેગ (Mo

Develop an applet to display the message "Happy New Year" within a text field

છબી
Experiment : 6 આપણે આમાં એક applet બનાવવાનું છે જે "happy new year" નો મેસેજ print કરતું હોય એને તે button નો ઉપયોગ થી થાય. yearbtn.java import java.awt.*; import java.awt.event.*; public class yearbtn extends Frame implements ActionListener{ Button b1; Label l1;     yearbtn()     {         b1=new Button("year");         l1=new Label(" ");         setLayout(new FlowLayout());         setVisible(true);         setSize(300,500);         add(b1);         add(l1);         b1.addActionListener(this);     }     public static void main(String args[])     {         yearbtn s=new yearbtn();             }      public void actionPerformed(ActionEvent e)     {         if(e.getSource()==b1)         {             l1.setText("happy new year");         } } } Output :     આ ઉદાહરણમાં, જ્યારે તમે લેબલ પર ક્લિક કરો છો, ત્યારે લેબલનો ટેક્સ્ટ લેબલ "Label clicked!" પર બદલાવામાં આવશે. તો એપ્લિકેશનમાં બટનનો છે પરંતુ પ્રતિક

Built an applet that displays a horizontal rectangle in its center. Let the rectangle fill with color from left to right.

છબી
Experiment : 3 આપણે આ practical માં applet માં progress bar બનાવવાની છે.એના માટે વચ્ચે એક આળું લંબચોરસ ની અંદર કલર વાળા લંબચોરસ ને ભરી ને કરી સકાય. Code = ProgressD.java import java.applet.Applet; import java.awt.*; /*<applet code="ProgressD.class" width=320 height=150> </applet> */ public class ProgressD extends Applet{     public void paint(Graphics G){         G.drawRect(48,50,218,50);                  for(int x=50;x<=260;x=x+12){             try{             Thread.sleep(500);             G.fillRect(x,52,10,46);             }catch(Exception e){             }         }     } } Output :     ચાલો તો એક પછી એક કરી લાઈન by લાઈન કોડ ને સમજયે  import java.applet.Applet; import java.awt.*; આ લાઈન માં import નો ઉપયોગ લાઇબ્રેરી ને add કરવા ઊપયોગ થયો છે, java applet અને java awt librery ને import કરવી છે એટલે તેના રહેલા function method નો ઉપયોગ આપણે કોડ માં કરી સકાય. /*<applet code="ProgressD.class" width=500 height=300> </applet&g

Draw seven red circles in a vertical column in the center of the applet

છબી
Experiment : 2 આ practical માં આપણે સાત લાલ ગોળ ઊભી (vertical) માં applet ના વચ્ચે દોરવાના છે. Code = redcircle.java import java.applet.Applet; import java.awt.*; /*<applet code="redcircle.class" width=700 height=700> </applet>*/ public class redcircle extends Applet {    public void paint(Graphics g)    {        g.drawString("Hello",338,355);        int y=0;        g.setColor(Color.RED);        for(int i=0;i<7;i++)        {            g.fillOval(300,y,100,100);            y=y+100;        }    } } Output આ task કરવા માટે આપણે આને પેહલા એક applet બનાવ્યે અને ત્યાર બાદ loop ની મદદ થી 10 ગોળ બનાવી. import java.applet.Applet; import java.awt.*; આપણે અહી import (keyword) નો ઉપયોગ કરી ને જરૂરી library ને add કરી છે. આમાં applet librery દ્વારા applet ના function methods ઉપયોગ કરી સકાસે. એને Awt (Abstract windows Toolkit) windows user interface tools ઊપયોગ કરી સકાઈ. /*<applet code="redcircle.class" width=700 height=700></applet>

Write an applet that draws a circle. The dimension of the applet should be 500 x 300 pixels. The circle should be centered in the applet and have a radius of 100 pixels. Display your name centered in a circle.( using drawOval() method ).

છબી
Experiment : 1 આપણે applet નો ઉપયોગ કરી ને ગોળ બનાવી ને તેની અંદર લખવાનું છે. એના માટે drawOval() method નો ઉપયોગ કરવાનો છે.  circle.java import java.applet.Applet; import java.awt.*; /*<applet code="circle.class" width=500 height=300> </applet>*/ public class circle extends Applet {    public void paint(Graphics g)    {        g.drawOval(200,100,100,100);        g.drawString("Hi",238,150);    } } Output   અહી આપણે બે method નો ઉપયોગ કરશું .. એક તો drawOval (જેના દ્વારા ગોળ બનવશું) અને drawString (જેના દ્વારા text લખશુ )   ચાલો તો એક પછી એક કરી લાઈન by લાઈન કોડ ને સમજયે  import java.applet.Applet; import java.awt.*; આ લાઈન માં import નો ઉપયોગ લાઇબ્રેરી ને add કરવા ઊપયોગ થયો છે, java applet અને java awt librery ને import કરવી છે એટલે તેના રહેલા function method નો ઉપયોગ આપણે કોડ માં કરી સકાય. AWT(Abstract Window Toolkit) Applet એ એવી library છે જે java program web page ની અંદર સાથે embedded કોડ છે. એ client side work કરે છે .   java.awt માં pain