JSpinner with ChangeListener

A jspinner generates an event of type ChangeEvent when an item is selected that is sent to listeners of type ChangeListener. Both types are defined in the javax.swing.event package. To obtain the current value of the jspinner, call getValue( ). It returns the current setting. Program       Progarm Source import javax.swing.JFrame; import javax.swing.JSpinner; … Read more…

JRadioButton(Another Example)

setIcon( ) method possible to change the icon inside a JButton during program execution. Program       Program Source import javax.swing.JFrame; import javax.swing.JRadioButton; import javax.swing.JButton; import javax.swing.ImageIcon; import java.awt.FlowLayout; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; class Frame extends JFrame implements ItemListener{ private JButton jb; private JRadioButton jr1,jr2,jr3,jr4; private ImageIcon icon; Frame() { setTitle(“Vehicle Selection”); setLayout(new FlowLayout()); … Read more…

JButton with setRolloverIcon

setRolloverIcon() you can define different icons that are displayed for the button when it is disabled, pressed, or selected. Another icon can be used as a rollover icon, which is displayed when the mouse is positioned over a button. Program       Program Source import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.ImageIcon; import java.awt.FlowLayout; class Frame extends JFrame … Read more…

JButton with Icon

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.JButton; import javax.swing.ImageIcon; import java.awt.FlowLayout; class Frame extends JFrame { Frame() { setTitle(“JButton with Icon”); setLayout(new FlowLayout()); setButtons(); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setButtons() { JButton … 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…

Simple Ranking Application with JOptionPane showOptionDialog

Program       Program Source import javax.swing.JOptionPane; import javax.swing.ImageIcon; public class Javaapp { public static void main(String[] args) { int var1=0,var2=0,var3=0; ImageIcon icon = new ImageIcon(“WLive48x48.png”); String players[]={“Sachin Tendulkar”,”Sehwag”,”Dhoni”}; while(true) { int optionReturns = JOptionPane.showOptionDialog(null ,”Who is the best Indian cricket player?” ,”Player Ranking” ,JOptionPane.NO_OPTION ,JOptionPane.PLAIN_MESSAGE ,icon ,players ,”Sachin Tendulkar”); if(optionReturns == 0) var1++; … Read more…