Posts

Ask for more

If anyone is having any trouble in developing the program in any language, is humbly welcome. Post your comments

Property Event-Delegation

import javax.swing.JFrame; import javax.swing.JButton; import java.awt.Color; import java.awt.EventQueue; import java.awt.BorderLayout; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; class BoundFrame extends JFrame {     private JButton button1;     private JButton button2;     private Random random;         public BoundFrame() {         initialize();     }         private void initialize() {         button1 = new JButton("Select Me");         button2 = new JButton("No Select Me");         random = new Random();                 button1.addActionListener(new Butt...

Moving Banner on Window

import java.awt.Graphics; import java.awt.Color; import java.awt.Font; import java.awt.event.MouseEvent; import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.event.MouseMotionAdapter; public class MoveBannerFrame extends JFrame {     public MoveBannerFrame() {         BannerLabel lbl = new BannerLabel();                 lbl.setFont(new Font("TimesRoman", Font.BOLD, 32));         lbl.setForeground(Color.RED);                 add(lbl);     }     public static void main(String[] args) {         MoveBannerFrame frame = new MoveBannerFrame();         frame.setTitle("Mouse Motion");         frame.setSize(1000, 600);         frame.setLoc...

Largest palindrome multiple of two three digit numbers

public class LargestPamildromeof3Digits {     public static int reverse(int n) {         int num = 0;         int size = String.valueOf(n).length() - 1;                 while (n > 0) {             num += (n % 10) * (int)Math.pow(10, size--);             n /= 10;         }                 return num;     }     public static boolean isPalindrome(int n) {         if (n == reverse(n))             return true;         else             return false;     }       ...

It's Magic...................

import javax.swing.JOptionPane; public class MagicOf9 {     public static void main(String[] args) {         String msg = "Think and write somewhere n digit number, \n" +             "note that all digits must be unique \nfor e.g. for three" +             " digit number I am assuming 123, \nwhere 1, 2, and 3 are " +             "different and unique digits. \nNow add all the digits in " +             "the number \nfor e.g. in our case it is 1 + 2 + 3. \nThe sum " +             "is 6. \nNow subtract this resultant (i.e. 6 in this example) \n" +             "from the supposed number. \nEnter your any (n - 1) digits like \n" +           ...

Method with variable arguments

class VarArgs {     public static void main(String[] args) {         System.out.println(sum(1));                System.out.println(sum(1, 2));                System.out.println(sum(1, 2, 3));                System.out.println(sum(1, 2, 3, 4));            }         static int sum(int...args) {         int sum = 0;             for (int i = 0; i < args.length; i++)             sum += args[i];                     return sum;     } }

Zeller's Congruence

class ZellersCongruence {     /**     * Calculate day of week using Zeller's Congruence     *     * For the Gregorian calendar     * h =(q + floor(13(m + 1) / 5) + K + floor(K / 4) + floor(J/ 4) + 5J) % 7     *     * For Julian calendar     * h =(q + floor(13(m + 1) / 5) + K + floor(K / 4) + 5 + 6J) % 7     *     * where     * h is the day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, ...)     * q is the day of the month     * m is the month (3 = March, 4 = April, 5 = May, ..., 14 = February)     * K the year of the century (year % 100).     * J is the century (actually floor(year/100)) (For example, in 1995 the century would be 19, even though it was the 20th century.)     *     * NOTE: In this algorithm January and February are ...