1. Button Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "Button_Demo.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//****************************Start***********************
import javax.swing.*;
import java.awt.*;
public class Button_Demo extends JFrame {
JButton b1, b2;
public Button_Demo() {
Container c = getContentPane();
c.setLayout(new FlowLayout());
b1 = new JButton("Exit");
b2 = new JButton("Click");
c.add(b1);
c.add(b2);
// b1.setHorizontalAlignment(SwingConstants.LEFT);
// b2.setHorizontalAlignment(SwingConstants.RIGHT);
//b1.setHorizontalAlignment(SwingConstants.LEADING);
b1.setVerticalAlignment(SwingConstants.BOTTOM);
pack();
setVisible(true);
//b1.isVisible(false);
}
public static void main(String arsg[]) {
Button_Demo obj = new Button_Demo();
}
}
//***************************End*********************************
2. Combo Box Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "combobox.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//****************************Start*******************************
import javax.swing.*;
import java.awt.*;
public class combobox extends JFrame {
JComboBox c1;
public combobox() {
Container c = getContentPane();
c.setLayout(new FlowLayout());
String n[] = {"X", "Y", "z"};
c1 = new JComboBox(n);
c1.addItem("A");
c1.addItem("B");
c1.addItem("C");
c.add(c1);
pack();
setVisible(true);
}
public static void main(String arsg[]) {
combobox obj = new combobox();
}
}
Steps:
1.Copy program below in a text file.
2.Give File Name As "Button_Demo.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//****************************Start***********************
import javax.swing.*;
import java.awt.*;
public class Button_Demo extends JFrame {
JButton b1, b2;
public Button_Demo() {
Container c = getContentPane();
c.setLayout(new FlowLayout());
b1 = new JButton("Exit");
b2 = new JButton("Click");
c.add(b1);
c.add(b2);
// b1.setHorizontalAlignment(SwingConstants.LEFT);
// b2.setHorizontalAlignment(SwingConstants.RIGHT);
//b1.setHorizontalAlignment(SwingConstants.LEADING);
b1.setVerticalAlignment(SwingConstants.BOTTOM);
pack();
setVisible(true);
//b1.isVisible(false);
}
public static void main(String arsg[]) {
Button_Demo obj = new Button_Demo();
}
}
//***************************End*********************************
2. Combo Box Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "combobox.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//****************************Start*******************************
import javax.swing.*;
import java.awt.*;
public class combobox extends JFrame {
JComboBox c1;
public combobox() {
Container c = getContentPane();
c.setLayout(new FlowLayout());
String n[] = {"X", "Y", "z"};
c1 = new JComboBox(n);
c1.addItem("A");
c1.addItem("B");
c1.addItem("C");
c.add(c1);
pack();
setVisible(true);
}
public static void main(String arsg[]) {
combobox obj = new combobox();
}
}
//****************************End*******************************
3. Event Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "event.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//****************************Start*******************************
import java.awt.*;
import java.awt.event.*;
public class event extends Frame implements ActionListener {
Button b1, b2, b3;
Label l1;
public event() {
setLayout(new FlowLayout());
b1 = new Button("Ok");
b2 = new Button("Cancel");
b3 = new Button("Exit");
l1 = new Label();
l1.setPreferredSize(new Dimension(1000,1000));
add(b1);
add(b2);
add(b3);
add(l1);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
pack();
//setSize(400, 500);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b1)
{
l1.setText("You Clicked"+b1.getLabel());
}
else if(e.getSource()==b2)
{
l1.setText("You Clicked"+b2.getLabel());
}
else
{
System.exit(0);
}
}
public static void main(String arsg[]) {
event e = new event ();
}
}
//***************************End********************************
4. Grid Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "grid .java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//***************************Start*********************************
import java.awt.*;
public class grid extends Frame {
Button b1, b2, b3, b4,b5,b6;
public grid() {
setLayout(new GridLayout(3,2,5,5));
b1 = new Button("b1");
b2 = new Button("b2");
b3 = new Button("b3");
b4 = new Button("b4");
b5 = new Button("b5");
b6 = new Button("b6");
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
pack();
setVisible(true);
}
public static void main(String arsg[]) {
grid obj = new grid();
}
}
//*****************************End**********************************
5. Check Box Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jcheckbox.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*****************************Start***********************************
import javax.swing.*;
import java.awt.*;
public class jcheckbox extends JFrame
{
JCheckBox c1,c2,c3;
public jcheckbox()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
c1=new JCheckBox();
c2=new JCheckBox("A");
c3=new JCheckBox("B",true);
c.add(c1);
c.add(c2);
c.add(c3);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args)
{
jcheckbox ch=new jcheckbox();
}
}
//******************************End**********************************
6. Editor Pane Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jeditorpane.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//******************************Start*********************************
import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;
public class jeditorpane extends JFrame
{
JEditorPane e;
public jeditorpane()
{
try
{
e=new JEditorPane();
add(e);
pack();
setVisible(true);
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String[] args) {
jscrollpane jp= new jscrollpane();
}
}
//******************************End**********************************
7. Label Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jlabel.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*****************************Start**********************************
import javax.swing.*;
import java.awt.*;
public class jlabel extends JFrame
{
JLabel l1;
public jlabel()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
l1=new JLabel("Label is used to print the message");
c.add(l1);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
jlabel jl =new jlabel();
}
}
//*****************************End***********************************
8. Panel Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jpanel.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*****************************Start***********************************
import javax.swing.*;
import java.awt.*;
public class jpanel {
JPanel jp1,jp2;
public jpanel()
{
jp1=new JPanel();
jp2=new JPanel(new FlowLayout());
}
public static void main(String[] args) {
jpanel aw=new jpanel();
}
}
3. Event Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "event.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
import java.awt.*;
import java.awt.event.*;
public class event extends Frame implements ActionListener {
Button b1, b2, b3;
Label l1;
public event() {
setLayout(new FlowLayout());
b1 = new Button("Ok");
b2 = new Button("Cancel");
b3 = new Button("Exit");
l1 = new Label();
l1.setPreferredSize(new Dimension(1000,1000));
add(b1);
add(b2);
add(b3);
add(l1);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
pack();
//setSize(400, 500);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b1)
{
l1.setText("You Clicked"+b1.getLabel());
}
else if(e.getSource()==b2)
{
l1.setText("You Clicked"+b2.getLabel());
}
else
{
System.exit(0);
}
}
public static void main(String arsg[]) {
event e = new event ();
}
}
//***************************End********************************
4. Grid Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "grid .java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//***************************Start*********************************
import java.awt.*;
public class grid extends Frame {
Button b1, b2, b3, b4,b5,b6;
public grid() {
setLayout(new GridLayout(3,2,5,5));
b1 = new Button("b1");
b2 = new Button("b2");
b3 = new Button("b3");
b4 = new Button("b4");
b5 = new Button("b5");
b6 = new Button("b6");
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
pack();
setVisible(true);
}
public static void main(String arsg[]) {
grid obj = new grid();
}
}
//*****************************End**********************************
5. Check Box Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jcheckbox.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*****************************Start***********************************
import javax.swing.*;
import java.awt.*;
public class jcheckbox extends JFrame
{
JCheckBox c1,c2,c3;
public jcheckbox()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
c1=new JCheckBox();
c2=new JCheckBox("A");
c3=new JCheckBox("B",true);
c.add(c1);
c.add(c2);
c.add(c3);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args)
{
jcheckbox ch=new jcheckbox();
}
}
6. Editor Pane Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jeditorpane.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//******************************Start*********************************
import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;
public class jeditorpane extends JFrame
{
JEditorPane e;
public jeditorpane()
{
try
{
e=new JEditorPane();
add(e);
pack();
setVisible(true);
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String[] args) {
jscrollpane jp= new jscrollpane();
}
}
//******************************End**********************************
7. Label Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jlabel.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
import javax.swing.*;
import java.awt.*;
public class jlabel extends JFrame
{
JLabel l1;
public jlabel()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
l1=new JLabel("Label is used to print the message");
c.add(l1);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
jlabel jl =new jlabel();
}
}
//*****************************End***********************************
8. Panel Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jpanel.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*****************************Start***********************************
import javax.swing.*;
import java.awt.*;
public class jpanel {
JPanel jp1,jp2;
public jpanel()
{
jp1=new JPanel();
jp2=new JPanel(new FlowLayout());
}
public static void main(String[] args) {
jpanel aw=new jpanel();
}
}
//****************************End*************************************
No comments:
Post a Comment
Welcome, happy learning