Adding image to JFrame

There is no specialized image component provided in Swing (which is sad in my opinion). So, there are a few options: As @Reimeus said: Use a JLabel with an icon. Create in the window builder a JPanel, that will represent the location of the image. Then add your own custom image component to the JPanel … Read more

How to programmatically close a JFrame

If you want the GUI to behave as if you clicked the X close button then you need to dispatch a window closing event to the Window. The ExitAction from Closing An Application allows you to add this functionality to a menu item or any component that uses Actions easily.

the getSource() and getActionCommand()

Assuming you are talking about the ActionEvent class, then there is a big difference between the two methods. getActionCommand() gives you a String representing the action command. The value is component specific; for a JButton you have the option to set the value with setActionCommand(String command) but for a JTextField if you don’t set this, … Read more

setMnemonic() and call a method by pressing the key

It’s worth reading here about Oracle Tutorial – Enabling Keyboard Operation where it is explained in details along with sample. Read more about on Oracle Tutorial – How to Use Key Bindings Some example directly from the above tutorial: Read more here Oracle Tutorial – How to Use Buttons, Check Boxes, and Radio Buttons Sample … Read more