Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
SWING: Swing library is an official Java GUI toolkit released by Sun Microsystems. It is used to create Graphical user interfaces with Java. The main characteristics of the Swing toolkit platform independent configurable lightweight The Swing API has 18 public packages: javax.accessibility javax.swing.tree javax.swing.undo Swing is an advanced GUI toolkit. It has a rich set of widgets. From basic widgets like buttons, labels, scrollbars to advanced widgets like trees and tables. Swing itself is written in Java. Swing is a part of JFC, Java Foundation Classes. It is a collection of packages for creating full featured desktop applications. JFC consists of AWT, Swing, Accessibility, Java 2D, and Drag and Drop. Swing was released in 1997 with JDK 1.2. It is a mature toolkit. The Java platform has Java2D library, which enables developers to create advanced 2D graphics and imaging. There are basically two types of widget toolkits. Lightweight Heavyweight There is also another GUI library for the Java programming language. It is called SWT. The Standard widget toolkit. The SWT library was initially developed by the IBM corporation. Now it is an open source project maintained by the Eclipse community. The SWT is an example of a heavyweight toolkit. It lets the underlying OS to create GUI. SWT uses the java native interface to do the job. Swing Packages javax.swing The high level swing package primarily consists of components, adapters, default component models and interfaces for all the delegates and models. javax.swing.border The border package declares the Border interface and classes, which define specific border rendering styles. javax.swing.plaf The plaf package contains the Pluggable Look-and-Feel API for developers interested in defining custom interfaces. javax.swing.table The table package contains the interfaces and classes, which support the Swing table component. javax.swing.text The text package contains the support classes for the Swing document framework. javax.swing.text.html The text.html package contains the support classes for a basic HTML renderer. javax.swing.undo The undo package provides the support classes for implementing undo/redo capabilities in a GUI. javax.accessibility The JFC Accessibility package is included with Swing and available for testing. Widgets This section describes how to use the various Swing widgets. Part of the component hierarchy looks similar to AWT. here are over double the number of components in Swing than in AWT. This second set of components is what most appeals to developers, as it provides a much richer set of widgets to use. Program Calculator Program Applet import import import import javax.swing.*; java.awt.event.*; java.awt.FlowLayout; java.awt.BorderLayout; public class CalcProgram extends JFrame implements ActionListener { JTextField num1 = new JTextField("0.00"); JTextField num2 = new JTextField("0.00"); JLabel answer = new JLabel("0.00"); JLabel symbol = new JLabel("+"); JLabel equals = new JLabel("="); JButton addButton = new JButton(" + "); JButton subButton = new JButton(" - "); public CalcProgram() { JPanel fields = new JPanel(new FlowLayout()); fields.add(num1); fields.add(symbol); fields.add(num2); fields.add(equals); fields.add(answer); JPanel buttons = new JPanel(new FlowLayout()); buttons.add(addButton); buttons.add(subButton); getContentPane().setLayout(new BorderLayout()); getContentPane().add("North", fields); getContentPane().add("Center", buttons); addButton.addActionListener(this); subButton.addActionListener(this); pack(); setVisible(true); } public void actionPerformed(ActionEvent e) { double x = Double.parseDouble(num1.getText()); double Double.parseDouble(num2.getText()); if (e.getSource() == addButton) { answer.setText(String.valueOf( x + y )); symbol.setText("+"); } if (e.getSource() == subButton) { answer.setText(String.valueOf( x - y )); symbol.setText("-"); } } public static void main(String args[]) { CalcProgram c = new CalcProgram(); } } y =