Posts Tagged ‘java’

Intercepting Events With A Glass Pane

Thursday, August 25th, 2005

There are a ton of GlassPane examples out there, but it was hard to find a good concise one that did exactly what I wanted. So here are the results of a spike.

This should create a GlassPane that catches all mouse / key events and disappears only when escape is pressed.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GlassPane extends JPanel {
	public void install(final RootPaneContainer rootPane) {
		final Component prevGlassPane = rootPane.getGlassPane();
		addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
		addFocusListener(new FocusAdapter() {
			public void focusLost(FocusEvent e) {
		addKeyListener(new KeyAdapter() {
			public void keyTyped(KeyEvent e) {
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
	public void paint(Graphics g) {
		g.setFont(new Font("Arial", Font.BOLD, 24));
		g.drawString("Glass!!!", 110, 140);
	public static void main(String[] args) {
		final JFrame frame = new JFrame("GlassPane Test");
		JButton showButton = new JButton("Click here to show glass pane");
		showButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new GlassPane().install(frame);
		frame.getContentPane().setLayout(new BorderLayout(10, 10));
		frame.getContentPane().add(BorderLayout.NORTH, new JTextField("TextField1"));
		frame.getContentPane().add(BorderLayout.CENTER, new JTextField("TextField2"));
		frame.getContentPane().add(BorderLayout.EAST, showButton);
		frame.setSize(new Dimension(575, 300));

What Should You Use For Java Persistence

Thursday, January 22nd, 2004

People keep asking me what to use for persistence in java. Definitely not entity beans :)

|These days I’m more in the .Net world, but I still know quite a few !ThoughtWorkers in the Java world, I called on|people.JoeWalnes|
(a published author now!) and one of the !ThoughtWorkers that does a decent job of impressing the hell out of me, for a recommendation I could pass on.

joejoejoewalnes: if you want relational db persistence, hibernate is the way to go. if you want to pay, try kodo (a commercial jdo impl)… both are very good
joejoejoewalnes: if you want simpler persistence and dont care about a rdbms, try prevayler or jdbm
joejoejoewalnes: and if you want to learn about hibernate, buy my book

So there you have it people.

*Hibernate –

*Kodo –

*Prevayler –


and as for Joe’s shameless plug ;)

*Java Open Source Programming on Amazon –