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>

FREE Hit Counters