View RSS Feed

Most Popular Blogs

  1. JList Example

    by , 12-28-2011 at 12:17 AM
    Java Code:
    package myPackage;
    
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    
    public class ListFrame extends JFrame
    {
    	JList myJList;
    	String[] colorrs;
    ...
    Categories
    Uncategorized
  2. JList Multiple Selection and Copying with a Button to Another JList Example

    by , 12-28-2011 at 11:33 PM
    Java Code:
    package myPackage;
    
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.ListSelectionModel;
    
    public class MultipleSelectionFrame extends JFrame 
    {
    	private static final long	serialVersionUID	= 1L;
    	private JList colorJList;
    ...
    Categories
    Uncategorized
  3. A Simple GridLayout Example

    by , 12-29-2011 at 01:12 AM
    Java Code:
    package myPackage;
    
    import java.awt.Container;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    
    public class GridLayoutFrame extends JFrame implements ActionListener
    {
    	
    	private JButton[] buttons; // array of buttons
    	private static final String[] names = {"one", "two", "three"
    ...
    Categories
    Uncategorized
  4. Look of a Calculator

    by , 12-30-2011 at 06:37 PM
    Java Code:
    package myPackage;
    
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    public class SimpleCalculator {
    
    	public static void main(String[] args) 
    	{
    		JFrame myFrame = new JFrame( "Testing" );
    ...
    Categories
    Uncategorized
  5. Writing an Array Object to a Binary File and Reading Back

    by , 01-14-2012 at 12:03 AM
    Java Code:
    package myPackage;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FilterOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.OutputStream;
    import java.io.PrintStream;
    import java.io.PrintWriter;
    import java.io.Serializable;
    ...
    Categories
    Uncategorized
  6. Reading Bytes from a Text File

    by , 01-14-2012 at 12:48 AM
    Java Code:
    package myPackage;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FilterOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.OutputStream;
    import java.io.PrintStream;
    import java.io.PrintWriter;
    import java.io.Serializable;
    ...
    Categories
    Uncategorized
  7. Reading Byte From a Text File and Printing To Console Character And Byte Value

    by , 01-14-2012 at 12:12 PM
    Java Code:
    public static void main(String[] args) 
    	{
    		File myText = new File("c:/myDir/myText.txt");
    		
    		try {
    			InputStream myByteReader = new FileInputStream(myText);
    			System.out.println("Available total bytes:" + myByteReader.available());
    			int firstByte = myByteReader.read();
    			System.out.println("First byte:" + firstByte);
    			System.out.println("Char of first byte:" + (char) firstByte);
    ...
    Categories
    Uncategorized
  8. Reading a Files first line with a simple gui application

    by , 01-16-2012 at 12:12 AM
    Java Code:
    package myPackage;
    
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.Scanner;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    
    public class FileOrganizer extends JFrame implements ActionListener 
    {
    	public
    ...
    Categories
    Uncategorized
  9. Using of Class Class. An Example:

    by , 01-28-2012 at 11:30 AM
    Java Code:
    package myPackage1;
    
    interface HasBatteries{};
    interface Waterproof{};
    interface Shoots{};
    
    class Toy
    {
    	Toy(){};
    	Toy(int i){};
    }
    
    class FancyToy extends Toy implements HasBatteries,Waterproof,Shoots
    {
    	FancyToy()
    	{
    		super(1);
    	}
    }
    
    public class ToyTest 
    {
    	static void printInfo(Class cc)
    	{
    		System.out.println("Class name:
    ...
    Categories
    Uncategorized
  10. Casting with Class: Class.

    by , 01-28-2012 at 09:21 PM
    Java Code:
    public class ClassCasts 
    {
    	
    	public static void main(String args[])
    	{
    		Building b = new House();
    		Class<House> houseType = House.class;
    		House h = houseType.cast(b);
    		System.out.println(b.getClass());
    	}
    
    }
    Categories
    Uncategorized
  11. Initializing

    by , 02-01-2012 at 07:23 PM
    Java Code:
    package myPackage;
    
    public class SprinklerSystem 
    {
    	private String valve1;
    	private int valveStrength;
    	private WaterSource source = new WaterSource();
    	
    	static 
    	{
    		System.out.println("You are in Static block!");
    	}
    
    	{
    		System.out.println("You are in initi block!");
    		this.valve1 = "Valve1 ";
    	}
    	
    
    	
    	SprinklerSystem()
    ...
    Categories
    Uncategorized
  12. Using of Inner Classes

    by , 02-06-2012 at 01:15 AM
    Java Code:
    package myPackage2;
    
    public abstract class Event 
    {
    	private long eventTime;
    	protected final long delayTime;
    	
    	public Event(long delayTime)
    	{
    		this.delayTime = delayTime;
    		start();
    	}
    	
    	public void start()
    	{
    		eventTime = System.nanoTime() + 2*delayTime;
    	}
    	
    	public boolean ready()
    	{
    		return System.nanoTime() >= eventTime;
    	}
    ...
    Categories
    Uncategorized
  13. A little on Containers. ( Collections + Maps )

    by , 02-07-2012 at 08:39 PM
    Java Code:
    package myPaackkage;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.LinkedHashMap;
    import java.util.LinkedHashSet;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Map;
    import java.util.TreeMap;
    import java.util.TreeSet;
    
    public class
    ...
    Categories
    Uncategorized
  14. Checking for Randomness of Java with HashMap

    by , 02-07-2012 at 11:19 PM
    Java Code:
    package myPaackkage;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.ListIterator;
    import java.util.Random;
    
    public class SayisalGenerator {
    	
    	static Random myRandomGenerator = new Random();
    	
    	public static void main(String[] args)
    	{
    		HashMap<Integer,Integer> myHashMap = new HashMap<Integer,Integer>();
    		
    		for(int i=0;i<1000;i++)
    		{
    ...
    Categories
    Uncategorized
  15. Making your own class Iterable.

    by , 02-09-2012 at 08:21 PM
    Java Code:
    package myPaackkage;
    
    import java.util.*;
    
    
    public class SomeClass implements Iterable<String> 
    {
    	@Override
    	public Iterator<String> iterator() 
    	{
    		System.out.println("Hello!!");
    		
    		return new Iterator<String>()
    				{
    			private int i = 0;
    
    					@Override
    					public boolean hasNext() {
    						while(i<words.size())
    							return true;
    ...

    Updated 02-21-2012 at 11:33 PM by fatabass (Code tags.)

    Categories
    Uncategorized
  16. Listing the installed look and feels

    by , 02-15-2012 at 08:55 PM
    Java Code:
    import javax.swing.UIManager;
    
    public class TestClass {
    
    	public static void main(String args[]) {
    		UIManager.LookAndFeelInfo laf[] = UIManager
    				.getInstalledLookAndFeels();
    		for (int i = 0, n = laf.length; i < n; i++) {
    			System.out.print("LAF Name: " + laf[i].getName() + "\t");
    			System.out.println("  LAF Class name: "
    					+ laf[i].getClassName());
    		}
    		System.exit(0);
    ...
    Categories
    Uncategorized
  17. Strategy Pattern Example

    by , 03-03-2012 at 11:20 PM
    Java Code:
    package strategyPattern;
    
    public class Warrior {
    	
    	private AttackBehaviour attackBehaviour;
    	public String name;
    
    	void setAttackBehaviour(AttackBehaviour aB) {
    		this.attackBehaviour = aB;
    	}
    	
    	void attack() {
    		attackBehaviour.attack();
    	}
    }
    
    package strategyPattern;
    
    public interface AttackBehaviour {
    	
    	void attack();
    
    }
    
    package
    ...
    Categories
    Uncategorized
  18. Self Made Observable Pattern

    by , 03-03-2012 at 11:50 PM
    Java Code:
    package observerPatternSelfMade;
    
    public class MyObservableClass implements MyObservableInterface {
    
    	
    	
    	@Override
    	public void registerObserver(MyObserverInterface o) {
    		observers.add(o);
    	}
    
    	@Override
    	public void removeObserver(MyObserverInterface o) {
    		observers.remove(o);
    	}
    
    	@Override
    	public void notifyObservers() {
    		
    		for(int i = 0; i<observers.size();i++)
    ...
    Categories
    Uncategorized
  19. Factory Pattern Example

    by , 03-04-2012 at 09:10 PM
    Java Code:
    package factoryPattern2;
    
    public abstract class Product {
    	
    	private String productName;
    	
    	public void setName(String name) {
    		this.productName = name;
    	}
    	
    	public String getName() {
    		return productName;
    	}
    
    	public void putInABox() {
    		System.out.println("Putting the product in a box..");
    	}
    
    }
    
    
    package factoryPattern2;
    ...
    Categories
    Uncategorized
  20. isTheStringPalinDrome, reverseTheWordOrder, fibonaciWithoutRecursion, removeDuplicates

    by , 04-03-2012 at 11:51 PM
    Java Code:
    package assignmentOne;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Set;
    
    public class PartOneAssignments {
    	
    	// This method accepts a String as the argument and checks whether it is palindrome or not
    	static boolean isTheStringPalinDrome(String s) {
    		
    		// Be positive and assume that the String provided is Palindrome
    		boolean stringIsPalinDrome = true;
    ...
    Categories
    Uncategorized
  21. Homework help - Dice Roll

    by , 04-28-2013 at 01:03 AM
    Quote Originally Posted by Slick Java View Post
    Hi, I am having trouble with this program. The point of this program is to roll a dice, store dice values in an array and print out how much time the value has been occurred. The output should be like this:

    1 3

    4 1

    5 1

    2 1

    But I am getting this:

    1 3

    4 1

    5 1

    1 3

    2 1

    1 3


    I am trying to find a way to get
    ...
    Categories
    Uncategorized
  22. Help centering the square inside

    by , 09-14-2013 at 12:40 AM
    Quote Originally Posted by Messi5454 View Post
    I emailed the instructor my code and he said the only thing i have to do is center my inner square .
    i attached picture
    Attachment 5522

    Java Code:
    import java.awt.*;
    
    import javax.swing.*;
    
    
    // begining of the Gepmetry class
    // geometry class uses JFrame to draw the window and 
    // geometric shapes  
    public class Hw2  extends JFrame {
    
    //Variables to use for drawing 3 shapes.
    ...
    Categories
    Uncategorized
Page 2 of 2 FirstFirst 12