How to Earn Money ADFLY

Monday 20 February 2017

Change Background Color Action Listener in java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Simple extends JFrame{

JButton bt;
JTextField tx;
public Simple(){

setBounds(0,0,600,400);//Set Bounds In JFrame
setTitle("Simple Java Program");
setLayout(null);
bt=new JButton("Submit");
bt.setBounds(150,100,100,30);
bt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent we){
getContentPane().setBackground(Color.yellow);

}});
tx=new JTextField();
tx.setBounds(150,50,200,30);


add(tx);
add(bt);
setVisible(true);
}
public static void main(String args[]){
JFrame f=new Simple();
}
}

No comments:

Post a Comment