Skip to content

Instantly share code, notes, and snippets.

BJ Peter DeLaCruz bjpeterdelacruz

Block or report user

Report or block bjpeterdelacruz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View SampleJideApp.java
JFrame frame = new JFrame();
final JPanel panel = new JPanel();
// Create tree and add nodes.
DefaultMutableTreeNode root = new DefaultMutableTreeNode(new TestObject("Hello"));
root.add(new DefaultMutableTreeNode(new TestObject("World")));
root.add(new DefaultMutableTreeNode(new TestObject("Foo")));
root.add(new DefaultMutableTreeNode(new TestObject("Bar")));
final JTree tree = new JTree(root);
@bjpeterdelacruz
bjpeterdelacruz / DynamicClassLoadingExample.java
Last active Dec 11, 2015
How to dynamically load a class, de-serialize an object that was serialized using the loaded class, and ignore serialVersionUID in a unit test.
View DynamicClassLoadingExample.java
private URLClassLoader childClassLoader;
private Class<?> clazz;
@Before
public void init() throws Exception {
// put class file in same package together with this source file
URL url = getClass().getResource("MyClass.class").toURI().toURL();
childClassLoader = new URLClassLoader(new URL[] { url },
getClass().getClassLoader());
clazz = childClassLoader.loadClass("com.bpd.old.MyClass");
@bjpeterdelacruz
bjpeterdelacruz / sieve.java
Last active Dec 26, 2015
A Java program that will find all prime numbers between 0 and N.
View sieve.java
import java.util.ArrayList;
/**
* This program finds all of the prime numbers between 0 and a number supplied by the user,
* inclusive.
*
* @author BJ Peter DeLaCruz
* @version 1.1
*/
public class CountingPrimeNumbers {
View codingstandard1.java
ahead(centerY * 2); // Move to the bottom edge.
turnRight(90.0); // Face west.
ahead(centerX); // Move to the lower left corner.
turnRight(90.0); // Face north.
ahead(centerY * 2); // Move to the upper left corner.
View codingstandard2.java
counter = 0; // If robot loses radar contact with enemy after 10 turns,
tracker = 0; // try to find it again or pick another enemy by resetting
// tracker back to zero.
View codingstandard3.java
// Move to the bottom edge.
ahead(centerY * 2);
// Face west.
turnRight(90.0);
// Move to the lower left corner.
ahead(centerX);
// Face north.
turnRight(90.0);
// Move to the upper left corner.
ahead(centerY * 2);
@bjpeterdelacruz
bjpeterdelacruz / MyFileChooser.java
Created Oct 21, 2013
A custom file chooser that will change the state of the Open button when the user clicks on a file
View MyFileChooser.java
public class MyFileChooser extends JFileChooser {
public MyFileChooser() {
setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
addPropertyChangeListener(new MyListener());
}
private class MyListener implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent event) {
String property = FileChooser.SELECTED_FILE_CHANGED_PROPERTY;
View junit_ex1.java
SomeObject obj = new SomeObject();
assertFalse(obj.hasA() || obj.hasB() || obj.hasC());
assertTrue(obj.hasD() && obj.hasE());
View junit_ex2.java
SomeObject obj = new SomeObject();
assertTrue(!obj.hasA());
assertTrue(!obj.hasB());
assertTrue(!obj.hasC());
assertTrue(obj.hasD());
assertTrue(obj.hasE());
View junit_ex3.java
SomeObject obj = new SomeObject();
// initial state
assertTrue(obj.hasA());
assertTrue(obj.hasB());
assertTrue(obj.hasC());
assertTrue(obj.hasD());
assertTrue(obj.hasE());
// perform some changes
assertTrue(!obj.hasA());
You can’t perform that action at this time.