Skip to main content

jbutton Click Event example Advance Java

Jbutton Click Event example Advance Java 

Change frame Color On Button click Advance Java 






import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
    
class FrameDemo extends JFrame implements ActionListener
{
     
JButton btn;

Container c;
        
FrameDemo()
{              
c=this.getContentPane();
       JButton btn= new JButton("Click");
btn.setBounds(100,50,100,50);
        c.add(btn);
        c.setLayout(null);
       btn.addActionListener(this);
}
                  
public void actionPerformed(ActionEvent a)
                  
c.setBackground(Color.RED);
}
}
       // creating a class ActionDemo (step 2 )
class ActionDemo
{
public static void main( String args[])
{
                // Creating object of FrameDemo class ( Step 5 )
FrameDemo f=new FrameDemo();
f.setTitle("click Event ");
f.setVisible(true);
f.setBounds(100,50,700,500);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Labels

Show more

Popular posts from this blog

Jframe Form Designing sample

Advance JAva-Jframe Form Designing sample Code import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.Color; public class Sample extends JFrame  { public Sample() {     setTitle("Home");      getContentPane().setBackground(Color.orange);       setSize(300,200);      setLayout(null);         setDefaultCloseOperation(EXIT_ON_CLOSE);      setLocation(100, 100);              JLabel l0=new JLabel("Registration");        l0.setBounds(10,0,100,20);   add(l0);  JLabel l1=new JLabel("Enter Name");  l1.setBounds(30,20,100,20);  add(l1);      JTextField textFieldUserName = new JTextField(50);     textFieldUserName.setBounds(110,20,60,20);     ...

Java Program to update record using JFrame and Prepaired Statement

Java Program to update record using JFrame and Prepaired Statement Java Program to edit record using JFrame and Prepaired Statement Here is table Design  Create table demo using two column as id  and Dname , id is primary key  Program source code  import javax.swing.*;   import java.awt.event.*;   import java.sql.*; public class FrameUpdate extends JFrame implements ActionListener{       JTextField tf1,tf2,tf3;       JButton b1,b2;   JLabel l1,l2; Connection con;    PreparedStatement psmt;   int result; //declaration of control   FrameUpdate(){           JFrame f= new JFrame("UpdateDemo");   // l1=new JLabel("Enter RollNo"); l1.setBounds(150,10,150,50);         tf1=new JTextField();           tf1.setBounds(150,50,150,20);   ...