Howto develop a basic swing application in Java

This is a bonus post developed for the Pentaho Reporting video course for Packt Publishing. In this post is shared how to develop a basic swing application in a Java Environment. Another similar post has been developed to share howto develop a basic web application in Java.

The video tutorials contained in this post have been developed with only text messages but the video course contains a voice over with a natural english and professional accent.

The focus of this post is on what is necessary as prerequisites of the mentioned video course but the content is definitely generic and could be usefull even in other cases and other scenarios. I hope this is usefull for many people as possibile. 🙂

Installing the basic softwares

In this video we are going to install the Oracle Java 7 (in particolar Java 7u25).

Last but not least let’s install Eclipse IDE for Java EE Developers (Kepler).

Defining a basic swing application

In this tutorial we are going to set up the development environment on Eclipse and create a new java project.

Below the written Java code:

JFrame frame = new JFrame("MyFirstSwingApp");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Press me!");

MouseListener mouseListener = new MouseAdapter()
{
 public void mousePressed(MouseEvent mouseEvent)
 {
  System.out.println("Left button pressed.");
 }
};
button.addMouseListener(mouseListener);
Container contentPane = frame.getContentPane();
contentPane.add(button, BorderLayout.SOUTH);

frame.setSize(300, 50);
frame.setVisible(true);

Conclusions

In this post is shared how to develop a basic swing application in a Java Environment. The focus is on what is necessary as prerequisites of the Pentaho Reporting video course but the content is definitely generic and could be usefull even in other cases and other scenarios. I hope this is usefull for many people as possibile. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.