Posts

Showing posts from 2019

Java Validate International Phone Numbers

Image
Below is example of how to use Pattern and Matcher in Java, to validate international phone numbers. package myjavaexample; import java.awt.Component; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.regex.Matcher; import java.util.regex.Pattern; 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.JPasswordField; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; public class MyJavaExample extends JFrame { private JTextField textphone = new JTextField(25); public void showFrame() { setTitle( "JFrame Login Example" ); JPanel panel = new JPanel(); panel.setBorder( new EmptyBorder(10, 10, 10, 10)); panel.setLayout( new BoxLayout(panel, BoxLayout.Y_AXIS))...

Java Simple Login Form

Image
This is just simple Java login frame with username and password. package myjavaexample; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; public class MyJavaExample { public void showFrame() { JFrame frame = new JFrame( "JFrame Login Example" ); JPanel panel = new JPanel(); panel.setBorder( new EmptyBorder(10, 10, 10, 10)); panel.setLayout( new GridLayout(3, 2,5,5)); JLabel username = new JLabel( "Username" ); JTextField textuser = new JTextField(25); panel.add(username); panel.add(textuser); JLabel password = new JLabel( "Password...

How to Use Extends and Implements

Image
Java example code, how to use extends and implements in class package myjavaexample; public class MyJavaExample { private interface DoSomething { public void sound(); } private class Animal { public String voice= "Animal" ; public Animal() { } public Animal(String voice) { this .voice=voice; } } private class Pet extends Animal implements DoSomething { public Pet() { } public Pet(String voice) { super(voice); } public void sound() { System.out.println( this .voice); } } public void experiment() { Pet dog= new Pet(); dog.sound(); Pet cat= new Pet( "Miauww" ); cat.sound(); Pet bird= new Pet( "Cici" ); bird.sound(); } ...

How to Calculate Factorial in Java

Image
This is Java code example to calculate factorial problem package myjavaexample; public class MyJavaExample { public static void main(String[] args) { int n=8,result=1; for ( int i=n;i>0;i--){ result*=i; } System.out.println(n+ "! = " +result); } }

Java Get Hour, Minute and Second

Image
Simple code to make analog clock with Java. This section is to show how to get hour, minute and second from java.util.Calendar. package myjavaexample; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.util.Calendar; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.WindowConstants; public class MyJavaExample extends JFrame { public void openImage() { JPanel pane = new JPanel() { protected void paintComponent(Graphics g) { super.paintComponent(g); Calendar now = Calendar.getInstance(); int hour = now.get(Calendar.HOUR); int minute = now.get(Calendar.MINUTE); int second = now.get(Calendar.SECOND); Graphics2D g2d = (Graphics2D)g; g2d.translate(0.5* this .getWidth(),0.5* this .getWidth());...

Java Rotating Images

Image
This is the exemple of Java code how to rotate image. package myjavaexample; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.WindowConstants; public class MyJavaExample extends JFrame { private BufferedImage image; private int rotation=0; public void openImage() { try{ image = ImageIO.read( new File( "C:\\Users\\Edugame\\Documents\\kincir.png" )); }catch(IOException e){} JPanel pane = new JPanel() { protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.RED); g.fillRect(( int )(0.5*getWidt...

Java Font Example in JLabel

Image
Here example code to set font in JLabel: package myjavaexample; import java.awt.Font; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.WindowConstants; public class MyJavaExample extends JFrame { public void openFrame() { JLabel label = new JLabel( "Hello World!" ); Font font = new Font( "Courier" , Font.BOLD,28); label.setFont(font); label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10,10)); add(label); setTitle( "Simple Image Preview" ); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setSize(200,200); setLocation(200,200); pack(); setVisible( true ); } public static void main(String[] args) { MyJavaExample mainwin= new MyJavaExample(); mainwin.openFrame(); } }

Draw an Image to a JPanel

Image
Here's simple Java code to make image or photo preview using JPanel. package myjavaexample; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.WindowConstants; public class MyJavaExample extends JFrame { private BufferedImage image; public void openImage() { try{ image = ImageIO.read( new File( "C:\\Users\\Edugame\\Pictures\\dev_icon3.png" )); }catch(IOException e){} JPanel pane = new JPanel() { protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(image, 0, 0, null); } }; pane.setPreferredSize( new Dimension(image.getWidth(),image.getHeight())); add(pane); setTitle( ...

Java Check a Word in Sentence

For detect a sentence contains a specific word, you can use indexOf function like example code below: package myjavaexample; public class MyJavaExample { public static void main(String[] args) { String sentence= "I like Java programming language, because its can be use in Android also" ; String word = "Java" ; if (sentence.indexOf(word) != -1) { System.out.println( "Found the word \"" + word+ "\" at index number " + sentence.indexOf(word)); } else { System.out.println( "Can't find \"" + word+ "\" inside \"" +sentence+ "\"" ); } } }

Drawing Simple Animation with Java JPanel

Image
Simple Java code, how to animate 2D ball movement with circle in Java JPanel. package myjavaexample; import java.awt.Canvas; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.JFrame; import javax.swing.JPanel; public class MyJavaExample extends JFrame { private MyCanvas canvas= new MyCanvas(); public void setup() { this .setSize(800,600); this .setLocation(200,200); this .setTitle( "Drawing Simple Animation" ); canvas.setPreferredSize( new Dimension(400,300)); this .add(canvas); this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this .setResizable( false ); this .pack(); this .setVisible( true ); canvas.calldraw(); } private class MyCanvas extends JPanel { private int x=20,y=20,vx=3,vy=4; ...

JScrollPane Resize Allowing JFrame Size

Image
This code is show how to allow JScrollPane allowing size of parent size with GridBagLayout. package myjavaexample; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.border.EmptyBorder; public class MyJavaExample extends JFrame { public void setup() { this .setSize(800,600); this .setLocation(200,200); this .setTitle( "JScrollPane Resize Allowing JFrame Size" ); this .setLayout( new GridBagLayout()); GridBagConstraints con = new GridBagConstraints(); con.fill = GridBagConstraints.BOTH; con.weightx = 1; con.weighty = 1; con.gridx = 0; con.gridy = 0; JPanel panel= new JPanel(); panel.setLayout( new GridBagLayout()); panel.setBorder( new Empty...

Activate JTextArea Right Click Mouse

Image
This is the Java code example how to activated right click in JTextArea. package myjavaexample; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.Action; import javax.swing.BoxLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.KeyStroke; import javax.swing.border.EmptyBorder; import javax.swing.text.DefaultEditorKit; import javax.swing.text.JTextComponent; import javax.swing.text.TextAction; public class MyJavaExample extends JFrame { public void setup() { this .setSize(800,600); this .setLocation(200,200); this .setTitle( "JTextArea Right Click" ); this .setLayout( new BorderLayout()); JPanel panel= new JPanel(); panel.setBorder( new EmptyBorder(5, 10, 5, 10)); JTextArea t...

Simple Java Code HTML Highlighter

Image
This is simple code to highlight Java code to insert in HTML page: package htmltotext; import java.awt.BorderLayout; import java.awt.Dimension; 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.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.border.EmptyBorder; public class HTMLtoText extends JFrame { private JTextArea textArea = new JTextArea(); private JTextArea textHasil = new JTextArea(); private String[] tobiru= new String[]{ "new" , "package" , "import" , "public" , "private" , "protected" , "extends" , "implements" , "for" , "if" , "while" , "class" , "int" , "float" , "double" , "this" , "true...

Simple Java Multithread in Array

Image
Simple Java multithread code that use thread as array and Thread.currentThread().getId function: Code package myjavaexample; public class MyJavaExample extends Thread { public void run() { System.out.println( "Thread ID=" +Thread.currentThread().getId()); } public static void main(String[] args) { MyJavaExample[] example= new MyJavaExample[10]; for ( int i=0;i<example.length;i++){ example[i]= new MyJavaExample(); example[i].start(); } } }

Simple Java Hello World

Image
Simple Java Hello World with Netbeans. The code: package myjavaexample; public class MyJavaExample { public static void main(String[] args) { System.out.println("Hello World!"); } }

Java Code to Detect and Write Sitemap Manually

Image
Here the simple Java code to make a mini application to create sitemap in my static web. I build with JFrame and FileOutputStream for write result to file. package sitemap.maker; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; public class SiteMapMaker extends JFrame { private JTextField jnama=new JTextField(25); private JLabel jl = new JLabel(); private String checkIndexPHP(String path,int id,File folder) { File[] files = folder.listFiles(); ...

Pong Game with HTML5 Canvas

Image
Here the simple code Pong Game with HTML5 Canvas <div style="text-align:center;"> <canvas id="myCanvas" width="600" height="400" style="border:1px solid #000000;"></canvas> </div> <script> var ky1=0,ky2=0,px=0,py=0,vx=0,vy=0,scorekiri=0,scorekanan=0; var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); var lastMouse={x:0,y:0}; var pressedState=false; ky1=ky2=Math.round(0.5*c.height)-30; function drawGame(){ //draw background ctx.beginPath(); ctx.rect(0, 0,c.width,c.height); ctx.fillStyle = "black"; ctx.fill(); //draw middle line ctx.beginPath(); ctx.moveTo(Math.round(0.5*c.width),0); ctx.lineTo(Math.round(0.5*c.width),c.height); ctx.strokeStyle = "white"; ctx.lineWidth = 5; ctx.setLineDash([8,3]); ctx.stroke(); //draw kotak 1 ctx.beginPath(); ctx.rect(0,ky1,20,60); ctx.fillStyle = "white"; ctx.fill(); //draw...

The Wordpress Plugin of WhatsApp Floating Button

Image
Usually website communication need public feedback to see users enthusiasm of website's contents. One of the feedback, can be use WhatsApp floating button at right bottom of page, as screenshot image below. Uboiz WA Float Icon is simple Wordpress widget plugin to show floating WhatsApp button. Where the WhatApp number can be edited in widget form. This plugin tested on Wordpress 5.0.3 and place this plugin in your Wordpress plugin folder ( /wp-content/plugins/ ). Download Uboiz WA Float Icon Reference Castro, Kevin. 2019. Whatsapp-floating-button . https://codepen.io/demoonkevin/pen/MvPEpV . Accessed date 16 Jan 2019.

Simple Marquee Latest Post Wordpress Plugin

Image
Marquee is HTML element that used to insert a scrolling area of text horizontally or vertically. Uboiz-marquee-latest-post is a simple Wordpress plugin to show the latest post as horizontally marquee. Where the interface presented as Wordpress widget, the number of posts can be changed how many to displayed as marquee, up to 10 posts. And as Widget, its also can be placed in the sidebar as needed. Place this plugin in Wordpress plugin folder ( /wp-content/plugins/ ) and its tested at Wordpress 5.0.3. Download Uboiz Marquee Widget

Simple Wordpress Plugin to Show Page List

Image
Below is simple code that use wp_list_pages of Wordpress function as plugin. You can use shortcode [uboiz_list_page] in page, as like as screenshot below: This plugin tested in Wordpress 5.0.2, and you can download and place in plugin folder ( /wp-content/plugins/ ) in your Wordpress site. Download uboiz-page-list.zip