Where to write Swing Code – First Swing Application

In this chapter you will learn:

1. Where to Write Swing Code?
2. How to Use Eclipse to Develop Swing
3. Your First Swing Application

Where to Write Swing Code?

As you know Swing and Java is platform independent so you can write Swing Code on simple text editor as notepad but I strongly recommend you to use Advanced Java Editor like NetBeans, VSCode, DrJava or Eclipse. These tools make your job easier, provides extra information of components and give auto intelligence on your code. Debugging and Execution of Swing Codes are also very easy.

How to Use Eclipse to Develop Swing?

There is no extra science and swing looks like a simple java class.

Step 1 : Launch Eclipse

 

Step 2 : Go to File > New > JavaProject. Create New Java Project SwingApps

New Project
New Project
 

Step 3: Right click on your project name SwingApps > New > Package. Create Package Test.MainJava.com

Create Package
Create Package
 

Step 4: Right Click on Package Test.MainJava.com > New > Class. Give class name FirstApp.java and click Ok.

New Class
New Class
 

Now your Package Explorer looks like this. If Package Explorer not appearing select it from Window > Show View > Package Explorer.

Package ExplorerPackage Explorer
 

Write Swing Code in FirstApp.Java Class

Paste the following code in FirstApp.Java class and run your program.

Output

output

Summary

This is simple program in Swing which lets you understand basic swing programming. By doing this first swing project now, you know how to use eclipse IDE for developing swing project. In the next chapter you will learn various swing components, their uses and connectivity with database.


Leave a Reply

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