Continuing with the Graphical aspects, now we were taught about Swings. Swing is built on the foundation of the AWT. It has lightweight components and a pluggable look and feel. A Swing GUI consists of two key items: components and containers. The main package is javax.swing. This package must be imported into any program that uses Swing. It the classes that implement the basic Swing components, such as push buttons, labels, and check boxes.
Example: demonstrating how to change font of JTextField's text using Java Swing JTextField class.
OUTPUT:-
Example: demonstrating how to change font of JTextField's text using Java Swing JTextField class.
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.JApplet;
import javax.swing.JTextField;
public class TextFieldTest extends JApplet{
public void init(){
this.getContentPane().setLayout(new FlowLayout());
JTextField field = new JTextField("JTextField Change Font",30);
Font font = new Font("Courier", Font.BOLD,12);
field.setFont(font);
add(field);
}
}
import java.awt.Font;
import javax.swing.JApplet;
import javax.swing.JTextField;
public class TextFieldTest extends JApplet{
public void init(){
this.getContentPane().setLayout(new FlowLayout());
JTextField field = new JTextField("JTextField Change Font",30);
Font font = new Font("Courier", Font.BOLD,12);
field.setFont(font);
add(field);
}
}
OUTPUT:-
No comments:
Post a Comment