JButton with ActionListener and ActionEvent

Event Handling When the user clicks a button or perform any other interface related action in your application, an interface event occurs. Each components has a predefined set of events. When an event occurs in your application, the application notified and takes the appropriate action. Events are passed from source controls to Listener objects. That means … Read more…

JButton

The JButton class provides a rich set of features to of design highly user-friendly buttons.with initial text and an icon. Program       Program Source import javax.swing.JFrame; import javax.swing.JButton; import java.awt.FlowLayout; class Frame extends JFrame{ Frame() { setTitle(“JButton”); setLayout(new FlowLayout()); setButtons(); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setButtons() { JButton jb1 = new … Read more…

Multiple JLabel

This program uses a JFrame container to hold an instance of a multiple JLabel. The labels displays a multiple text message. Program       Program Source import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.FlowLayout; class Frame extends JFrame{ Frame() { setTitle(“Multiple JLabel”); setLayout(new FlowLayout()); setLabel(); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setLabel() { JLabel jl1 … Read more…

setToolTipText

setToolTipText() :  SpecifIc text will be displayed when the mouse will pass over Swing Components. Program       Program Source import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.FlowLayout; class Frame extends JFrame{ Frame() { setTitle(“setToolTipText”); setLayout(new FlowLayout()); setLabel(); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setLabel() { JLabel jl = new JLabel(“JLabel”); jl.setToolTipText(“This is JLabel”); add(jl); … Read more…

JLabel with ImageIcon

The swing icons are encapsulated by ImageIcon class. This class paints an image from the image. ImageIcon(String filename) Program       Program Source import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.ImageIcon; import java.awt.FlowLayout; class Frame extends JFrame{ Frame() { setTitle(“ImageIcon”); setLayout(new FlowLayout()); setLabel(); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setLabel() { ImageIcon icon = new … Read more…

JFrame with FlowLayout

The FlowLayout arrange the components from the upper left corner, left to right and top to bottom. When no more components fit on a line, the next one appears on the next line. A small space is left between every components on each side. Program        Program Source import javax.swing.JFrame; import javax.swing.JLabel; import … Read more…