{"id":38963,"date":"2016-07-06T11:00:03","date_gmt":"2016-07-06T08:00:03","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=38963"},"modified":"2016-07-05T10:51:55","modified_gmt":"2016-07-05T07:51:55","slug":"create-gui-java","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/","title":{"rendered":"How to Create GUI in JAVA"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>There are two sets of Java APIs for graphics programming: AWT (Abstract Windowing Toolkit) and Swing.<br \/>\n<b>1.<\/b> <code>AWT<\/code> API was introduced in JDK 1.0. Most of the <code>AWT<\/code> components have become obsolete and should be replaced by newer Swing components.<br \/>\n<b>2.<\/b> Swing API, a much more comprehensive set of graphics libraries that enhances the AWT, was introduced as part of Java Foundation Classes (JFC) after the release of JDK 1.1. JFC consists of Swing, Java2D, Accessibility, Internationalization, and Pluggable Look-and-Feel Support APIs. JFC was an add-on to JDK 1.1 but has been integrated into core Java since JDK 1.2.<\/p>\n<p>Other than AWT\/Swing Graphics APIs provided in JDK, others have also provided Graphics APIs that work with Java, such as Eclipse&#8217;s Standard Widget Toolkit (SWT) (used in Eclipse), Google Web Toolkit (GWT) (used in Android), 3D Graphics API such as Java bindings for OpenGL (JOGL) and Java3D.<\/p>\n<h2>2 GUI Creation<\/h2>\n<p>In this example we will learn how to create a GUI using eclipse in JAVA.<\/p>\n<h3>2.1 Setup<\/h3>\n<p><b> Prerequisite: <\/b><br \/>\nThis example is developed on Eclipse therefore a compatible Eclipse IDE is required to be installed on the system.<\/p>\n<p>We also need WindowBuilder tool to be installed on Eclipse IDE for the easiness of the work.<br \/>\nFollowing Steps are required to install the WindowBuilder tool.<\/p>\n<ul>\n<li>Go to Eclipse \u2192Help\u2192 Install New Software\n<p><figure id=\"attachment_37938\" aria-describedby=\"caption-attachment-37938\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/Screenshot-2-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-37938\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/Screenshot-2-1.jpg\" alt=\"Installing WindowBuilder Tool\" width=\"860\" height=\"678\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/Screenshot-2-1.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/Screenshot-2-1-300x237.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/Screenshot-2-1-768x605.jpg 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-37938\" class=\"wp-caption-text\">Installing WindowBuilder Tool<\/figcaption><\/figure><\/li>\n<li>Select your version of eclipse version\/download\/eclipse.org\/release\/eclipse version, <b> For example, Mars \u2013 http:\/\/download.eclipse.org\/releases\/mars<\/b><\/li>\n<li>Select <b>General purpose tools<\/b> from the dropdown and click next.\n<p><figure id=\"attachment_38965\" aria-describedby=\"caption-attachment-38965\" style=\"width: 857px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-38965\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G1.jpg\" alt=\"Installing WindowBuilder Tool\" width=\"857\" height=\"671\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G1.jpg 857w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G1-300x235.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G1-768x601.jpg 768w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><\/a><figcaption id=\"caption-attachment-38965\" class=\"wp-caption-text\">Installing WindowBuilder Tool<\/figcaption><\/figure><\/li>\n<\/ul>\n<p>This will take some time to install the software, so you have to restart eclipse in order to see the changes.<\/p>\n<h3>2.2 Programming GUI with AWT<\/h3>\n<p>Java Graphics APIs &#8211; AWT and Swing &#8211; provide a huge set of reusable GUI components, such as button, text field, label, choice, panel and frame for building GUI applications. You can simply reuse these classes rather than re-invent the wheels. I shall start with the <code>AWT<\/code> classes before moving into Swing to give you a complete picture. I have to stress that <code>AWT<\/code> component classes are now obsoleted by Swing&#8217;s counterparts.<\/p>\n<h4>2.2.1 AWT Packages<\/h4>\n<p>AWT is huge! It consists of 12 packages (Swing is even bigger, with 18 packages as of JDK 1.8). Fortunately, only 2 packages &#8211; java.awt and java.awt.event &#8211; are commonly-used.<br \/>\n1.The java.awt package contains the core AWT graphics classes:<\/p>\n<ul>\n<li>GUI Component classes (such as Button, TextField, and Label),<\/li>\n<li>GUI Container classes (such as Frame, Panel, Dialog and ScrollPane),<\/li>\n<li>Layout managers (such as FlowLayout, BorderLayout and GridLayout),<\/li>\n<li>Custom graphics classes (such as Graphics, Color and Font).<\/li>\n<\/ul>\n<p>2.The java.awt.event package supports event handling:<\/p>\n<ul>\n<li>Event classes (such as ActionEvent, MouseEvent, KeyEvent and WindowEvent),<\/li>\n<li>Event Listener Interfaces (such as ActionListener, MouseListener, KeyListener and WindowListener),<\/li>\n<li>Event Listener Adapter classes (such as MouseAdapter, KeyAdapter, and WindowAdapter).<\/li>\n<\/ul>\n<p>AWT provides a platform-independent and device-independent interface to develop graphic programs that runs on all platforms, such as Windows, Mac, and Linux.<\/p>\n<h4>2.2.2 Containers and Components<\/h4>\n<p>There are two types of GUI elements:<br \/>\n1. Component: Components are elementary GUI entities (such as Button, Label, and TextField.)<br \/>\n2. Container: Containers (such as Frame and Panel) are used to hold components in a specific layout (such as flow or grid). A container can also hold sub-containers.<\/p>\n<p>GUI components are also called controls (Microsoft ActiveX Control), widgets (Eclipse&#8217;s Standard Widget Toolkit, Google Web Toolkit), which allow users to interact with (or control) the application through these components (such as button-click and text-entry).<\/p>\n<p>A Frame is the top-level container of an AWT program. A Frame has a title bar (containing an icon, a title, and the minimize\/maximize\/close buttons), an optional menu bar and the content display area. A Panel is a rectangular area used to group related GUI components in a certain layout. In the above figure, the top-level Frame contains two Panels. There are five components: a Label (providing description), a TextField (for users to enter text), and three Buttons (for user to trigger certain programmed actions).<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>In a GUI program, a component must be kept in a container. You need to identify a container to hold the components. Every container has a method called add(Component c). A container (say aContainer) can invoke aContainer.add(aComponent) to add aComponent into itself. For example,<br \/>\n<span style=\"text-decoration: underline;\"><em>MyGUIProgram.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">Panel panel = new Panel();        \/\/ Panel is a Container\r\nButton btn = new Button(\"Press\"); \/\/ Button is a Component\r\npanel.add(btn);                   \/\/ The Panel Container adds a Button Component\r\n\r\n<\/pre>\n<h4>2.2.2 AWT Container Classes<\/h4>\n<p><b> Top-Level Containers: Frame, Dialog and Applet <\/b><br \/>\nEach GUI program has a top-level container. The commonly-used top-level containers in AWT are Frame, Dialog and Applet:<\/p>\n<ul>\n<ul>\n<li>A Frame provides the &#8220;main window&#8221; for the GUI application, which has a title bar (containing an icon, a title, the minimize, maximize\/restore-down and close buttons), an optional menu bar, and the content display area. To write a GUI program, we typically start with a subclass extending from <code>java.awt.Frame<\/code> to inherit the main window as follows:<\/li>\n<\/ul>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><em>MyGUIProgram.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">import java.awt.Frame;  \/\/ Using Frame class in package java.awt\r\n\r\n\/\/ A GUI program is written as a subclass of Frame - the top-level container\r\n\/\/ This subclass inherits all properties from Frame, e.g., title, icon, buttons, content-pane\r\npublic class MyGUIProgram extends Frame {\r\n \r\n   \/\/ Constructor to setup the GUI components\r\n   public MyGUIProgram() { ...... }\r\n\r\n   \/\/ Other methods\r\n   ......\r\n   ......\r\n\r\n   \/\/ The entry main() method\r\n   public static void main(String[] args) {\r\n      \/\/ Invoke the constructor (to setup the GUI) by allocating an instance\r\n      new MyGUIProgram();\r\n   }\r\n}\r\n\r\n<\/pre>\n<ul>\n<li>An AWT Dialog is a &#8220;pop-up window&#8221; used for interacting with the users. A Dialog has a title-bar (containing an icon, a title and a close button) and a content display area, as illustrated.<\/li>\n<li>An AWT Applet (in package java.applet) is the top-level container for an applet, which is a Java program running inside a browser. Applet will be discussed in the later chapter.<\/li>\n<\/ul>\n<p><b>Secondary Containers: Panel and ScrollPane <\/b><br \/>\nSecondary containers are placed inside a top-level container or another secondary container. AWT also provide these secondary containers:<\/p>\n<ul>\n<ul>\n<li>Panel: a rectangular box under a higher-level container, used to layout a set of related GUI components in pattern such as grid or flow.<\/li>\n<li>ScrollPane: provides automatic horizontal and\/or vertical scrolling for a single child component.<\/li>\n<\/ul>\n<\/ul>\n<h4>2.2.2 AWT Component Classes<\/h4>\n<p>AWT provides many ready-made and reusable GUI components. The frequently-used are: Button, TextField, Label, Checkbox, CheckboxGroup (radio buttons), List, and Choice, as illustrated below.<\/p>\n<p><b>AWT GUI Component:java.awt.Label <\/b><br \/>\nA <code>java.awt.Label<\/code> provides a text description message. Take note that System.out.println() prints to the system console, not to the graphics screen. You could use a Label to label another component (such as text field) or provide a text description.<\/p>\n<p>Check the JDK API specification for java.awt.Label.<\/p>\n<p>Below is how a label will look like:<\/p>\n<p><figure id=\"attachment_38989\" aria-describedby=\"caption-attachment-38989\" style=\"width: 852px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-38989\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G2.jpg\" alt=\"Inserting a Label\" width=\"852\" height=\"691\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G2.jpg 852w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G2-300x243.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G2-768x623.jpg 768w\" sizes=\"(max-width: 852px) 100vw, 852px\" \/><\/a><figcaption id=\"caption-attachment-38989\" class=\"wp-caption-text\">Inserting a Label<\/figcaption><\/figure><\/p>\n<p><b>Constructors <\/b><\/p>\n<ul>\n<ul>\n<ul>\n<li>public Label(String strLabel, int alignment); \/\/ Construct a Label with the given text String, of the text alignment<\/li>\n<li>public Label(String strLabel); \/\/ Construct a Label with the given text String<\/li>\n<li>public Label(); \/\/ Construct an initially empty Label<\/li>\n<\/ul>\n<\/ul>\n<\/ul>\n<p>The Label class has three constructors:<br \/>\n1.The first constructor constructs a Label object with the given text string in the given alignment. Note that three static constants <code>Label.LEFT<\/code>, <code>Label.RIGHT<\/code>, and <code>Label.CENTER<\/code> are defined in the class for you to specify the alignment (rather than asking you to memorize arbitrary integer values).<br \/>\n2.The second constructor constructs a Label object with the given text string in default of left-aligned.<br \/>\n3.The third constructor constructs a Label object with an initially empty string. You could set the label text via the <code>setText() <\/code> method later.<\/p>\n<p><b>Constructing a Component and Adding the Component into a Container<\/b><br \/>\nThree steps are necessary to create and place a GUI component:<br \/>\n1.Declare the component with an identifier (name);<br \/>\n2.Construct the component by invoking an appropriate constructor via the new operator;<br \/>\n3.Identify the container (such as Frame or Panel) designed to hold this component. The container can then add this component onto itself via aContainer.add(aComponent) method. Every container has an add(Component) method. Take note that it is the container that actively and explicitly adds a component onto itself, instead of the other way.<\/p>\n<p>Below is the code to add a label(component) to a frame(container)<\/p>\n<p><span style=\"text-decoration: underline;\"><em>MyGUIProgram.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">        JLabel lblName = new JLabel(\"Name\");\r\n\t\tlblName.setBounds(93, 67, 46, 14);\r\n\t\tframe.getContentPane().add(lblName);\r\n<\/pre>\n<p><b>AWT GUI Component: java.awt.Button <\/b><\/p>\n<p>A <code>java.awt.Button<\/code> is a GUI component that triggers a certain programmed action upon clicking.<br \/>\n<b>Constructors<\/b><br \/>\npublic Button(String buttonLabel);<br \/>\n\/\/ Construct a Button with the given label<br \/>\npublic Button();<br \/>\n\/\/ Construct a Button with empty label<br \/>\nThe Button class has two constructors. The first constructor creates a Button object with the given label painted over the button. The second constructor creates a Button object with no label.<\/p>\n<p>Here is how button will look like:<\/p>\n<p><figure id=\"attachment_38994\" aria-describedby=\"caption-attachment-38994\" style=\"width: 855px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G3.jpg\"><img decoding=\"async\" class=\"size-full wp-image-38994\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G3.jpg\" alt=\"Insertion of a button\" width=\"855\" height=\"685\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G3.jpg 855w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G3-300x240.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G3-768x615.jpg 768w\" sizes=\"(max-width: 855px) 100vw, 855px\" \/><\/a><figcaption id=\"caption-attachment-38994\" class=\"wp-caption-text\">Insertion of a button<\/figcaption><\/figure><\/p>\n<p>clicking of a button generates an event. code for adding a button is described below :<br \/>\n<span style=\"text-decoration: underline;\"><em>MyGUIProgram.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">JButton btnSubmit = new JButton(\"Submit\");\r\n\t\t    btnSubmit.addActionListener(new ActionListener() {\r\n\t\t\tpublic void actionPerformed(ActionEvent arg0) {\r\n\t\t\t\tJOptionPane.showMessageDialog(null, \"Data Submitted\");\r\n\t\t\t}\r\n\t\t});\r\n\t\tbtnSubmit.setBounds(93, 121, 89, 23);\r\n\t\tframe.getContentPane().add(btnSubmit);\r\n\r\n<\/pre>\n<p><b> AWT GUI Component: java.awt.TextField <\/b><br \/>\nA <code>java.awt.TextField<\/code> is single-line text box for users to enter texts. (There is a multiple-line text box called TextArea.) Hitting the &#8220;ENTER&#8221; key on a TextField object triggers an action-event.<\/p>\n<p><b>Constructors<\/b><br \/>\npublic TextField(String strInitialText, int columns);<br \/>\n\/\/ Construct a TextField instance with the given initial text string with the number of columns.<br \/>\npublic TextField(String strInitialText);<br \/>\n\/\/ Construct a TextField instance with the given initial text string.<br \/>\npublic TextField(int columns);<br \/>\n\/\/ Construct a TextField instance with the number of columns.<\/p>\n<p>Below is how a TextField will look like :<\/p>\n<p><figure id=\"attachment_38997\" aria-describedby=\"caption-attachment-38997\" style=\"width: 856px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G4.jpg\"><img decoding=\"async\" class=\"size-full wp-image-38997\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G4.jpg\" alt=\"Inserting a TextField\" width=\"856\" height=\"693\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G4.jpg 856w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G4-300x243.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/G4-768x622.jpg 768w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><figcaption id=\"caption-attachment-38997\" class=\"wp-caption-text\">Inserting a TextField<\/figcaption><\/figure><\/p>\n<h2>3. AWT Event-Handling<\/h2>\n<p>Java adopts the so-called &#8220;Event-Driven&#8221; (or &#8220;Event-Delegation&#8221;) programming model for event-handling, similar to most of the visual programming languages (such as Visual Basic and Delphi).<\/p>\n<p>In event-driven programming, a piece of event-handling codes is executed (or called back by the graphics subsystem) when an event has been fired in response to an user input (such as clicking a mouse button or hitting the ENTER key). This is unlike the procedural model, where codes are executed in a sequential manner.<\/p>\n<p>The AWT&#8217;s event-handling classes are kept in package <code>java.awt.event<\/code>.<\/p>\n<p>Three objects are involved in the event-handling: a source, listener(s) and an event object.<\/p>\n<p>The source object (such as Button and Textfield) interacts with the user. Upon triggered, it creates an event object. This event object will be messaged to all the registered listener object(s), and an appropriate event-handler method of the listener(s) is called-back to provide the response. In other words, triggering a source fires an event to all its listener(s), and invoke an appropriate handler of the listener(s).<\/p>\n<p>The sequence of steps is illustrated above:<\/p>\n<ul>\n<li>The source object registers its listener(s) for a certain type of event.<br \/>\nSource object fires event event upon triggered. For example, clicking an Button fires an ActionEvent, mouse-click fires MouseEvent, key-type fires KeyEvent, etc.<\/li>\n<\/ul>\n<p>How the source and listener understand each other? The answer is via an agreed-upon interface. For example, if a source is capable of firing an event called XxxEvent (e.g., MouseEvent) involving various operational modes (e.g., mouse-clicked, mouse-entered, mouse-exited, mouse-pressed, and mouse-released). Firstly, we need to declare an interface called XxxListener (e.g., MouseListener) containing the names of the handler methods. Recall that an interface contains only abstract methods without implementation<\/p>\n<p>Secondly, all the listeners interested in the XxxEvent must implement the XxxListener interface. That is, the listeners must provide their own implementations (i.e., programmed responses) to all the abstract methods declared in the XxxListener interface. In this way, the listenser(s) can response to these events appropriately.<\/p>\n<p>Thirdly, in the source, we need to maintain a list of listener object(s), and define two methods: addXxxListener() and removeXxxListener() to add and remove a listener from this list.<\/p>\n<p>Take note that all the listener(s) interested in the XxxEvent must implement the XxxListener interface. That is, they are sub-type of the XxxListener. Hence, they can be upcasted to XxxListener and passed as the argument of the above methods.<\/p>\n<p>In summary, we identify the source, the event-listener interface, and the listener object. The listener must implement the event-listener interface. The source object then registers listener object via the addXxxListener() method<\/p>\n<ul>\n<li>The source is triggered by a user.<\/li>\n<li>The source create an XxxEvent object, which encapsulates the necessary information about the activation. For example, the (x, y) position of the mouse pointer, the text entered, etc.<\/li>\n<li>Finally, for each of the listeners in the listener list, the source invokes the appropriate handler on the listener(s), which provides the programmed response.<\/li>\n<\/ul>\n<h2>4. Download<\/h2>\n<p>This was an example of How to create a GUI in JAVA.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/MyGUIProgram.zip\"><strong>MyGUIProgram<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction There are two sets of Java APIs for graphics programming: AWT (Abstract Windowing Toolkit) and Swing. 1. AWT API was introduced in JDK 1.0. Most of the AWT components have become obsolete and should be replaced by newer Swing components. 2. Swing API, a much more comprehensive set of graphics libraries that enhances &hellip;<\/p>\n","protected":false},"author":98,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[],"class_list":["post-38963","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-swing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Create GUI in JAVA - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction There are two sets of Java APIs for graphics programming: AWT (Abstract Windowing Toolkit) and Swing. 1. AWT API was introduced in JDK\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create GUI in JAVA - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction There are two sets of Java APIs for graphics programming: AWT (Abstract Windowing Toolkit) and Swing. 1. AWT API was introduced in JDK\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/jyoti.jha.9256\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-06T08:00:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jyoti Jha\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jyoti Jha\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/\"},\"author\":{\"name\":\"Jyoti Jha\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7dcd033e37def0d21806e891845d89b7\"},\"headline\":\"How to Create GUI in JAVA\",\"datePublished\":\"2016-07-06T08:00:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/\"},\"wordCount\":1999,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"articleSection\":[\"swing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/\",\"name\":\"How to Create GUI in JAVA - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2016-07-06T08:00:03+00:00\",\"description\":\"1. Introduction There are two sets of Java APIs for graphics programming: AWT (Abstract Windowing Toolkit) and Swing. 1. AWT API was introduced in JDK\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Desktop Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"swing\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to Create GUI in JAVA\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7dcd033e37def0d21806e891845d89b7\",\"name\":\"Jyoti Jha\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/Jyoti-Jha-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/Jyoti-Jha-96x96.jpg\",\"caption\":\"Jyoti Jha\"},\"description\":\"Jyoti is a tech enthusiast and is an avid programmer. She holds a post graduation degree in (M.Tech) Computer Science Engineering from Thapar Univeristy, Patiala, India. Post her graduate studies, she has worked in Software companies such as SLK Software and Aricent, India as Software Engineer in various projects primarily in the field of Requirement analysis and design, implementing new algorithms in C++ and JAVA used in ISDN network and designing databases and. She is inquisitive about socio economic reforms as well as advancement in technical fronts and keep herself informed with TED talks and various blogs.\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\/\",\"https:\/\/www.facebook.com\/jyoti.jha.9256\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/jyoti-jha\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create GUI in JAVA - Java Code Geeks","description":"1. Introduction There are two sets of Java APIs for graphics programming: AWT (Abstract Windowing Toolkit) and Swing. 1. AWT API was introduced in JDK","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/","og_locale":"en_US","og_type":"article","og_title":"How to Create GUI in JAVA - Java Code Geeks","og_description":"1. Introduction There are two sets of Java APIs for graphics programming: AWT (Abstract Windowing Toolkit) and Swing. 1. AWT API was introduced in JDK","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/jyoti.jha.9256","article_published_time":"2016-07-06T08:00:03+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Jyoti Jha","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Jyoti Jha","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/"},"author":{"name":"Jyoti Jha","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7dcd033e37def0d21806e891845d89b7"},"headline":"How to Create GUI in JAVA","datePublished":"2016-07-06T08:00:03+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/"},"wordCount":1999,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","articleSection":["swing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/","name":"How to Create GUI in JAVA - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2016-07-06T08:00:03+00:00","description":"1. Introduction There are two sets of Java APIs for graphics programming: AWT (Abstract Windowing Toolkit) and Swing. 1. AWT API was introduced in JDK","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/create-gui-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Desktop Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/"},{"@type":"ListItem","position":4,"name":"swing","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/"},{"@type":"ListItem","position":5,"name":"How to Create GUI in JAVA"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7dcd033e37def0d21806e891845d89b7","name":"Jyoti Jha","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/Jyoti-Jha-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/Jyoti-Jha-96x96.jpg","caption":"Jyoti Jha"},"description":"Jyoti is a tech enthusiast and is an avid programmer. She holds a post graduation degree in (M.Tech) Computer Science Engineering from Thapar Univeristy, Patiala, India. Post her graduate studies, she has worked in Software companies such as SLK Software and Aricent, India as Software Engineer in various projects primarily in the field of Requirement analysis and design, implementing new algorithms in C++ and JAVA used in ISDN network and designing databases and. She is inquisitive about socio economic reforms as well as advancement in technical fronts and keep herself informed with TED talks and various blogs.","sameAs":["https:\/\/www.javacodegeeks.com\/","https:\/\/www.facebook.com\/jyoti.jha.9256"],"url":"https:\/\/examples.javacodegeeks.com\/author\/jyoti-jha\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/38963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/98"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=38963"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/38963\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=38963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=38963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=38963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}