![]() For building GUI applications at least one container class is necessary.įollowing are the three types of container classes: Container ClassĪny classwhich has other components in it is called as a container class. This is helpful because we do not have to start from the scratch. It becomes easier to build applications since we already have GUI components like button, checkbox etc. It is platform independent unlike AWT and has lightweight components. It is build on top of the AWT API and entirely written in java. It is a part of the JFC( Java Foundation Classes). Swing in Java is a lightweight GUI toolkit which has a wide variety of widgets for building optimized window based applications. ![]() Following are the concepts discussed in this article: In this article, we will go through the concepts involved in the process of building applications using swing in Java. ![]() Putting together all these components makes a graphical user interface. It includes components like button, scroll bar, text field etc. It is used for creating window based applications. When you create objects of other components like Buttons, TextFields, etc.Swing in java is part of Java foundation class which is lightweight and platform independent.While creating a frame (either by instantiating or extending Frame class), following two attributes are must for visibility of the frame:.Import the javax.swing and java.awt package to use the classes and methods of Swing.SetVisible(true) //setting frame visibility SetDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) //setting close operation. SetLayout(new FlowLayout()) //setting layout using FlowLayout object. JLabel lb = new JLabel("Welcome to My Second Window") //Creating a label named Welcome to My Second Window SetTitle("MyWindow") //setting title of frame as MyWindow Jf.setVisible(true) //setting frame visibilityĬreating JFrame window by extending JFrame class import javax.swing.* //importing swing package Jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) //setting close operation. Jf.setLayout(new FlowLayout()) //setting layout using FlowLayout object JButton btn = new JButton("Say Hello") //Creating a Button named Say Hello Jf = new JFrame("MyWindow") //Creating a JFrame with name MyWindow Import java.awt.* //importing awt package Import javax.swing.* //importing swing package There are two ways to create a JFrame Window.Ĭreating JFrame window by Instantiating JFrame class import javax.swing.* //importing swing package JTextField : JTextFields allow editing of a single line of text. JButton allows an icon, string or both associated with a button. JButton : JButton class provides the functioning of push button. ![]() JLabel : JLabel has descended from JComponent, and is used to create text labels. Like Window it uses BorderLayout by default. ![]() JWindow : This is Swing's version of Window and has descended directly from Window class. The component which is added to the Frame, is refered as its Content. JFrame : JFrame is Swing's version of Frame and is descended directly from Frame class. JPanel is descended directly from JComponent. JPanel : JPanel is Swing's version of AWT class Panel and uses the same default layout, FlowLayout. Java Swing is a part of Java Foundation Classes (JFC). JFC is an abbreviation for Java Foundation classes which encompass a group of features for building Graphical User Interfaces(GUI) and adding rich graphical functionalities and interactivity to Java applications. Swing classes are defined in javax.swing package and its sub-packages. It is used to create graphical user interface with Java. Swing library is an official Java GUI tool kit released by Sun Microsystems. Swing provides the look and feel of modern Java GUI. Java Swing is a GUI Framework that contains a set of classes to provide more powerful and flexible GUI components than AWT.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |