Search This Blog

Thursday 17 August 2023

15. Java Program to demonstrate MouseWheelMoved Event.

// 15. Java Program to demonstrate MouseWheelMoved event.

import java.awt.Color;
import java.awt.Container;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.JFrame;
import java.awt.*;
 
public class WheelEx2 extends JFrame
{
       public WheelEx2()
    {
        final Container cPane = getContentPane();
        MouseWheelListener mouseWheelListener = new MouseWheelListener()
        {
            Label lb=new Label();
            public void mouseWheelMoved(MouseWheelEvent event)
            {
                lb.setBounds(20,50,100,20);
                lb.setFont(new Font("Verdana", Font.BOLD, 18));
                add(lb);
                int direction=event.getWheelRotation();
                if(direction<0)
                    lb.setText("UP");
                else
                    lb.setText("Down");
            }
               
        };
 
        cPane.addMouseWheelListener(mouseWheelListener);
        cPane.setBackground(Color.GRAY);
        cPane.setForeground(Color.RED);
    }
    public static void main(String args[])
    {
 
        JFrame jFrame = new WheelEx2();
 
        jFrame.setSize(600, 400);
 
        jFrame.setVisible(true);
    }
}

Thursday 16 February 2023

B13.(New) PHP Program to read data from MySQL table and calculate attendance percentage & Attendance Shortage.

 <!-- 13. PHP Program to read data from MySQL table and calculate attendance percentage & Attendance Shortage. -->

<!-- Run this query from MySQL [insert into prog13 values('BC180123','XYZ','WP',40,36,0);]-->

<html>

<head>

<title>Read data and update mysql table using php </title>

</head>

<body bgcolor=gray text=yellow>

<?php

// Establish Connection with Server

$connection = mysql_connect("localhost", "root", "");

// Selecting Database

$db = mysql_select_db("test", $connection);

//MySQL Query to read data

$query = mysql_query("select * from prog13", $connection);

echo "<h3>Student Attendance Details</h3>";

echo "<table border=3 cellspacing=5>";

echo"<tr><th>RegNo</th><th>StudentName</th><th>Subject</th><th>ClassesHeld</th><th>ClassesAttended</th><th>AttendancePercentage</th><th>AttendanceShortage</th></tr>";

while ($row = mysql_fetch_array($query))

{

    echo "<tr><td>".$row['RegNo']."</td>";

    echo "<td>".$row['StudentName']."</td>";

    echo "<td>".$row['Subject']."</td>";

    echo "<td>".$row['ClassesHeld']."</td>";

    echo "<td>".$row['ClassesAttended']."</td>";

    echo "<td>".$row['AttendancePercentage']."</td>";

    $reg=$row['RegNo'];

    $CH=$row['ClassesHeld'];

    $CA=$row['ClassesAttended'];

    $per=($CA/$CH)*100;

    if($per<75)$status='YES';

    else $status='NO';

    echo "<td>".$status."</td></tr>";

   

    //Query for updation with calculated percentage.

         $query1 = mysql_query("update prog13 set AttendancePercentage='".$per."'where RegNo='".$reg."';",$connection);

    //Query to reset AttendancePercentage to zero.

         //$query1 = mysql_query("update prog13 set AttendancePercentage=0 where RegNo='".$reg."';",$connection);

}

echo "<table border=3>";

echo "<br><b>MySQL table updated successfully.</b>";

mysql_close($connection); // Closing Connection with Server

?>

</body>

</html>

Sunday 21 August 2022

B8. NEP Java Program to create Menu Bar and Pull-Down Menus.

// ProgB8. NEP Java Program to create Menu Bar and Pull-Down Menus.

 

import java.awt.*; 

class ProgB8 

{ 

    ProgB8()

    { 

        Frame f= new Frame("Menu Bar and Pull Down Menus"); 

        MenuBar mb=new MenuBar(); 

        Menu menu=new Menu("MainMenu"); 

        Menu submenu=new Menu("SubMenu"); 

        MenuItem i1=new MenuItem("Item1"); 

        MenuItem i2=new MenuItem("Item2"); 

        MenuItem i3=new MenuItem("Item3"); 

        MenuItem i4=new MenuItem("Item4"); 

        MenuItem i5=new MenuItem("Item5"); 

        menu.add(i1); 

        menu.add(i2); 

        menu.add(i3); 

        submenu.add(i4); 

        submenu.add(i5); 

        menu.add(submenu); 

        mb.add(menu); 

        f.setMenuBar(mb); 

        f.setSize(500,500); 

        f.setLayout(null); 

        f.setVisible(true);

        f.setBackground(Color.blue);

    } 

    public static void main(String args[]) 

    { 

              new ProgB8(); 

    } 

}

B7. NEP Java program to demonstrate various mouse handling events using suitable example.

// ProgB7. NEP Java program to demonstrate various mouse handling events using suitable example.

 

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

/*

<applet code="ProgB7" height="300" width="500">

</applet>

*/

public class ProgB7 extends Applet implements MouseListener

{

    Font f1;

    String msg="Demonstration of Mouse Events";

    public void init()

    {

        f1 = new Font("Georgia",Font.BOLD,22);

        addMouseListener(this);

    }

    public void mouseClicked(MouseEvent me)

    {

        msg = "Mouse Clicked";

        repaint();

    }

    public void mousePressed(MouseEvent me)

    {

        msg = "Mouse Pressed";

        repaint();

    }

    public void mouseReleased(MouseEvent me)

    {

        msg = "Mouse Released";

        repaint();

    }

    public void mouseEntered(MouseEvent me)

    {

        msg = "Mouse Entered";

        repaint();

    }

    public void mouseExited(MouseEvent me)

    {

        msg = "Mouse Exited";

        repaint();

    }

    public void paint(Graphics g)

    {

        g.setColor(Color.blue);

        g.setFont(f1);

        g.drawString(msg,20,20);

    }

}

B6. NEP Java Program to create a window when we press M or m the window displays Good Morning, A or a the window displays Good After Noon

/* B6. NEP Java Program to create a window when we press M or m the window displays Good Morning, A or a the window displays Good After Noon E or e the window displays Good Evening, N or n the window displays Good Night */

 

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

/*<applet code="ProgB6" width=500 height=500> </applet>*/

public class ProgB6 extends Applet implements KeyListener

{

        String msg="Press M or A or E or N";

        int X=10,Y=20;

        Font f1;

        public void init()

        {

        f1= new Font("Georgia",Font.BOLD, 22);

                  addKeyListener(this);

        }

        public void keyPressed(KeyEvent ke)

        {

                  int key=ke.getKeyCode();

                  switch(key)

                  {

 

             case KeyEvent.VK_M: msg="Good Morning!";

                            break;

             case KeyEvent.VK_A:     msg="Good Afternoon!";

                            break;

             case KeyEvent.VK_E:     msg="Good Evening!";

                            break;

             case KeyEvent.VK_N:     msg="Good Night!";

                            break;

                           

        }

        repaint();

        }

        public void keyReleased(KeyEvent ke)

        {

                //showStatus("Key UP");

        }

        public void keyTyped(KeyEvent ke)

        {

               repaint();

        }

        public void paint(Graphics g)

        {

        g.setFont(f1);

        g.setColor(Color.blue);

                  g.drawString(msg,X,Y);

        }

}

FREE Hit Counters