Some reader favorites:
EJB fundamentals and session beans
Create a scrollable virtual desktop in Swing
More action with Struts 2
In a recent review of Struts 2 in Action, JW Blogger Oleg Mikheev notes that Struts 2 is "just a collection of extensions built upon WebWork, which is ultimately
the right thing to learn before starting a Struts 2 project." While Struts 2 has some architectural flaws, Oleg calls WebWork
well-designed, well-tested, and reliable. What are your experiences using Struts 2 and WebWork?
Also see "Hello World the WebWork way," a JavaWorld excerpt from WebWork in Action, by Patrick Lightbody and Jason Carreira.
| Memory Analysis in Eclipse |
| Enterprise AJAX - Transcend the Hype |
How do you set menu and button hotkeys in Java? I use JDK 1.1.4; is the method to do this in JDK 1.2 any different?
The example below should answer your question about hotkeys in Java. The code shows how to set up a mnemonic for a menu, a
menu item, a check box, and a button. You can activate the hotkeys by pressing Alt and the mnemonic.
It'll work with both JDK 1.1 and JDK 1.2. Please note that with JDK 1.1, you'll need to use a Swing version more recent than 1.0.2.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ShortCutKeys extends JApplet
{
JButton button;
JCheckBox checkBox;
JMenuBar menuBar;
JMenu fileMenu;
JMenuItem exitMenuItem;
JPanel panel;
public void init()
{
Container container = this.getContentPane();
Handler eventHandler = new Handler();
checkBox = new JCheckBox("Hello Mom!");
checkBox.setMnemonic(java.awt.event.KeyEvent.VK_M);
checkBox.addActionListener(eventHandler);
button = new JButton("Hello Dad!");
button.setMnemonic(java.awt.event.KeyEvent.VK_D);
button.addActionListener(eventHandler);
panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(checkBox);
panel.add(button);
exitMenuItem = new JMenuItem("Exit");
exitMenuItem.setMnemonic('x');
exitMenuItem.addActionListener(eventHandler);
fileMenu = new JMenu("File");
fileMenu.setMnemonic('f');
fileMenu.add(exitMenuItem);
menuBar = new JMenuBar();
menuBar.add(fileMenu);
container.add(menuBar, BorderLayout.NORTH);
container.add(panel, BorderLayout.CENTER);
}
class Handler implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == checkBox)
{
System.err.println("Action Performed on CHECKBOX");
}
else if (ae.getSource() == button)
{
System.err.println("Action Performed on BUTTON");
}
else if (ae.getSource() == exitMenuItem)
{
System.exit(0);
}
}
}
public static void main(String[] args)
{
JFrame frame = new JFrame("Short Cut Keys");
ShortCutKeys sck = new ShortCutKeys();
sck.init();
frame.getContentPane().add(sck);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{ System.exit(0); }
}
);
frame.setSize(300, 100);
frame.show();
}
}