Posts

Trigger cart item

 trigger CartItemTrigger on Cart_Item__c (before insert, before update) {     // Step 1: Collect all Product Ids from Cart Items     Set<Id> productIds = new Set<Id>();          for (Cart_Item__c item : Trigger.new) {         if (item.Product__c != null) {             productIds.add(item.Product__c);         }     }     // Step 2: Query related Order Line Items     Map<Id, Order_Line_Item__c> productToOrderLineItemMap = new Map<Id, Order_Line_Item__c>();     for (Order_Line_Item__c oli : [         SELECT Product__c, ListPrice__c          FROM Order_Line_Item__c          WHERE Product__c IN :productIds         LIMIT 1     ]) {         productToOrderLineItemMap.put(oli.Product__c, oli); ...

Upload File

  < h3 > File Upload: </ h3 > Select a file to upload: < br /> < form action = "/Dmart/Product" method = "post" enctype = "multipart/form-data" > < input type = "file" name = "Image" size = "50" /> < br /> < input type = "submit" value = "Upload File" /> </ form > //========================================================= import java.io.File; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.Part; @WebServlet("/Product") @MultipartConfig public class Product extends HttpServlet { public Product() { super(); // T...

MDI Open JFreame

    // TODO add your handling code here:         jInternalFrame1.setSize(400, 300);         jInternalFrame1.setLocation(0, 0);         jDesktopPane1.add(jInternalFrame1);         try {             jInternalFrame1.setMaximum(true);         } catch (PropertyVetoException ex) {             Logger.getLogger(DashBoard.class.getName()).log(Level.SEVERE, null, ex);         }      jInternalFrame1.setVisible(true);

DataBase Part1

  import java.sql.Connection;    import java.sql.ResultSet;   import java.sql.DriverManager;  import java.sql.SQLException;       public class DataBase {          private static final String URL = "jdbc:mysql://localhost:3306/testdb";     private static final String USER = "root";     private static final String PASSWORD = "Sabir123@";     private static final String DBDRIVER = "com.mysql.cj.jdbc.Driver";          java.sql.Statement stmt=null;     Connection con;          public void OpenConnection(){                 try{          Class.forName(DBDRIVER); con = DriverManager.getConnection(URL,USER,PASSWORD);          System.out.print("Connection Success");         }catch(Exception e){          ...

USE In another JFrame

     DataBase db=new DataBase();          public NewJFrame() {         initComponents();        // db.OpenConnection(); //       db.Insertrecord("Sabir", "BCA II", "1001", "223333"); //       db.Insertrecord("Prem", "BCA III", "101", "333"); //       db.Insertrecord("Tejas", "BCA I", "1091", "444"); //       db.Insertrecord("Atul", "BCA II", "1021", "555");       // db.Updaterecord("1", "Sabir", "BCA III", "1011", "223333");      ///db.DeleteRecord("1");                ResultSet rs=  db.ReadStudent();          try{           while(rs.next()){               System.out.println("Name:"+rs.getString("Name"));           }         ...

CRUD Opration

 /*  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license  * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template  */   import java.sql.Connection;    import java.sql.ResultSet;   import java.sql.DriverManager;  import java.sql.SQLException;       public class DataBase {          private static final String URL = "jdbc:mysql://localhost:3306/testdb";     private static final String USER = "root";     private static final String PASSWORD = "Sabir123@";     private static final String DBDRIVER = "com.mysql.cj.jdbc.Driver";          java.sql.Statement stmt=null;     Connection con;          public void OpenConnection(){                 try{          Class.forName(DBDR...

🛢️ MySQL Connection & CRUD Operations in Java

🛢️ MySQL Connection & CRUD Operations in Java In this guide, you will learn how to connect Java applications to a MySQL database and perform basic CRUD (Create, Read, Update, Delete) operations using JDBC (Java Database Connectivity). 🔌 1. Setting up MySQL Connector First, download the MySQL Connector/J (JDBC driver) and add the JAR file to your project’s build path or dependencies. 📡 2. Connecting to MySQL Database import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DBConnection { private static final String URL = "jdbc:mysql://localhost:3306/testdb"; private static final String USER = "root"; private static final String PASSWORD = "your_password"; public static Connection getConnection() { try { return DriverManager.getConnection(URL, USER, PASSWORD); } catch (SQLException e) { System.out.println("Connection Failed!"); e.printStackTrace(); ...

📁 Java File Handling

  📘 1. Introduction to File Handling in Java File handling in Java allows programmers to store, retrieve, and manipulate data in files stored on the disk. This is achieved using classes from the java.io and java.nio packages. 📁 2. File Class Overview Java provides a File class in the java.io package to represent the pathnames of files and directories. 📘 1. Creating a File import java.io.File; import java.io.IOException; public class CreateFile { public static void main(String[] args) { try { File file = new File("example.txt"); if (file.createNewFile()) { System.out.println("File created: " + file.getName()); } else { System.out.println("File already exists."); } } catch (IOException e) { System.out.println("An error occurred."); e.printStackTrace(); } } } ✍️ 2. Writing to a File import java....

Font Color Change

  //===========================Step1===    int color_start,color_end;     private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                                  // TODO add your handling code here:                          color_start = textPane1.getSelectionStart();              color_end = textPane1.getSelectionEnd();         FontColorDailog.setVisible(true);     }                                         //==========OnChange Listiner  initComponant()     jColorChooser3.getSelectionModel().addChangeListener(e -> {      StyledDocument doc = tex...

Save as RTF And Read RTF

  ==================Save==============     private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                                  // TODO add your handling code here:       JFileChooser fileChooser = new JFileChooser();         fileChooser.setDialogTitle("Save As");         int userSelection = fileChooser.showSaveDialog(null);         if (userSelection == JFileChooser.APPROVE_OPTION) {             File fileToSave = fileChooser.getSelectedFile();             String filePath = fileToSave.getAbsolutePath();              try (FileOutputStream fos = new FileOutputStream(fileToSave)) {                 new RTFEditorKi...

Open And Read File

  JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Open File"); int userSelection = fileChooser.showOpenDialog(null); if (userSelection == JFileChooser.APPROVE_OPTION) {     File selectedFile = fileChooser.getSelectedFile();     StringBuilder contentBuilder = new StringBuilder();     try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) {         String line;         while ((line = reader.readLine()) != null) {             contentBuilder.append(line).append("\n");         }         textPane1.setText(contentBuilder.toString()); // Show content in textPane1         System.out.println("File loaded: " + selectedFile.getAbsolutePath());     } catch (IOException ex) {         Logger.getLogger(DashBoard.class.getName()).log(Level.SEVERE, null, ex); ...

Save File Dialog

     JFileChooser fileChooser = new JFileChooser();         fileChooser.setDialogTitle("Save As");         int userSelection = fileChooser.showSaveDialog(null);         if (userSelection == JFileChooser.APPROVE_OPTION) {             File fileToSave = fileChooser.getSelectedFile();             String filePath = fileToSave.getAbsolutePath();             // Add .sabir extension if it's not present             if (!filePath.toLowerCase().endsWith(".sabir")) {                 filePath += ".sabir";                 fileToSave = new File(filePath);             }             System.out.println("Save file to: " + fileToSave.getAbsolutePath());       ...

Short Code Class

 //========================= /*  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license  * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template  */ package mdi; import javax.swing.JTextPane; import javax.swing.JToggleButton; import javax.swing.SwingUtilities; import javax.swing.text.AttributeSet; import javax.swing.text.Element; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; public class StylesCollection { public void Font(JTextPane textPane, String styleName, JToggleButton toggleButton) {     StyledDocument doc = textPane.getStyledDocument();     int start = textPane.getSelectionStart();     int end = textPane.getSelectionEnd();     if (start == end) return; // No text selected     // Get the first character's style in the selected text     Element element = doc.ge...

New OnchageColor And SectionMaintain

 //====================OnChage Event =============          jColorChooser1.getSelectionModel().addChangeListener(e -> {     Color selectedColor = jColorChooser1.getColor();     // You can now use the selectedColor or update a preview, etc.     //System.out.println("Selected color: " + selectedColor);     jLabel1.setForeground(selectedColor); }); //========================Set Style============================                    StyledDocument doc = textPane.getStyledDocument();                 int start = textPane.getSelectionStart();                 int end = textPane.getSelectionEnd();                                                   Style style = textPane.a...

TextPan Bold

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                                  // TODO add your handling code here:                   StyledDocument doc = textPane.getStyledDocument();                 int start = textPane.getSelectionStart();                 int end = textPane.getSelectionEnd();                                                   Style style = textPane.addStyle("BoldStyle", null);                 StyleConstants.setBold(style, true);                    ...

Maximux Size yourFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);

import javax.swing.JFrame;   setDefaultCloseOperation(EXIT_ON_CLOSE);  yourFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); //======================Log In Button ===============   if(username.getText().equals("admin")&&password.getText().equals("admin")){             new DashBoard().setVisible(true);             this.setVisible(false);            // System.exit(0);         }else{               JOptionPane.showMessageDialog(null, "Log In Error","Invalid Username or Password.",JOptionPane.ERROR_MESSAGE);         } //=====Minimize button  JInternalFrame internalFrame = new JInternalFrame(     "My Frame",    // Title     true,          // Resizable     true,          // Closable     true,    ...

Call Frame

 ///======External Frame Open  new NewJFrame1().setVisible(true);   System.exit(0); //============     jFrame1.setVisible(true); //open     jFrame1.setVisible(false); //close

MessageBox

   int r=JOptionPane.showConfirmDialog(null,"Warring","Wrong Button Press.",JOptionPane.OK_CANCEL_OPTION,JOptionPane.ERROR_MESSAGE);                  System.out.println(r); https://www.geeksforgeeks.org/java-joptionpane/

jSlider and jProgressBar

 jSlider ===============================================================    private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {                                               // TODO add your handling code here:         int v=jSlider1.getValue();         System.out.println(v);         jLabel2.setText(String.valueOf(v));             }   =================================================================== jProgressBar ===================================================================  private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                                  // TODO ad...

Append New Element

    DefaultListModel listModel1 = new DefaultListModel();         ListModel<String> tempL=  jList1.getModel();                  for(int i=0;i<tempL.getSize();i++){             listModel1.add(i, tempL.getElementAt(i));         }                  listModel1.addElement(jTextField1.getText());                  jList1.setModel(listModel1);         jTextField1.setText("");