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.
SwingApps> New > Package. Create Package
Test.MainJava.com> New > Class. Give class name
FirstApp.javaand click Ok.
Write Swing Code in FirstApp.Java Class
Paste the following code in FirstApp.Java class and run your program.
public class FirstApp
public static void main(String args)
JFrame f=new JFrame();//creating instance of JFrame
JButton b=new JButton("Click Me");//creating instance of JButton
b.setBounds(140,100,120, 40);//x axis, y axis, width, height
f.add(b);//adding button in JFrame
f.setSize(400,500);//400 width and 500 height
f.setLayout(null);//using no layout managers
f.setVisible(true);//making the frame visible
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.