Skip to content

Instantly share code, notes, and snippets.

View lebesnec's full-sized avatar
🦆
quack 🦆

Christophe Le Besnerais lebesnec

🦆
quack 🦆
View GitHub Profile
package ilist.ui;
import ilist.ui.generic.components.TransparentPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Frame;
someComponent.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("color") && evt.getNewValue() instanceof Color) {
Color color = (Color) evt.getNewValue();
someComponent.setColor(color);
someComponent.repaint();
}
}
});
public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
public static final String PROTOCOL = "jdbc:derby:";
public static final String DATABASE_NAME = "myGreatDatabase";
private Connection connection = null;
private void () {
try {
Class.forName(DRIVER).newInstance();
connection = DriverManager.getConnection(PROTOCOL + DATABASE_NAME + ";create=true");
public void shutdown() {
try {
connection.close();
DriverManager.getConnection(PROTOCOL + ";shutdown=true");
} catch (SQLException se) {
// an exception is thrown even if the database is closed correctly,
// so we have to check the current state to see if something failed
if (!"XJ015".equals(se.getSQLState()))
se.printStacktrace();
public void initTables() {
Statement statement1 = null;
PreparedStatement statement2 = null;
try {
statement1 = connection.createStatement();
statement1.execute("create table people(name varchar(40) not null, age int)");
connection.commit();
statement2 = connection.prepareStatement("insert into people values (?, ?)");