Skip to main content
Open navigation menu
Close suggestions
Search
Search
en
Change Language, English
Upload
Sign in
Sign in
0 ratings
0% found this document useful (0 votes)
9 views
18 pages
Java Exp.8,9,10,11
Java program for content sorting,creating analog clock using applet,create calculator using swings,crateing ms word using swings
Uploaded by
princetaak1234
AI-enhanced title
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save java exp.8,9,10,11 (1) For Later
Share
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
9 views
18 pages
Java Exp.8,9,10,11
Java program for content sorting,creating analog clock using applet,create calculator using swings,crateing ms word using swings
Uploaded by
princetaak1234
AI-enhanced title
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Go to previous items
Download
Save
Save java exp.8,9,10,11 (1) For Later
Share
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
Go to next items
Download
[Link]: suresh 56 Mahesh 89 Shyam 61 Vikas 92 Shloka 84 Nalini 62 Abhi 71 Bhavani 68 SOURCE CODE: // sorting the content of a given text file import [Link]. BufferedReader, import [Link]; import [Link] FileReader, import [Link]; import [Link].]OExceptior import [Link] ArrayList; import [Link]; import [Link]. Comparator, 1 Student Class class Student { String name; int marks; Public Student(String name, int marks) { [Link] = name; this. marks = marks; } } 1 nameCompare Class to compare the names class NameCompare implements Comparator { @Override public int compare(Student s1, Student s2) { retum [Link]([Link]); } } 1 marksCompare Class to compare the marks class MarksCompare implements Comparator
{ @Override public int compare(Student s1, Student s2) { return [Link] - [Link];7 } public class SortTextFile { public static void main(Stringl] args) { try{ 1! Creating BufferedReader object to read the input text file BufferedReader reader = new BufferedReader(new FileReader("input txt"); 11 Creating ArrayList to hold Student objects ArrayList
studentRecords = new ArrayList<>(); // Reading Student records one by one String currentLine = [Link](); while (currentLine != null) { Stringl} studentDetail = [Link](""); String name = studentDetail(0}; int marks = [Link](studentDetaill1)); 1/ Creating Student object for every student record and adding it to ArrayList [Link](new Student(name, marks)); currentLine = [Link](); 2 // Closing the reader [Link](); // Sorting ArrayList studentRecords based on marks [Link](studentRecords, new MarksCompare()); 11 Creating BufferedWriter object to write into output text file BufferedWriter writer = new ButferedWriter(new FileWriter(“[Link]")); J Mriting every studentRecords into output text file for (Student student : studentRecords) { [Link]([Link]); [Link](” " + student. marks); [Link](); } 11 Closing the writer [Link](); } catch (IOException e) { [Link](); } } }OUTPUT: [Link] : Vikas 92 Mahesh 89 Shloka 84 Shyam 81 Abhi 71 Bhavani 68 Nalini 62 Suresh 56SOURCE CODE: // to develop an analog clock using an applet . // Java program to illustrate // analog clock using Applets import [Link]. Applet import [Link].*; import [Link].*; public class analogClock extends Applet { @override public void init() { // Applet window size & color [Link](new Dimension(800, 400)); setBackground(new Color (50, 50, 50); new Taread() { @override public void run() { while (true) { repaint(); delayAnimation() ; } }.start(); } // Animating the applet private void delayAnimation() { try { // Animation delay is 1000 milliseconds Thread. sleep (1000) ; } catch (InterruptedException e) { [Link]() ; } } // Paint the applet @override public void paint (Graphics g) {// Get the system time Calendar time = [Link]() ; int hour = [Link] (Calendar .HOUR_OF_DAY) ; int minute = [Link] (Calendar .MINUTE) ; int second = time. get (Calendar SECOND) ; // 12 hour format if (hour > 12) { hour -= 12; } // Draw clock body center at (400, 200) [Link] ([Link]) ; g.£illoval (300, 100, 200, 200); // Labeling [Link] (Color .black) ; [Link]("12", 390, 120); g-drawString("9", 310, 200); [Link]("6", 400, 290); [Link]("3", 480, 200); // Declaring variables to be used double angle; int x, yi // Second hand's angle in Radian angle = [Link]((15 - second) * 6); // Position of the second hand // with length 100 unit x = (int) ([Link] (angle) * 100); y = (int) ([Link] (angle) * 100); // Red color second hand [Link] (Color. red) ; [Link](400, 200, 400 + x, 200 - y); // Minute hand's angle in Radian angle = Math. toRadians((15 - minute) * 6); // Position of the minute hand // with length 80 unit x = (int) ([Link] (angle) * 80); y = (int) ([Link](angle) * 80);// blue color Minute hand [Link] (Color .blue) ; [Link] (400, 200, 400 + x, 200 - y); // Hour hand's angle in Radian angle = [Link]((15 - (hour * 5)) * 6); // Position of the hour hand // with length 50 unit x = (int) ([Link] (angle) * 50); y = (int) ([Link] (angle) * 50); // Black color hour hand [Link] ([Link]) ; g-drawLine (400, 200, 400 + x, 200 - y); Here's the HTML code to embed the applet:
‘
OUTPUT: This will display a clock with moving hour, minute, and second hands to represent the current time. TleSOURCE CODE: // to develop a scientific calculator using swings. import [Link].*; import [Link].*; import [Link]."; class Calculator extends JFrame implements ActionListener { private static final long serialVersionUID = 1; // Adding serial version UID 1/ Declare components private JTextField displayField; private String operand1, operand2, operator, /{ Constructor Calculator() { operandi = operand2 = operator = ""; J Set up the frame sefTitle(*Calculator’); setSize(300, 400); setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new BorderLayout()); 11 Create and add display field displayField = new JTextField(16); [Link](false); add(displayField, BorderLayout. NORTH); // Create and add button panel JPanel buttonPanel = new JPanel(new GridLayout(s, 4)); addButtons(buttonPanel); add(buttonPanel, BorderLayout CENTER); } /{ Method to add buttons to the panel private void addButtons(JPanel panel) { String[] buttonLabels T "9", "4", hk for (String label : buttonLabels) { Button button = new JButton(label); [Link](this); [Link](button); } ) 1/ ActionListener implementation Public void actionPerformed(ActionEvent e) {String command = [Link](); switch (command) { case 'C’ clearDisplay(); break; case" calculateResult(); break; case "+" case" case case": setOperator(command); break; default: appendToDisplay(command); break; } } // Method to append a digit or decimal point to the display private void appendToDisplay(String input) { if ([Link]()) { operand! += input; [Link](operand1); }else { operand2 += input; [Link](operand2); } } 1 Method to set the operator private void setOperator(String op) { operator = op; [Link](operandt + operator); } // Method to calculate and display the result private void calculateResult() { if (loperand1 .isEmpty() && [Link]() && ![Link]()) { double result = 0; double num = [Link](operand1); double num2 = Double. parseDouble(operand2); switch (operator) { case "+": result = numt + num2; breal case"!result = numt - num2; break; case "*": result = num1 * num2; breal case": if (num2 != 0) ( result = numt /num2; jelse { [Link](this, "Error: Division by zero", "Error", JOptionPane.ERROR_MESSAGE); clearDisplay(); retum; } break; } [Link]([Link](result); operand! = [Link](result); operand2 = operatoi } } // Method to clear the display and reset operands and operator private void clearDisplay() { operand! = operand? = operator [Link]("); } /{ Main method Public static void main(String[] args) { ‘[Link](() -> { new Calculator().setVisible(true); ym } }OUTPUT: laa. oO x P+ oe | Ty T-]-]— —)SOURCE CODE: //Create an editor like MS-word using swings import [Link].*; import [Link]. DocumentEvent; import [Link]; import [Link]; // Add this import for UndoableEdit import [Link]." import [Link].*; import [Link]"; import [Link] ArrayList; import [Link]; // Add this import for PrinterException class Editor extends JFrame implements ActionListener, DocumentListener { private static final long serialVersionUID = private JTextArea textArea; private File currentFile; private boolean isTextModified; private ArrayList
undoBuffer; private ArrayList
redoButfer; Editor() ( 11 Create the fram sefTitle("Text Editor setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setSize(800, 600); setLocationRelativeTo(null); // Create a menu bar JMenuBar menuBar = new JMenuBar(); // Create File menu JMenu fileMenu = new JMenu("File"); JMenultem newMenultem = new JMenultem("New’); JMenultem openMenultem = new JMenultem("Open'); JMenultem saveMenultem = new JMenultem("Save"); JMenultem saveAsMenultem = new JMenultem("Save As"); JMenultem printMenultem = new JMenultem('Print’); JMenultem exitMenultem = new JMenultem("Exit"); /) Add action listeners to File menu items [Link] (this); ‘[Link](thi [Link](this); [Link](this); [Link] (this); [Link](this); 1/ Add File menu items[Link](newMenultem); [Link](openMenultem); [Link](saveMenultem); [Link](saveAsMenultem); [Link](); [Link](printMenultem); [Link](); [Link](exitMenultem); Create Edit menu JMenu editMenu = new JMenu("Edit"); JMenultem undoMenultem = new JMenultem("Undo’); JMenultem redoMenultem = new JMenultem("Redo") JMenultem cutMenultem = new JMenultem("Cut"); JMenultem copyMenultem = new JMenultem("Copy"); JMenultem pasteMenultem = new JMenultem("Paste"); 1] Add action listeners to Edit menu items [Link](this); [Link](this); [Link](this); [Link](this); [Link] Listener(this); 11 Add Edit menu items [Link](undoMenultem); [Link](redoMenultem); [Link](); [Link](cutMenultem); [Link](copyMenultem); [Link](pasteMenultem); 1] Add menus to menu bar [Link]{ileMenu); [Link](editMenu); 11 Set menu bar to frame setJMenuBar(menuBar); 1 Create text area textArea = new JTextArea(): [Link]().addDocumentListener (this); JSorollPane scrollPane = new JScrollPane(textArea); 1/ Add text area to frame add(scroliPane, BorderLayout. CENTER);currentFile = null; isTextModified = false; undoButfer = new ArrayList<>(); redoBuffer = new ArrayList<>(); 1] Add window listener for closing the application addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { closeEditor(); } ys 1/ Set frame visible setVisible(true); } Public void actionPerformed(ActionEvent e) { String command = [Link](); switch (command) { case "New: newFile(); break; case "Open openFile(); break; case "Save": saveFile(); break; case "Save As": saveFileAs(); break; case "Print printFile(); break; case "Undo": undoEdit(); break; case "Redo’ redoEdit(); break; case "Cut": [Link](); break; case "Copy": [Link](): break; case "Paste"textArea paste); break; case "Exit': closeEditor(); break; default: break; } } private void newFile() { if (isTextModified) { int choice = [Link](this, "Do you want to save changes to the current file?", "Save changes", JOptionPane.YES_NO_CANCEL_OPTION); if (choice == JOptionPane.YES_OPTION) { saveFile(); } else if (choice == JOptionPane.CANCEL_OPTION) { retum; } } [Link]("); currentFile = null; isTextModified = false; setTitle("Text Editor"); } private void openFile() { JFileChooser fileChooser = new JFileChooser(); int response = [Link](this); if (response == JFileChooser.APPROVE_OPTION) { File file = [Link](); try (ButferedReader reader = new ButferedReader(new FileReader(file))) StringBuilder text = new StringBuilder(); String line; while ((line = [Link]()) != null) { [Link](ine).append("\n"); } [Link]([Link]()); currentFile = file; TextModified = false; setTitle("Text Editor - " + [Link]()); } catch (IOException ex) { [Link](this, "Error opening file: "+ [Link](), "Error", JOptionPane.ERROR_MESSAGE); } } }private void saveFile() { if (currentFile == null) { saveFileAs(); }else { try (BufferedWriter writer = new BufferedWriter(new FileWriter(currentFile))) { [Link]([Link]()); isTextModified = false; }eatch (IOException ex) { [Link](this, "Error saving file: " + [Link](), "Error", JOptionPane.ERROR_MESSAGE); } } } private void saveFileAs() { JFileChooser fileChooser = new JFileChooser(); int response = [Link](this); if (response == JFileChooser. APPROVE_OPTION) { File file = [Link](); try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { [Link]([Link]()); currentFile = file; ‘extModified = false; setTitle("Text Editor - " + [Link]()); } catch (IOException ex) { [Link](this, "Error saving file: " + [Link](), "Error", JOptionPane.ERROR_MESSAGE); } } } private void printFile() { try{ textArea print(); } catch (PrinterException ex) { [Link](this, "Error printing file: " + [Link](), "Error", JOptionPane.ERROR_MESSAGE); } } private void undoEdit() { if ([Link]()) { UndoableEdit edit = [Link]([Link]() - 1); [Link]\edit); [Link](); } }private void redoEdit() { if ([Link]()) { UndoableEdit edit = [Link]([Link]() - 1); [Link](edit); edit redo); } } private void closeEditor() { if (isTextModified) { int choice = [Link](this, "Do you want to save changes to the current file?", "Save changes", JOptionPane.YES_NO_CANCEL_OPTION); if (choice == JOptionPane. YES_OPTION) { saveFile(); } else if (choice == JOptionPane.CANCEL_OPTION) { return; } } dispose(); } i DocumentListener methods @Override public void insertUpdate(DocumentEvent e) { isTextModified = true; 2 @Override public void removeUpdate(DocumentEvent e) { isTextModified = true; Z @Override public void changedUpdate(DocumentEvent e) { isTextModified = true; } public static void main(String[] args) { new Editor() } }—_ x] at ce |
You might also like
Java Programming Lab Manual
PDF
No ratings yet
Java Programming Lab Manual
49 pages
Understanding Java Applets and Their Lifecycle
PDF
No ratings yet
Understanding Java Applets and Their Lifecycle
7 pages
JNTUH Java Programming Lab Manual
PDF
No ratings yet
JNTUH Java Programming Lab Manual
28 pages
Oop Through Java Lab Manual New
PDF
No ratings yet
Oop Through Java Lab Manual New
41 pages
Analog Clock in Applet
PDF
No ratings yet
Analog Clock in Applet
3 pages
Java Programming Lab Manual Guide
PDF
No ratings yet
Java Programming Lab Manual Guide
57 pages
Java Programming: Applets and Threads
PDF
No ratings yet
Java Programming: Applets and Threads
24 pages
Convert Calculator Program to Applet
PDF
No ratings yet
Convert Calculator Program to Applet
3 pages
Java Programming: Header File Examples
PDF
No ratings yet
Java Programming: Header File Examples
22 pages
Java Programming Exercises and Solutions
PDF
No ratings yet
Java Programming Exercises and Solutions
16 pages
Eclipse Testing Lab Guide
PDF
No ratings yet
Eclipse Testing Lab Guide
36 pages
Java Programs for Mouse Events and Calculator
PDF
No ratings yet
Java Programs for Mouse Events and Calculator
42 pages
Java Project Setup in IntelliJ IDEA
PDF
No ratings yet
Java Project Setup in IntelliJ IDEA
49 pages
Java Programming Assignments Overview
PDF
No ratings yet
Java Programming Assignments Overview
8 pages
Java GUI Applications: Calculator & Lists
PDF
No ratings yet
Java GUI Applications: Calculator & Lists
14 pages
Java Programming Lab Syllabus and Projects
PDF
No ratings yet
Java Programming Lab Syllabus and Projects
39 pages
Java Thread Communication Example
PDF
No ratings yet
Java Thread Communication Example
43 pages
Java Manual
PDF
No ratings yet
Java Manual
41 pages
Java Lab Programmes
PDF
No ratings yet
Java Lab Programmes
74 pages
Simple Java Swing Calculator Guide
PDF
No ratings yet
Simple Java Swing Calculator Guide
11 pages
Java Programs for File and GUI Operations
PDF
No ratings yet
Java Programs for File and GUI Operations
26 pages
Java Applet Programming Examples
PDF
No ratings yet
Java Applet Programming Examples
35 pages
Advanced Java Programming Lab Record
PDF
No ratings yet
Advanced Java Programming Lab Record
35 pages
Java Programming: IDE Projects and Applets
PDF
No ratings yet
Java Programming: IDE Projects and Applets
51 pages
Java Programs for GUI and Data Structures
PDF
No ratings yet
Java Programs for GUI and Data Structures
27 pages
Java Programming Basics in NetBeans
PDF
No ratings yet
Java Programming Basics in NetBeans
25 pages
Practical-JavaProgramming With Date
PDF
No ratings yet
Practical-JavaProgramming With Date
32 pages
Java Detailed Practical for Execution
PDF
No ratings yet
Java Detailed Practical for Execution
18 pages
Java Programming with NetBeans IDE
PDF
No ratings yet
Java Programming with NetBeans IDE
7 pages
Java Programs for Beginners: Examples
PDF
No ratings yet
Java Programs for Beginners: Examples
89 pages
RMI Factorial Calculation Example
PDF
No ratings yet
RMI Factorial Calculation Example
23 pages
Java Swing Calculator GUI Lab 2024
PDF
No ratings yet
Java Swing Calculator GUI Lab 2024
4 pages
Java Swing Calculator and Applet Examples
PDF
No ratings yet
Java Swing Calculator and Applet Examples
29 pages
AJP Lab Programs
PDF
No ratings yet
AJP Lab Programs
51 pages
Java Exception Handling and GUI Programs
PDF
No ratings yet
Java Exception Handling and GUI Programs
8 pages
Module 5
PDF
No ratings yet
Module 5
18 pages
Java Assignment2
PDF
No ratings yet
Java Assignment2
25 pages
Wa0003.
PDF
No ratings yet
Wa0003.
28 pages
Advanced Java Programming Practicals
PDF
No ratings yet
Advanced Java Programming Practicals
37 pages
Java Programming Lab Manual for B.Tech
PDF
No ratings yet
Java Programming Lab Manual for B.Tech
28 pages
Java Applet Graphics Programming Guide
PDF
No ratings yet
Java Applet Graphics Programming Guide
56 pages
Java Programs for Prime, Leap Year, and More
PDF
No ratings yet
Java Programs for Prime, Leap Year, and More
31 pages
Java Programs for Simple Interest and Area
PDF
No ratings yet
Java Programs for Simple Interest and Area
7 pages
Java OOP Lab Manual for CSE Students
PDF
No ratings yet
Java OOP Lab Manual for CSE Students
36 pages
Advanced Java Applet Programs Guide
PDF
No ratings yet
Advanced Java Applet Programs Guide
26 pages
Universal College: Lab Report On CACS 354: Advanced Java Programming
PDF
No ratings yet
Universal College: Lab Report On CACS 354: Advanced Java Programming
54 pages
All 60 Java Programs Final
PDF
No ratings yet
All 60 Java Programs Final
27 pages
Tannu AJ2
PDF
No ratings yet
Tannu AJ2
36 pages
Java Mouse Cursor Position Applet
PDF
No ratings yet
Java Mouse Cursor Position Applet
19 pages
Java Applet Programming Examples
PDF
No ratings yet
Java Applet Programming Examples
44 pages
Java GUI Integer Division Calculator
PDF
No ratings yet
Java GUI Integer Division Calculator
9 pages
WAP To Develop An Analog Clock Using Applet: Program 19
PDF
No ratings yet
WAP To Develop An Analog Clock Using Applet: Program 19
4 pages
Java Programs for Student Management
PDF
No ratings yet
Java Programs for Student Management
13 pages
Java Generics and GUI Programming Guide
PDF
No ratings yet
Java Generics and GUI Programming Guide
15 pages
Java Swing Calculator and Matrix App
PDF
No ratings yet
Java Swing Calculator and Matrix App
21 pages
Scientific Calculator Micro-Project Report
PDF
No ratings yet
Scientific Calculator Micro-Project Report
17 pages
Java Applet and Matrix Programs Guide
PDF
No ratings yet
Java Applet and Matrix Programs Guide
22 pages
Java Lab Manual for OOP Programming
PDF
No ratings yet
Java Lab Manual for OOP Programming
66 pages
Advanced Java Programming Lab Record
PDF
No ratings yet
Advanced Java Programming Lab Record
46 pages