Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Monday, 17 June 2013

Happy Father's Day


/**
 * @(#)HappyFathersDay.java
 *
 *
 * @author -> Anant Mahale
 * @version 1.00 2013/6/16
 */
import java.awt.*;
import java.awt.event.*;
class ButtonFrame extends Frame implements ActionListener
{
    private Button btn_press;
    public ButtonFrame()
    {
        setLayout(new FlowLayout());
       
        setTitle("Wish");
        setSize(500,500);
        setLocation(200,200);
       
        btn_press=new Button("Wish Your Father");
        btn_press.setForeground(Color.orange);
        btn_press.addActionListener(this);
        add(btn_press);
       
        addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent we)
            {
                System.exit(0);
            }
        });
    }
    public void actionPerformed(ActionEvent ae)
    {
        if(ae.getSource()==btn_press)
        {
            new dailog().setVisible(true);
        }
    }
}
class dailog extends  Dialog implements  ActionListener
{

    private Button btn_yes;
    private Panel north_panel,south_panel;
    public dailog()
    {
       
        super(new ButtonFrame(),"Dialog Demo",true);
        setBackground(Color.darkGray);
        south_panel=new Panel();
       
        setTitle("Father's Day Wishes");
        setSize(700,250);
        setLocation(50,80);
        btn_yes=new Button("Exit");
       
        south_panel.add(btn_yes);
        add(south_panel,"South");
        btn_yes.addActionListener(this);
    }
    public void paint(Graphics g)
    {
        g.setFont(new Font("MV Boli",Font.BOLD,30));
        g.setColor(Color.RED);
        g.drawString("Your guiding hand on my shoulder,",75,80);
        g.drawString("Will remain with me forever.,",75,110);
        g.drawString("Thanks for always being there Papa.",75,140);
        g.drawString("Happy Father’s Day!",75,170);
    }
    public void actionPerformed(ActionEvent ae)
    {
        if(ae.getSource()==btn_yes)
        {
            System.exit(0);
        }
    }
}
class HappyFathersDay
{
    public static void main(String args[])
    {
        new ButtonFrame().setVisible(true);
    }
}

Friday, 14 June 2013

program in java - simple button program in awt


import java.awt.*;
class MyFrame extends Frame
{
    private Button btn_east,btn_west,btn_south,btn_norht,btn_center;
    public MyFrame()
    {
        setTitle("My First Button Program");
        setSize(400,400);
        setResizable(false);
        setLocation(100,100);
        btn_east=new Button("East");
        btn_west=new Button("West");
        btn_norht=new Button("North");
        btn_south=new Button("South");
        btn_center=new Button("Center");
        add(btn_east,"East");
        add(btn_west,"West");
        add(btn_norht,"North");
        add(btn_south,"South");
        add(btn_center,"Center");
    }
}
class FirstButton
{
    public static void main(String []args)
    {
        new MyFrame().setVisible(true);
    }
}

program in java - button deamo


import java.awt.*;
import java.awt.event.*;
class MyButton extends Frame implements ActionListener
{
    private Button btn_yes,btn_no;
    public MyButton()
    {
        btn_yes=new Button("Yes");
        btn_no=new Button("No");
       
         FlowLayout f=new FlowLayout();
        setLayout(f);
       
        add(btn_yes);
        add(btn_no);
       
        setTitle("Button Demo");
        setSize(400,400);
        setLocation(100,100);
        btn_yes.addActionListener(this);
        btn_no.addActionListener(this);       
    }
    public void actionPerformed(ActionEvent ae)
    {
        String btn=ae.getActionCommand();
        if(btn.equals("Yes"))
            System.out.println("Yes Button is Clicked");
        else
            System.out.println("No Button is Clicked");
    }
}
class ButtonDemo
{
    public static void main(String args[])
    {
        new MyButton().setVisible(true);
    }
}

program in java swing - use button with swing and change background color while click on buttons


// wap in javat ot place 3 buttton red,green,blueto click red button to
//set the background of frameand so on.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class button extends JFrame implements ActionListener
{
    JButton b1,b2,b3;
    Container c=getContentPane();
    button()
    {
        c.setLayout(new FlowLayout());

        b1=new JButton("Red");
        b1.addActionListener(this);
        c.add(b1);

   
        b2=new JButton("Green");
        b2.addActionListener(this);
        c.add(b2);
       
        b3=new JButton("Blue");
        b3.addActionListener(this);
        c.add(b3);
    }
    public void actionPerformed(ActionEvent ae)
    {
        String str=ae.getActionCommand();
        if(str=="Red")
        {
            c.setBackground(Color.red);
        }
        if(str=="Green")
        {
            c.setBackground(Color.green);
        }
        if(str=="Blue")
        {
            c.setBackground(Color.blue);
        }
    }
    public static void main(String args[])
    {
        button b=new button();

        b.setTitle("Button");
        b.setSize(500,500);
        b.setVisible(true);

        b.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent we)
            {
                System.exit(0);
            }
        });
    }
}