diff --git a/source/_posts/Armstrong-Number-Program.md b/source/_posts/Armstrong-Number-Program.md index b8cd51c9a829b91a04180936b34766cc7d87b199..526ff57a51fc5578e3d06c482a6ac7ef1f60acf4 100644 --- a/source/_posts/Armstrong-Number-Program.md +++ b/source/_posts/Armstrong-Number-Program.md @@ -1,6 +1,6 @@ --- title: Armstrong Number Program -date: 2016-10-11 16:56:37 +date: 2012-01-27 08:03:45 categories: - Codes tags: diff --git a/source/_posts/Calculate-Celsius-to-Fahrenheit-Temperature-in-Java.md b/source/_posts/Calculate-Celsius-to-Fahrenheit-Temperature-in-Java.md new file mode 100644 index 0000000000000000000000000000000000000000..949af8980fcc00b498f989ca076107bb9f8d2e57 --- /dev/null +++ b/source/_posts/Calculate-Celsius-to-Fahrenheit-Temperature-in-Java.md @@ -0,0 +1,84 @@ +--- +title: Calculate Celsius to Fahrenheit Temperature in Java +date: 2012-06-16 15:31:13 +categories: + - Codes +tags: + - code-example + - java + - swing +--- +In-order to convert from Celsius to Fahrenheit, we have to apply a simple logic onto Celsius "Multiply by 9, then divide by 5, then add 32". + +Our code provides a simple GUI, where the user has to enter the temperature in Celsius and after clicking on convert displays the Fahrenheit temperature below button in the form of JLabel. + +The Class has been designed by extending JPanel which can be called from other classes and added onto the JFrame for displaying. + +#### Screenshot + +![Calculate Celsius to Fahrenheit Temperature in Java Screenshot](/images/output_celsius_fahrenheit_java.jpg) + +#### C2F.java + +```java +package com.rohansakhale.treedemo; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +/** + * + * @author RohanSakhale + */ +public class C2F extends JPanel { + + JTextField tfInputTemp; + JLabel lInputTemp, lAnswer; + JButton bCalc; + JPanel InputTemp, collections; + + public C2F() { + tfInputTemp = new JTextField(15); + lInputTemp = new JLabel("Enter Temperature in Celsius: "); + lAnswer = new JLabel("Answer: "); + bCalc = new JButton("Convert"); + InputTemp = new JPanel(); + collections = new JPanel(); + collections.setLayout(new BoxLayout(collections, BoxLayout.Y_AXIS)); + InputTemp.add(lInputTemp); + InputTemp.add(tfInputTemp); + collections.add(InputTemp); + collections.add(bCalc); + collections.add(lAnswer); + bCalc.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (!tfInputTemp.getText().equals("")) { + double temp = Double.parseDouble(tfInputTemp.getText()); + double fahrenheit = ((temp * 9) / 5) + 32; + lAnswer.setText("Answer: " + fahrenheit + " F"); + } + } + }); + add(collections); + } +} + +class C2FMainDemo{ + public static void main(String[] args) { + JFrame c2fFrame = new JFrame("Celsius to Fahrenheit Demo Program"); + C2F c2f = new C2F(); + c2fFrame.add(c2f); + c2fFrame.setSize(400, 150); + c2fFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + c2fFrame.setVisible(true); + } +} +``` \ No newline at end of file diff --git a/source/_posts/Calculate-Fahrenheit-to-Celsius-Temperature-in-Java.md b/source/_posts/Calculate-Fahrenheit-to-Celsius-Temperature-in-Java.md new file mode 100644 index 0000000000000000000000000000000000000000..5d219c735ab4bad42f9218559ea496d1c31450ad --- /dev/null +++ b/source/_posts/Calculate-Fahrenheit-to-Celsius-Temperature-in-Java.md @@ -0,0 +1,83 @@ +--- +title: Calculate Fahrenheit to Celsius Temperature in Java +date: 2012-06-16 15:31:03 +categories: + - Codes +tags: + - code-example + - java + - swing +--- +In-order to convert from Fahrenheit to Celsius, we have to apply a simple logic onto Celsius "Deduct 32, then multiply by 5, then divide by 9". + +Our code provides a simple GUI, where the user has to enter the temperature in Fahrenheit and after clicking on convert displays the Celsius temperature below button in the form of JLabel. + +The Class has been designed by extending JPanel which can be called from other classes and added onto the JFrame for displaying. + +#### Screenshot: + +![Calculate Fahrenheit to CelsiusTemperature in Java](/images/output_fahrenheit_celsius_java.jpg) + +#### F2C.java + +```java +package com.rohansakhale.treedemo; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +/** + * + * @author RohanSakhale + */ +public class F2C extends JPanel{ + JTextField tfInputTemp; + JLabel lInputTemp, lAnswer; + JButton bCalc; + JPanel InputTemp, collections; + + public F2C() { + tfInputTemp = new JTextField(15); + lInputTemp = new JLabel(\"Enter Temperature in Fahrenheit: \"); + lAnswer = new JLabel(\"Answer: \"); + bCalc = new JButton(\"Convert\"); + InputTemp = new JPanel(); + collections = new JPanel(); + collections.setLayout(new BoxLayout(collections, BoxLayout.Y_AXIS)); + InputTemp.add(lInputTemp); + InputTemp.add(tfInputTemp); + collections.add(InputTemp); + collections.add(bCalc); + collections.add(lAnswer); + bCalc.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (!tfInputTemp.getText().equals(\"\")) { + double temp = Double.parseDouble(tfInputTemp.getText()); + double celsius = (temp - 32 ) * 5 / 9; + lAnswer.setText(\"Answer: \" + celsius + \" C\"); + } + } + }); + add(collections); + } +} + +class F2CMainDemo{ + public static void main(String[] args) { + JFrame f2cFrame = new JFrame(\"Celsius to Fahrenheit Demo Program\"); + F2C f2c = new F2C(); + f2cFrame.add(f2c); + f2cFrame.setSize(400, 150); + f2cFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f2cFrame.setVisible(true); + } +} +``` \ No newline at end of file diff --git a/source/_posts/Concurrent-Chat-Application-in-Java.md b/source/_posts/Concurrent-Chat-Application-in-Java.md index ec54c4e1469ec68debc3eecb7d636b877e953ffe..e15e26f26d0df66acdc67b3c6a00e9504844bbd3 100644 --- a/source/_posts/Concurrent-Chat-Application-in-Java.md +++ b/source/_posts/Concurrent-Chat-Application-in-Java.md @@ -1,6 +1,6 @@ --- title: Concurrent Chat Application in Java -date: 2016-10-11 20:57:45 +date: 2012-06-16 15:50:12 categories: - Codes tags: diff --git a/source/_posts/Convert-Integer-to-Binary.md b/source/_posts/Convert-Integer-to-Binary.md index 49222d8cd6b8842747e7d28af27d3d3944d95bf8..fa95a4d8b533a89b6538acd81b3a530ecb60c09c 100644 --- a/source/_posts/Convert-Integer-to-Binary.md +++ b/source/_posts/Convert-Integer-to-Binary.md @@ -1,6 +1,6 @@ --- title: Convert Integer to Binary -date: 2016-10-11 17:22:49 +date: 2012-02-12 23:56:09 categories: - Codes tags: diff --git a/source/_posts/Create-Web-Service-using-PHP-JSON.md b/source/_posts/Create-Web-Service-using-PHP-JSON.md index c867afe8df886ca2b6efc053092a67e6eabc8019..16ec63baa3bfac9edd9167d82343e32fb45bd285 100644 --- a/source/_posts/Create-Web-Service-using-PHP-JSON.md +++ b/source/_posts/Create-Web-Service-using-PHP-JSON.md @@ -1,6 +1,6 @@ --- title: Create Web Service using PHP & JSON -date: 2016-10-11 18:09:47 +date: 2012-05-24 16:36:40 categories: - Codes tags: diff --git a/source/_posts/Draw-Line-using-Bresenham-s-Algorithm.md b/source/_posts/Draw-Line-using-Bresenham-s-Algorithm.md index fcc757d64f64aceb7700cef33e621c04b69ee7e7..6350ecb869463f8fd0b8aac4bfc3ac66a23d4b1a 100644 --- a/source/_posts/Draw-Line-using-Bresenham-s-Algorithm.md +++ b/source/_posts/Draw-Line-using-Bresenham-s-Algorithm.md @@ -1,6 +1,6 @@ --- title: Draw Line using Bresenham's Algorithm -date: 2016-10-11 16:55:06 +date: 2011-11-12 12:25:40 categories: - Codes tags: diff --git a/source/_posts/Draw-Line-using-DDA-Algorithm.md b/source/_posts/Draw-Line-using-DDA-Algorithm.md index 2ea870b4b05348f3b156e5c9d248c2da6999c9fb..fde43f6e1b568200405bcf8cbd8cbad470626f22 100644 --- a/source/_posts/Draw-Line-using-DDA-Algorithm.md +++ b/source/_posts/Draw-Line-using-DDA-Algorithm.md @@ -1,6 +1,6 @@ --- title: Draw Line using DDA Algorithm -date: 2016-10-11 16:53:37 +date: 2011-11-12 12:11:39 categories: - Codes tags: diff --git a/source/_posts/Factorial-Number-Program-in-PHP.md b/source/_posts/Factorial-Number-Program-in-PHP.md index a85fb60b04f398f63fc8e3b9b15199af16de458f..70209d77e02966bf6b8d0e805eb99ff2cf18670e 100644 --- a/source/_posts/Factorial-Number-Program-in-PHP.md +++ b/source/_posts/Factorial-Number-Program-in-PHP.md @@ -1,6 +1,6 @@ --- title: Factorial Number Program in PHP -date: 2016-10-11 17:45:01 +date: 2012-06-06 00:02:03 categories: - Codes tags: diff --git a/source/_posts/Factorial-Program-in-Java.md b/source/_posts/Factorial-Program-in-Java.md new file mode 100644 index 0000000000000000000000000000000000000000..796fd3aaea4d7186dd33af30961add13c452e0a4 --- /dev/null +++ b/source/_posts/Factorial-Program-in-Java.md @@ -0,0 +1,103 @@ +--- +title: Factorial Program in Java +date: 2012-06-16 15:31:33 +categories: + - Codes +tags: + - code-example + - java +--- +In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, + +``` +5! = 5 x 4 x 3 x 2 x 1 = 120 +``` + +The following code creates a GUI for calculating factorial numbers upto 170. + +The user has to enter the number and click on Calculate which displays the answer on JLabel below the button. + +The Class has been designed by extending JPanel which can be called from other classes and added onto the JFrame for displaying. + +#### Screenshot + +![Factorial Program in Java](/images/output_factorial_java.jpg) + +#### Factorial.java + +```java +package com.rohansakhale.fact; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; + +/** + * + * @author RohanSakhale + */ +public class Factorial extends JPanel { + + JTextField tfNumber; + JLabel lEnterNumber, lAnswer; + JButton bCalc; + JPanel number, collection; + + public Factorial() { + tfNumber = new JTextField(15); + lEnterNumber = new JLabel("Enter Number: "); + lAnswer = new JLabel("Answer: "); + bCalc = new JButton("Calculate"); + number = new JPanel(); + collection = new JPanel(); + collection.setLayout(new BoxLayout(collection, BoxLayout.Y_AXIS)); + number.add(lEnterNumber); + number.add(tfNumber); + collection.add(number); + collection.add(bCalc); + collection.add(lAnswer); + + bCalc.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (!tfNumber.getText().equals(")) { + double num = Integer.parseInt(tfNumber.getText()); + if(num <= 170){ + double fact = 1; + for(double i = 1;i<=num;i++){ + fact = fact * i; + } + lAnswer.setText("Answer: " + fact); + tfNumber.setText("); + tfNumber.requestFocus(); + }else{ + JOptionPane.showMessageDialog(null, "Please enter number upto 170", "Error", JOptionPane.ERROR_MESSAGE); + } + }else{ + JOptionPane.showMessageDialog(null, "Please enter number upto 170", "Error", JOptionPane.ERROR_MESSAGE); + } + } + }); + add(collection); + } +} + +class FactorialDemo{ + public static void main(String[] args) { + JFrame factFrame = new JFrame("Factorial Demo Program"); + Factorial fact = new Factorial(); + factFrame.add(fact); + factFrame.setSize(400,150); + factFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + factFrame.setVisible(true); + } +} + +``` \ No newline at end of file diff --git a/source/_posts/File-IO-Operation-in-Java.md b/source/_posts/File-IO-Operation-in-Java.md index 5326e9c1e019eb10d1eab49540a1da6db9e6ae53..5507f1e88c268d3214993273ad6fc0cae125cfbf 100644 --- a/source/_posts/File-IO-Operation-in-Java.md +++ b/source/_posts/File-IO-Operation-in-Java.md @@ -1,6 +1,6 @@ --- title: File IO Operation in Java -date: 2016-10-11 17:37:31 +date: 2012-06-27 14:25:44 categories: - Codes tags: diff --git a/source/_posts/Funny-Program.md b/source/_posts/Funny-Program.md index 77655c97cb2435c633a89c08b4175671ebf3a25c..864a25f159f9d3580ed53ce7729b90408ee7b979 100644 --- a/source/_posts/Funny-Program.md +++ b/source/_posts/Funny-Program.md @@ -1,6 +1,6 @@ --- title: Funny Program -date: 2016-10-11 17:11:08 +date: 2012-01-27 08:03:25 categories: - Codes tags: diff --git a/source/_posts/JList-Java-Swing-Component-Demo.md b/source/_posts/JList-Java-Swing-Component-Demo.md index ed3bd0b04b20d82f676c1cc461123886adabf87b..bed21189702529e5fc9a69d489f649f1b0b4bc57 100644 --- a/source/_posts/JList-Java-Swing-Component-Demo.md +++ b/source/_posts/JList-Java-Swing-Component-Demo.md @@ -1,6 +1,6 @@ --- title: JList Java Swing Component Demo -date: 2016-10-11 16:51:53 +date: 2011-11-12 08:14:02 categories: - Codes tags: diff --git a/source/_posts/JTree-Java-Swing-Component-Demo.md b/source/_posts/JTree-Java-Swing-Component-Demo.md index af6cc29f2b086b0be9e8813b79e0a3d7e6a04809..5fd17cc0e52b402620c10f913529eb29406aeeb1 100644 --- a/source/_posts/JTree-Java-Swing-Component-Demo.md +++ b/source/_posts/JTree-Java-Swing-Component-Demo.md @@ -1,6 +1,6 @@ --- title: JTree Java Swing Component Demo -date: 2016-10-11 16:52:51 +date: 2011-11-12 10:33:50 categories: - Codes tags: diff --git a/source/_posts/JTree-Simple-Practice-Application-in-Java.md b/source/_posts/JTree-Simple-Practice-Application-in-Java.md new file mode 100644 index 0000000000000000000000000000000000000000..30bb2c1f162a97b56d0afffd897befefc32f7af5 --- /dev/null +++ b/source/_posts/JTree-Simple-Practice-Application-in-Java.md @@ -0,0 +1,136 @@ +--- +title: JTree Simple Practice Application in Java +date: 2012-06-16 15:24:18 +categories: + - Codes +tags: + - code-example + - java + - swing +--- +JTree is a control that displays a set of hierarchical data as an outline. + +We will use it as a menu to navigate through various small applications we made previously. + +The tree will basically contain each program as a node when selected using mouse, that particular program is displayed onto the JFrame. + +Programs used in this code are already being posted before for practice, I will name the Class & the link to find the class + +1. [Simple Calculator in Java]() +1. [Factorial Program in Java]() +1. [Calculate Celsius to Fahrenheit Temperature in Java]() +1. [Calculate Fahrenheit to Celsius Temperature in Java]() + +#### Screenshot + +![JTree Simple Practice Application in Java Output 1](/images/output_jtree_prac_app_1.jpg) + +![JTree Simple Practice Application in Java Output 2](/images/output_jtree_prac_app_2.jpg) + +![JTree Simple Practice Application in Java Output 3](/images/output_jtree_prac_app_3.jpg) + +![JTree Simple Practice Application in Java Output 4](/images/output_jtree_prac_app_4.jpg) + +![JTree Simple Practice Application in Java Output 5](/images/output_jtree_prac_app_5.jpg) + +#### TreeDemo.java + +```java +package com.rohansakhale.treedemo; + +import java.awt.BorderLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JFrame; +import javax.swing.JTree; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreePath; + +/** + * + * @author RohanSakhale + */ +public class TreeDemo { + + static String lastComponent = \"\"; + + public static void main(String[] args) { + final JFrame jf = new JFrame(\"Practice Applications\"); + + DefaultMutableTreeNode pracApps = new DefaultMutableTreeNode(\"Practice Apps\", true); + DefaultMutableTreeNode calc = new DefaultMutableTreeNode(\"Calculator\"); + DefaultMutableTreeNode fact = new DefaultMutableTreeNode(\"Factorial\"); + DefaultMutableTreeNode temperature = new DefaultMutableTreeNode(\"Temperature\", true); + DefaultMutableTreeNode c2f = new DefaultMutableTreeNode(\"C to F\"); + DefaultMutableTreeNode f2c = new DefaultMutableTreeNode(\"F to C\"); + temperature.add(c2f); + temperature.add(f2c); + pracApps.add(calc); + pracApps.add(fact); + pracApps.add(temperature); + final JTree tree = new JTree(pracApps); + + // JTree here can act as a menu for Practice Applications + // We add it on the west side of the JFrame + + jf.add(BorderLayout.WEST, tree); + + /* + * Classes created here within the same package can also be found online + * Calc = http://rohansakhale.com/codes/39/simple-calculator-in-java + * Factorial = http://rohansakhale.com/codes/40/factorial-program-in-java + * C2F = http://rohansakhale.com/codes/41/calculate-celsius-to-fahrenheit-temperature-in-java + * F2C = http://rohansakhale.com/codes/42/calculate-fahrenheit-to-celsius-temperature-in-java + * + */ + final Calc calculatorPanel = new Calc(); + final Factorial factorialPanel = new Factorial(); + final C2F c2fObj = new C2F(); + final F2C f2cObj = new F2C(); + + // Lets change the panel on center of JFrame + // by checking the mouse click + tree.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent me) { + TreePath path = tree.getPathForLocation(me.getX(), me.getY()); + if (path != null) { + // Check the last added component and remove it + if (!lastComponent.equals(\"\")) { + if (lastComponent.equals(\"Factorial\")) { + jf.remove(factorialPanel); + } else if (lastComponent.equals(\"C to F\")) { + jf.remove(c2fObj); + } else if (lastComponent.equals(\"Calculator\")) { + jf.remove(calculatorPanel); + } else if (lastComponent.equals(\"F to C\")) { + jf.remove(f2cObj); + } + } + + // Add the new component on the frame + // Depending on the Selected Tree Node + if (path.toString().contains(\"Calculator\")) { + jf.add(calculatorPanel); + lastComponent = \"Calculator\"; + } else if (path.toString().contains(\"Factorial\")) { + jf.add(factorialPanel); + lastComponent = \"Factorial\"; + } else if (path.toString().contains(\"C to F\")) { + jf.add(c2fObj); + lastComponent = \"C to F\"; + } else if (path.toString().contains(\"F to C\")) { + jf.add(f2cObj); + lastComponent = \"F to C\"; + } + jf.repaint(); + } + } + }); + jf.setSize(600, 400); + jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + jf.setVisible(true); + } +} +``` \ No newline at end of file diff --git a/source/_posts/Java-Socket-Program-to-check-Prime-Number.md b/source/_posts/Java-Socket-Program-to-check-Prime-Number.md index a9db90b74cb7aff6574776d0fb6e407f3d7f3416..d294143deeff35c1754caa5309c4d6e82b9e9da7 100644 --- a/source/_posts/Java-Socket-Program-to-check-Prime-Number.md +++ b/source/_posts/Java-Socket-Program-to-check-Prime-Number.md @@ -1,6 +1,6 @@ --- title: Java Socket Program to check Prime Number -date: 2016-10-11 17:25:39 +date: 2012-02-13 15:14:51 categories: - Codes tags: diff --git a/source/_posts/Login-Validation-Program.md b/source/_posts/Login-Validation-Program.md index 6a961cdfe506b8e0e157723d418cfbf4e409394f..57d445e44a4edc563878b3449543c8b9efc79e76 100644 --- a/source/_posts/Login-Validation-Program.md +++ b/source/_posts/Login-Validation-Program.md @@ -1,6 +1,6 @@ --- title: Login Validation Program -date: 2016-10-11 16:50:10 +date: 2011-11-12 07:59:07 categories: - Codes tags: diff --git a/source/_posts/Midpoint-Circle-Algorithm.md b/source/_posts/Midpoint-Circle-Algorithm.md index 267f609bcd60b31b95743b540d427e5b2d73c14e..ac652aab6824689fcb5d03b5f3a66561329d8a2c 100644 --- a/source/_posts/Midpoint-Circle-Algorithm.md +++ b/source/_posts/Midpoint-Circle-Algorithm.md @@ -1,6 +1,6 @@ --- title: Midpoint Circle Algorithm -date: 2016-10-11 16:55:59 +date: 2011-11-14 18:58:45 categories: - Codes tags: diff --git a/source/_posts/PHP-Factorial-program-using-GMP-Functions.md b/source/_posts/PHP-Factorial-program-using-GMP-Functions.md new file mode 100644 index 0000000000000000000000000000000000000000..144237873c834c0f521af8d37a3719c7eadec1c8 --- /dev/null +++ b/source/_posts/PHP-Factorial-program-using-GMP-Functions.md @@ -0,0 +1,40 @@ +--- +title: PHP Factorial program using GMP Functions +date: 2012-06-04 17:13:14 +categories: + - Codes +tags: + - code-example + - php +--- +Regular working with arbitrary number is usually a tough job, normally for generating factorial number using the regular looping methods you can generate only upto 170, and it doesn't work for huge numbers. + +**GMP** is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating point numbers. + +GMP functions allow you to work with arbitrary-length integers using the GNU MP library. + +You may need to do the initializations of GMP onto the server side if it don't work directly, read on php.net for it. + +For complete reference on GMP functions [visit here](http://www.php.net/manual/en/ref.gmp.php). + +The following code accepts a number from user and on the server side it is checked if numeric and passed onto the `gmp_fact()` method which returns the factorial of it and output is displayed on the screen. + +#### gmp_try.php + +```php +\'; + } else { + echo \'Enter proper number
\'; + } +} +?> +
+ Enter Number:
+ +
+``` \ No newline at end of file diff --git a/source/_posts/Pascal-Traingle.md b/source/_posts/Pascal-Traingle.md index 116173641368ec3fa87bc56548b18f88ff47f9ed..b95b73a72616cf8879c8a1770735a923860d454d 100644 --- a/source/_posts/Pascal-Traingle.md +++ b/source/_posts/Pascal-Traingle.md @@ -1,6 +1,6 @@ --- title: Pascal Traingle -date: 2016-10-11 17:17:05 +date: 2012-02-07 08:25:19 categories: - Codes tags: diff --git a/source/_posts/Pattern-Printing-1.md b/source/_posts/Pattern-Printing-1.md index ffbaa5b202c1d6abfdc7b84c29df2ac6d0e4f887..ae0d42a186c80c8cb2e539fbe149c12243897f8a 100644 --- a/source/_posts/Pattern-Printing-1.md +++ b/source/_posts/Pattern-Printing-1.md @@ -1,6 +1,6 @@ --- title: Pattern Printing 1 -date: 2016-10-11 17:14:19 +date: 2012-03-17 16:00:21 categories: - Codes tags: diff --git a/source/_posts/Pattern-Printing-2.md b/source/_posts/Pattern-Printing-2.md index dd91c9d31165433f6b50d621d3565af32119d1c0..d8e8c4ea8c00d2300f5efe3a6b00c03d4985429a 100644 --- a/source/_posts/Pattern-Printing-2.md +++ b/source/_posts/Pattern-Printing-2.md @@ -1,6 +1,6 @@ --- title: Pattern Printing 2 -date: 2016-10-11 17:42:26 +date: 2012-03-21 20:51:50 categories: - Codes tags: diff --git a/source/_posts/Pattern-Printing-3.md b/source/_posts/Pattern-Printing-3.md index cc6d5de9a11679845b260e6f5ac60663a3773fde..ba3c163979321cf193d651d75d6525449e7d953c 100644 --- a/source/_posts/Pattern-Printing-3.md +++ b/source/_posts/Pattern-Printing-3.md @@ -1,6 +1,6 @@ --- title: Pattern Printing 3 -date: 2016-10-11 18:01:13 +date: 2012-03-21 20:51:40 categories: - Codes tags: diff --git a/source/_posts/Pattern-Printing-4.md b/source/_posts/Pattern-Printing-4.md index 2b542f9b214f7949a5edfb9b6e296eb145cb7dbc..716ecea83d5e03d4e74217510d926f72951228fd 100644 --- a/source/_posts/Pattern-Printing-4.md +++ b/source/_posts/Pattern-Printing-4.md @@ -1,6 +1,6 @@ --- title: Pattern Printing 4 -date: 2016-10-11 18:03:21 +date: 2012-03-28 14:38:41 categories: - Codes tags: diff --git a/source/_posts/Program-to-find-Perfect-Number-s-upto-1000.md b/source/_posts/Program-to-find-Perfect-Number-s-upto-1000.md index d47a1bf3e2285acd90e858f1c35e7b15521c6e2f..6edd41292343fd4e79882ff979a0ea013d3e60b9 100644 --- a/source/_posts/Program-to-find-Perfect-Number-s-upto-1000.md +++ b/source/_posts/Program-to-find-Perfect-Number-s-upto-1000.md @@ -1,6 +1,6 @@ --- title: Program to find Perfect Number's upto 1000 -date: 2016-10-11 17:40:09 +date: 2012-03-12 22:50:10 categories: - Codes tags: diff --git a/source/_posts/Random-Panel-Color-in-Java.md b/source/_posts/Random-Panel-Color-in-Java.md index 339bf8a4316d925deaa221a819d6dab67f815a3e..1857c20f09f7efecb4b872f9a60678b203f80a50 100644 --- a/source/_posts/Random-Panel-Color-in-Java.md +++ b/source/_posts/Random-Panel-Color-in-Java.md @@ -1,6 +1,6 @@ --- title: Random Panel Color in Java -date: 2016-10-11 20:42:04 +date: 2012-06-16 19:27:21 categories: - Codes tags: diff --git a/source/_posts/Simple-Calculator-in-Java.md b/source/_posts/Simple-Calculator-in-Java.md new file mode 100644 index 0000000000000000000000000000000000000000..bce2291173fa6101c80074fdab6d146d0cb6ec2d --- /dev/null +++ b/source/_posts/Simple-Calculator-in-Java.md @@ -0,0 +1,131 @@ +--- +title: Simple Calculator in Java +date: 2012-06-16 15:31:44 +categories: + - Codes +tags: + - code-example + - java +--- +Creating a **simple graphical calculator** to perform Addition, Subtraction, Multiplication & Division made up using swing components. + +User has to input numbers as A & B and the output will be based on the two numbers given by user. + +Select the appropriate operation & output is displayed below using JLabel. + +The Class has been designed by extending JPanel which can be called from other classes and added onto the JFrame for displaying. + +#### Screenshot + +![Simple Calculate in Java Screenshot](/images/output_simple_calc_java.jpg) + +#### Calc.java + +```java +package com.rohansakhale.calc; + +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; + +/** + * + * @author RohanSakhale + */ +public class Calc extends JPanel { + + JTextField tfInputA, tfInputB; + JLabel lInputA, lInputB, lAnswer; + JButton bAdd, bSub, bMult, bDiv; + JPanel inputA, inputB, operations, collection; + + public Calc() { + tfInputA = new JTextField(15); + tfInputB = new JTextField(15); + lInputA = new JLabel("Enter Input A: "); + lInputB = new JLabel("Enter Input B: "); + lAnswer = new JLabel("Answer: "); + bAdd = new JButton(" + "); + bAdd.setSize(50, 20); + bSub = new JButton(" - "); + bSub.setSize(50, 20); + bMult = new JButton(" * "); + bMult.setSize(50, 20); + bDiv = new JButton(" / "); + bDiv.setSize(50, 20); + inputA = new JPanel(); + inputB = new JPanel(); + operations = new JPanel(new GridLayout(0, 2)); + collection = new JPanel(); + collection.setLayout(new BoxLayout(collection, BoxLayout.Y_AXIS)); + + CalcListener myListener = new CalcListener(); + + bAdd.addActionListener(myListener); + bSub.addActionListener(myListener); + bMult.addActionListener(myListener); + bDiv.addActionListener(myListener); + + inputA.add(lInputA); + inputA.add(tfInputA); + inputB.add(lInputB); + inputB.add(tfInputB); + operations.add(bAdd); + operations.add(bSub); + operations.add(bMult); + operations.add(bDiv); + + collection.add(inputA); + collection.add(inputB); + collection.add(operations); + collection.add(lAnswer); + add(collection); + } + + class CalcListener implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + + if (!tfInputA.getText().equals(") && !tfInputB.getText().equals(")) { + int a = Integer.parseInt(tfInputA.getText()); + int b = Integer.parseInt(tfInputB.getText()); + double answer = 0; + if (e.getSource() == bAdd) { + answer = a + b; + } else if (e.getSource() == bSub) { + answer = a - b; + } else if (e.getSource() == bMult) { + answer = a * b; + } else if (e.getSource() == bDiv) { + answer = a / b; + } + tfInputA.setText(""); + tfInputB.setText(""); + tfInputA.requestFocus(); + lAnswer.setText("Answer: " + answer); + } else { + JOptionPane.showMessageDialog(null, "Please enter proper values", "Error", JOptionPane.ERROR_MESSAGE); + } + } + } +} + +class CalculatorDemo{ + public static void main(String[] args) { + JFrame calcFrame = new JFrame("Calculator Demo"); + Calc calc = new Calc(); + calcFrame.add(calc); + calcFrame.setSize(400, 300); + calcFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + calcFrame.setVisible(true); + } +} +``` \ No newline at end of file diff --git a/source/_posts/Stack-Program-for-Android.md b/source/_posts/Stack-Program-for-Android.md index 0faeb2cd6dbe6f5d6533f47d4353d80751f540a1..19186e6dd0dcef92775379a53e0835e91ea61a40 100644 --- a/source/_posts/Stack-Program-for-Android.md +++ b/source/_posts/Stack-Program-for-Android.md @@ -1,6 +1,6 @@ --- title: Stack Program for Android -date: 2016-10-11 17:29:39 +date: 2012-03-17 16:31:14 categories: - Codes tags: diff --git a/source/_posts/Stack-Program-in-Object-Functional-Programming.md b/source/_posts/Stack-Program-in-Object-Functional-Programming.md index cce28b9e90854db2599266e7c545a47fa9dd8833..d46d7e591034b4064ad9a5b518dc7eb386aa45d5 100644 --- a/source/_posts/Stack-Program-in-Object-Functional-Programming.md +++ b/source/_posts/Stack-Program-in-Object-Functional-Programming.md @@ -1,6 +1,6 @@ --- title: Stack Program in Object Functional Programming -date: 2016-10-11 18:56:08 +date: 2012-05-24 21:25:14 categories: - Codes tags: diff --git a/source/_posts/Stack-Queue-using-MVC-architecture-in-Javascript.md b/source/_posts/Stack-Queue-using-MVC-architecture-in-Javascript.md new file mode 100644 index 0000000000000000000000000000000000000000..09d76512a11c1911c14505705650a7b58aa532a3 --- /dev/null +++ b/source/_posts/Stack-Queue-using-MVC-architecture-in-Javascript.md @@ -0,0 +1,208 @@ +--- +title: Stack & Queue using MVC architecture in Javascript +date: 2012-06-18 08:54:07 +categories: + - Codes +tags: + - code-example + - javascript + - mvc +--- +MVC i.e. **Model-View-Controller** architecture usually separates the program in three parts which are **Model** i.e. the code we write in the form of modules or that represents a model, **View** that helps in displaying data to the user in the form of GUI and **Controller** usually handles the user gestures carried out on the GUI. + +When using MVC architecture, our view can remain the same and by changing the Model it reflects the view with the help of the controller i.e. user interaction. + +The following program represents one view for displaying the data and two models of a Stack & Queue Data Structures to impact on the control passed by the user i.e. GUI interaction. + +Since we are using Javascript for representing these data structures, all functions act on the client side and no server side call is being made. + + +#### Live Demo + +

See the Pen MVC Datastructure JavaScript by Rohan Sakhale (@rsakhale) on CodePen.

+ + +#### Screenshots + +![MVC Architecture Data Structures Output #1](/images/output_mvc_stack_queue_1.jpg) +![MVC Architecture Data Structures Output #2](/images/output_mvc_stack_queue_2.jpg) +![MVC Architecture Data Structures Output #3](/images/output_mvc_stack_queue_3.jpg) +![MVC Architecture Data Structures Output #4](/images/output_mvc_stack_queue_4.jpg) + +#### Code + +```html + + + + + Data Structures in Javascript {Object Functional Programming} - {Using MVC Pattern} + + + + +
+
+
+ + + +
+
+ www.rohansakhale.com +
+ + + +``` \ No newline at end of file diff --git a/source/_posts/Stack-using-CPP-Array.md b/source/_posts/Stack-using-CPP-Array.md index a4a05f4005ce4125efc422c2dbd3d0a0fb9e7681..5fbf3e06830d096e06b6d5cf486edea620b4d55b 100644 --- a/source/_posts/Stack-using-CPP-Array.md +++ b/source/_posts/Stack-using-CPP-Array.md @@ -1,6 +1,6 @@ --- title: Stack using CPP Array -date: 2011/11/10 16:26:36 +date: 2011-11-10 16:26:36 categories: - Codes tags: diff --git a/source/_posts/Swing-Components-using-Grid-Layout-in-Java.md b/source/_posts/Swing-Components-using-Grid-Layout-in-Java.md index 09e92fe58296dccd5d176976bd6a816803f38962..78708611a3beb866149fbf70488f938ba6e34651 100644 --- a/source/_posts/Swing-Components-using-Grid-Layout-in-Java.md +++ b/source/_posts/Swing-Components-using-Grid-Layout-in-Java.md @@ -1,6 +1,6 @@ --- title: Swing Components using Grid Layout in Java -date: 2016-10-11 20:51:24 +date: 2012-06-27 15:25:17 categories: - Codes tags: diff --git a/source/_posts/Swing-Demo-Program.md b/source/_posts/Swing-Demo-Program.md index 0f929b6dd703d481954a712e824750c373283f8d..2d8cde92e6fc9a4fbad26791773da354962bf7eb 100644 --- a/source/_posts/Swing-Demo-Program.md +++ b/source/_posts/Swing-Demo-Program.md @@ -1,6 +1,6 @@ --- title: Swing Demo Program -date: 2012/05/27 14:38:25 +date: 2012-05-27 14:38:25 categories: - Codes tags: diff --git a/source/_posts/UDP-program-to-Reverse-string.md b/source/_posts/UDP-program-to-Reverse-string.md index 6f8458b4e031157ab05b7eea396b23849af82598..670415d4908f907ca1357b2c20f2ca6d4f252d0f 100644 --- a/source/_posts/UDP-program-to-Reverse-string.md +++ b/source/_posts/UDP-program-to-Reverse-string.md @@ -1,6 +1,6 @@ --- title: UDP program to Reverse string -date: 2016-10-11 18:05:23 +date: 2012-05-19 14:46:31 categories: - Codes tags: diff --git a/source/_posts/Using-JSON-Web-Service-in-Java-Program.md b/source/_posts/Using-JSON-Web-Service-in-Java-Program.md index 6b236537ba1db145679ef1bf5961c870d611111b..3a2777fa6cf86ecf6383e28603625d938a22c378 100644 --- a/source/_posts/Using-JSON-Web-Service-in-Java-Program.md +++ b/source/_posts/Using-JSON-Web-Service-in-Java-Program.md @@ -1,6 +1,6 @@ --- title: Using JSON Web Service in Java Program -date: 2016-10-11 18:49:00 +date: 2012-05-24 18:22:05 categories: - Codes tags: diff --git a/source/images/output_celsius_fahrenheit_java.jpg b/source/images/output_celsius_fahrenheit_java.jpg new file mode 100644 index 0000000000000000000000000000000000000000..84596ad4e9745bd3a079b45ce13df5a4a813a395 Binary files /dev/null and b/source/images/output_celsius_fahrenheit_java.jpg differ diff --git a/source/images/output_fahrenheit_celsius_java.jpg b/source/images/output_fahrenheit_celsius_java.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f9589b359ea75b551a75525e6d697a8b79085aa4 Binary files /dev/null and b/source/images/output_fahrenheit_celsius_java.jpg differ diff --git a/source/images/output_jtree_prac_app_1.jpg b/source/images/output_jtree_prac_app_1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c5ec6196d5febbd922b17e0356bfbd263de6ef6c Binary files /dev/null and b/source/images/output_jtree_prac_app_1.jpg differ diff --git a/source/images/output_jtree_prac_app_2.jpg b/source/images/output_jtree_prac_app_2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5627121390ede5dc36dfa0ea1378034d22581c74 Binary files /dev/null and b/source/images/output_jtree_prac_app_2.jpg differ diff --git a/source/images/output_jtree_prac_app_3.jpg b/source/images/output_jtree_prac_app_3.jpg new file mode 100644 index 0000000000000000000000000000000000000000..70e5ea5f8f498db213143c109d3fd93134f58b44 Binary files /dev/null and b/source/images/output_jtree_prac_app_3.jpg differ diff --git a/source/images/output_jtree_prac_app_4.jpg b/source/images/output_jtree_prac_app_4.jpg new file mode 100644 index 0000000000000000000000000000000000000000..979efc004759c49a1731e0d0638348e37b4d55a4 Binary files /dev/null and b/source/images/output_jtree_prac_app_4.jpg differ diff --git a/source/images/output_jtree_prac_app_5.jpg b/source/images/output_jtree_prac_app_5.jpg new file mode 100644 index 0000000000000000000000000000000000000000..712989abdf9ee4ddc50e4b8be7ed7ab210738dad Binary files /dev/null and b/source/images/output_jtree_prac_app_5.jpg differ diff --git a/source/images/output_mvc_stack_queue_1.jpg b/source/images/output_mvc_stack_queue_1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..744e9e310e9ea698cb5f1739edbdc499bd688299 Binary files /dev/null and b/source/images/output_mvc_stack_queue_1.jpg differ diff --git a/source/images/output_mvc_stack_queue_2.jpg b/source/images/output_mvc_stack_queue_2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..afaf76e5335e912bb0d7dc2c05e80b27c978e676 Binary files /dev/null and b/source/images/output_mvc_stack_queue_2.jpg differ diff --git a/source/images/output_mvc_stack_queue_3.jpg b/source/images/output_mvc_stack_queue_3.jpg new file mode 100644 index 0000000000000000000000000000000000000000..62fa0186ae081a9461c3cfe990a245a8e6b1f11b Binary files /dev/null and b/source/images/output_mvc_stack_queue_3.jpg differ diff --git a/source/images/output_mvc_stack_queue_4.jpg b/source/images/output_mvc_stack_queue_4.jpg new file mode 100644 index 0000000000000000000000000000000000000000..33235802724f953aa91c536ea55da3e8bb28656d Binary files /dev/null and b/source/images/output_mvc_stack_queue_4.jpg differ diff --git a/source/images/output_simple_calc_java.jpg b/source/images/output_simple_calc_java.jpg new file mode 100644 index 0000000000000000000000000000000000000000..216a086b54683ef81af274a67a5a04fdb8c06d3a Binary files /dev/null and b/source/images/output_simple_calc_java.jpg differ diff --git a/themes/next/_config.yml b/themes/next/_config.yml index 4792a9aae275082aa35dbbcbcd382390d6f12503..e899fdf461345911191cfa41a1f245f419af1815 100644 --- a/themes/next/_config.yml +++ b/themes/next/_config.yml @@ -58,8 +58,8 @@ menu_icons: # Schemes scheme: Muse -#scheme: Mist -#scheme: Pisces +# scheme: Mist +# scheme: Pisces # --------------------------------------------------------------- diff --git a/themes/next/languages/default.yml b/themes/next/languages/default.yml index 109b72cc7ee1ee21ffd5948bcf02472c8172b606..c986175a61c8c82f134da63afb7340f5e47ad10a 100644 --- a/themes/next/languages/default.yml +++ b/themes/next/languages/default.yml @@ -8,6 +8,8 @@ author: Author menu: home: Home archives: Archives + codes: Codes + company: Company categories: Categories tags: Tags about: About