Swing – JButton tutorial and example
JButton class is used for adding platform independent buttons to a swing application. In this tutorial we will learn how to create a button in Swing application and how to tweak their appearance as per the requirement. I have also shared some code snippets that may be useful for you while developing a Swing application.
Swing JButton Example
package swings;
import java.awt.event.*;
import javax.swing.*;
public class ButtonExample
{
public static void main(String[] args)
{
JFrame f=new JFrame("Button Example");
final JTextField tf=new JTextField();
tf.setBounds(50,50, 150,20);
JButton b=new JButton("Click Here");
b.setBounds(50,100,95,30);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tf.setText("Welcome to Java");
}
}
);
f.add(b);
f.add(tf);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
No program :( it shows only:
ReplyDeletepackage swings;
Sorry for inconvenience i will sort it ASAP
ReplyDelete