Question
JAVA Swing Form Example JAVA swing form example shows how to create a form using Eclipse. This article will focus on creation of form having
JAVA Swing Form Example
JAVA swing form example shows how to create a form using Eclipse.
This article will focus on creation of form having components such as TextBox, TextArea, Label, RadioButton, Button, CheckBox etc. and also how to handle events if generated by a particular component.
2.1. Setup
Prerequisite:
This example is developed on Eclipse therefore a compatible Eclipse IDE is required to be installed on the system.
We also need WindowBuilder tool to be installed on Eclipse IDE for the easiness of the work. Following Steps are required to install the WindowBuilder tool.
- Go to Eclipse Help Install New Software
Installing WindowBuilder Tool
- Select your version of eclipse version/download/eclipse.org/release/eclipse version, For example, Mars http://download.eclipse.org/releases/mars
- Select General purpose tools from the dropdown and click next.
Installing WindowBuilder Tool
This will take some time to install the software, restart eclipse in order to see the changes.
2.2 Java Swing Form
Create a new JAVA project lets say swing_1
- Go to src right click New Other WindowBuilder select Swing Designer Application Window
JAVA Swing Form
JAVA Swing Form
Enter the name of the application(eg. JAVASwingFormExample) and click finish.
This will create JAVASwingFormExample.java file and will provide Source and Design tab.
3 Code
Source file will look like this. Basically, a Frame is being created here.
JAVASwingFormExample.java
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | package swing_1;
import java.awt.EventQueue;
import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JButton; import java.awt.Color; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JRadioButton; import javax.swing.JToggleButton; import javax.swing.JScrollBar; import javax.swing.JComboBox; import javax.swing.JCheckBox;
public class JAVASwingFormExample{
private JFrame frame; private JTextField textField; private JTextField textField_1; private JTextField textField_2;
/** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { JAVASwingFormExample window = new JAVASwingFormExample(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }
/** * Create the application. */ public JAVASwingFormExample() { initialize(); }
/** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 730, 489); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null);
}
} |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started