Wednesday, October 18, 2023

Python Programming - Lab- Core Lab 5 - bharathiar University - Program 1 - Write a python program that displays the following information: Your name, Full address Mobile number, College name, Course subjects

 Python Programming - Lab

Core Lab 5  

Bharathiar University 

Program 1 - Write a python program that displays the following information: Your name, Full address Mobile  number, College name, Course subjects


Source Code

Here's a simple Python program that takes input for full name, address, mobile number, college name, and course subject, and then displays the entered information. 

Below is a Python program that prompts the user for their full name, address, mobile number, college name, and course subject. Then, it displays this information back to the user. Let's go through the code step by step. 

# Taking user input for personal information
full_name = input("Enter your full name: ")
address = input("Enter your address: ")
mobile_number = input("Enter your mobile number: ")
college_name = input("Enter your college name: ")
course_subject = input("Enter your course subject: ")


# Displaying the entered information
print("\nPersonal Information:")
print("Full Name:", full_name)
print("Address:", address)
print("Mobile Number:", mobile_number)
print("College Name:", college_name)
print("Course Subject:", course_subject)



Explanation of the steps:

User Input: The input() function is used to take input from the user.

The program prompts the user to enter their full name, address, mobile number, college name, and course subject.

The entered values are stored in respective variables (full_name, address, mobile_number, college_name, course_subject).

Display Information: The collected information is displayed back to the user using the print() function.

Each piece of information is printed along with its corresponding label.

When you run this program, it will ask you for the mentioned details one by one.

After you provide the input, it will display the entered information back to you.

Remember, you can run this Python code in any Python environment,

such as IDLE, Python shell, or a code editor like Visual Studio Code or PyCharm.


OUTPUT:
Enter your full name: Ram
Enter your address: 127, Ambedkar street, coimbatore
Enter your mobile number: 1234567890
Enter your college name: psg college of arts and science
Enter your course subject: python programming,data warehousing and data mining, deep learning

Personal Information:
Full Name: Ram
Address: 127, Ambedkar street, coimbatore
Mobile Number: 1234567890
College Name: psg college of arts and science
Course Subject: python programming, data warehousing and data mining, deep learning

Wednesday, October 11, 2023

BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University -Program -9- Write a Java Program to create Menu Bars and pull down menus

 

Bharathiar University

Programming Java Lab
Java Program 9
Write a Java Program to create Menu Bars and pull down menus




Source Code

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;

public class UserMenu { 
private static String text=""; 
private static JTextArea content;
    public static void main(String[] args) {
        JFrame frame = new JFrame("Menu Program");
   frame.setSize(500, 500);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        content=new JTextArea(50,50);
        content.setFont(new Font("Serif",Font.PLAIN,20));
        JMenuBar menuBar = new JMenuBar();
        JMenu fileMenu = new JMenu("File");
        JMenuItem newItem = new JMenuItem("New");
        JMenuItem openItem = new JMenuItem("Open");
        JMenuItem saveItem = new JMenuItem("Save");
        JMenuItem exitItem = new JMenuItem("Exit");

        fileMenu.add(newItem);
        fileMenu.add(openItem);
        fileMenu.add(saveItem);
        fileMenu.addSeparator();
        fileMenu.add(exitItem);

      JMenu editMenu = new JMenu("Edit");
       JMenuItem cutItem = new JMenuItem("Cut");
      JMenuItem copyItem = new JMenuItem("Copy");
      JMenuItem pasteItem = new JMenuItem("Paste");
      JMenuItem selectallItem = new JMenuItem("Select All");

        editMenu.add(cutItem);
        editMenu.add(copyItem);
        editMenu.add(pasteItem);
        editMenu.add(selectallItem);

        JMenu helpMenu = new JMenu("Help");
        JMenuItem aboutItem = new JMenuItem("About");
        helpMenu.add(aboutItem);

        menuBar.add(fileMenu);
        menuBar.add(editMenu);
        menuBar.add(helpMenu);

frame.setJMenuBar(menuBar);
frame.add(new JScrollPane(content));
frame.setVisible(true);

newItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
        content.setText("");
            }
        });

exitItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });



 cutItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
  text=(String)content.getSelectedText();
     content.replaceSelection("");

            }
        });

 copyItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
          text=(String)content.getSelectedText();

            }
        });

 pasteItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
        int pos=content.getCaretPosition();
        content.insert(text,pos);
            }
        });

 selectallItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
        content.selectAll();
            }
        });
        aboutItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(frame, "Menu Bar and Pull DownMenu Program");
            }
        });
    }
}

OUTPUT:






















Tuesday, October 10, 2023

BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University - Practical Program 11- Write a Java Program to draw a circle, square, ellipse and rectangle at the mouse click positions

 

Bharathiar University

Programming Java Lab
Java Program 11
Write a Java Program to draw a circle, square, ellipse and rectangle at the mouse click positions




Source Code

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MouseDraw extends JFrame {
    private Point clickPoint;
    private String selectedShape;

    public MouseDraw() {
        setTitle("MouseDrawer");
        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new FlowLayout());           

        addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                clickPoint = e.getPoint();
                repaint();  //calls paint method
            }
        });

        String[] shapes = {"Circle", "Square", "Ellipse", "Rectangle"};
        

        JComboBox<String> shapeCB = new JComboBox<String>(shapes);
        shapeCB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e){
            selectedShape = (String) shapeCB.getSelectedItem();
           repaint();
}
        });


      
        add(new JLabel("Select Shape: "));
        add(shapeCB);

        
    }

    public void paint(Graphics g) {
       super.paint(g);
        if (clickPoint != null) {
            int size = 50;
            if (selectedShape.equals("Circle")) {
                g.drawOval(clickPoint.x - size / 2, clickPoint.y - size / 2, size, size);
            } else if (selectedShape.equals("Square")) {
                g.drawRect(clickPoint.x - size / 2, clickPoint.y - size / 2, size, size);
            } else if (selectedShape.equals("Ellipse")) {
                g.drawOval(clickPoint.x - size, clickPoint.y - size / 2, size * 2, size);
            } else if (selectedShape.equals("Rectangle")) {
                g.drawRect(clickPoint.x - size, clickPoint.y - size / 2, size * 2, size);
            }
        }

    }

    public static void main(String[] args) {

            MouseDraw shapes = new MouseDraw();
            shapes.setVisible(true);
    }
}

OUTPUT:








Wednesday, October 4, 2023

Button click event using Java Swing


Button click event using Java Swing





Write a Java program to create a frame with label and button. When a button clicked some text to be printed in label. 


Output





Source code
;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ButtonClick extends JFrame {

    public ButtonClick() {
        setTitle("Print Some Text");
        setSize(500, 500);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new FlowLayout());           

        JLabel label=new JLabel("");
        JButton click=new JButton("Click Here");

       click.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e){
        label.setText("Hello everyone! Welcome");
}
        });


        add(label);
        add(click);

    }

    public static void main(String[] args) {

            ButtonClick ck  = new ButtonClick();
            ck.setVisible(true);
    }
}

    


Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...