Skip to content

Instantly share code, notes, and snippets.

View Blasanka's full-sized avatar
🚀
Flutter dev

B Liyanage Asanka Blasanka

🚀
Flutter dev
View GitHub Profile
@Blasanka
Blasanka / TokenizerExample.java
Last active June 5, 2017 11:46
In this code snippet I have taken an example to show you how Java StringTokenizer works.
package stringTokenizer;
import java.util.StringTokenizer;
public class TokenizerExample {
public static void main(String[] args) {
String url = "https//www.facebook.com/slcoders";
@Blasanka
Blasanka / BufferedReader.java
Last active April 9, 2017 18:13
Here is how to get user input to java program using BufferedReader implementation and descripion as a comment
package SLCoder;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Buffer {
public static void main(String[] args)throws Exception {
//System.in get default input device - keyboard
@Blasanka
Blasanka / FinalKeyword.java
Created March 31, 2017 20:02
This code snippet about final keyword in java. As a intro - We can use final keyword to variable then that variable become constant and if we use final keyword to a method that method cannot override and if we use for class that class stop inheriting.
class Father {
//delete final to get rid from error
public final void doingNow(){
System.out.println("reading book");
}
}
@Blasanka
Blasanka / MD5.java
Created June 5, 2017 11:38
JProgressBar Example(Only how progress bar works not functional).
This is a sample example for `JProgressBar`. This
import java.awt.EventQueue;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.FileInputStream;
import java.security.MessageDigest;
import java.util.List;
import javax.swing.JFrame;
@Blasanka
Blasanka / Main.java
Created June 5, 2017 15:06
Simple Example for JLabel mouse clicked. In this example when mouse clicked shows another JFrame and close the Main JFrame. Note: this is only for study purpose but having multiple JFrames in one application is not good solution. Instead you can use one JFrame and Multiple JPanels with appropriate layouts.
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Main {
JFrame MainFrame;
JFrame ChildFrame;
JLabel label;
@Blasanka
Blasanka / Example.java
Last active June 6, 2017 16:50
This is the main file(Example.java) and the second class called "ChildExample.java". Both are in this file you have to divide to two java files.
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Example {
private JFrame frame;
@Blasanka
Blasanka / Combination.java
Created June 6, 2017 19:55
This is a simple program created for get combinations for any given number set. Note: efficience wise this is not hundred persent good.
import java.util.ArrayList;
import java.util.List;
public class Combinations {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
int[] a = {0,1,2};//change values as many you want
for(int i: a){
list.add(i+"");//add first numbers in array- 1,2,3
@Blasanka
Blasanka / Jlist.java
Last active June 7, 2017 19:30
This simple program I have created for you to see how to get all the values in the JList. everythig explained by the comments so that you can understand easily. Also if you want to get selected items in JList you find my gist. If you have any problems, comment below.
/*
B Liyanage asanka - code snippets for you.
twitter - @bliyanageasanka
*/
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@Blasanka
Blasanka / airport_db_query.sql
Created June 8, 2017 11:56
This gist for airport database. This was design to give some question and relevant queries for those questions. In query you have also provided queries for creating tables and and sample exercises.
-------------------DDL-----------------------
CREATE TABLE Customer(
customerId INT PRIMARY KEY,
name VARCHAR(30),
age INT,
phone CHAR(10)
)
@Blasanka
Blasanka / MainFrame.java
Last active July 13, 2017 17:15
This java code to show you how to close one JFrame from a button click without closing another JFrame(dispose() in Window class) and how to close all the JFrame's using a button. Note: this code only open up a new JFrame and code for that frame is here: https://gist.github.com/Blasanka/e1a19df553d1e502b4c3aacaa3c6f7c0 In that link you can see al…
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;
public class MainFrame {
JFrame mainFrame;