keymasterviriya1150

Untitled

Jan 21st, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. //Calendar
  2. import java.awt.*;
  3. import java.applet.*;
  4. import javax.swing.*;
  5. import java.util.GregorianCalendar;
  6. import java.util.Calendar;
  7. import java.util.Date;
  8. import java.awt.event.*;
  9.  
  10.  
  11. class GUI extends JFrame
  12. {
  13.     public static void main(String[]args)
  14.     {
  15.        
  16.             GUI f=new GUI();
  17.             JColorChooser color= new JColorChooser ( );
  18.             //color.setColor( Color.RED);
  19.             f.add(color);
  20.             f.setSize(350,80);
  21.             f.setResizable(false);
  22.             f.setVisible(true);
  23.             f.setLocation(420,350);
  24.    
  25.     }
  26.     GUI()
  27.     {
  28.         getContentPane().setBackground(new Color(54,54,54));
  29.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  30.         getContentPane().setLayout(null);
  31.        
  32.         // Text Field
  33.         Date date=new Date();
  34.         java.text.SimpleDateFormat d=new java.text.SimpleDateFormat("dd/MM/yyyy");
  35.         d.applyPattern("06/10/1995");
  36.        
  37.         JTextField txt = new JTextField(d.format(date));
  38.         txt.setForeground(Color.blue);
  39.         txt.setBounds(50,10,140,20);
  40.         getContentPane().add(txt);
  41.  
  42.         // Button
  43.         JButton btn1 = new JButton("Change");
  44.         btn1.setForeground(Color.green);
  45.         btn1.addActionListener(new ActionListener()
  46.             {
  47.                 public void actionPerformed(ActionEvent e)
  48.                 {
  49.                     GregorianCalendar g=new GregorianCalendar();
  50.                     txt.setText(g.get(Calendar.DATE)+"/"+(g.get(Calendar.MONTH)+1)+"/"+g.get(Calendar.YEAR));
  51.                 }
  52.         });
  53.         btn1.setBounds(200,10, 80, 20);
  54.         getContentPane().add(btn1);
  55.         //lable
  56.         final JLabel j = new JLabel("Date");
  57.         j.setForeground(Color.red);
  58.         j.setBounds(10, 10, 80, 20);
  59.         getContentPane().add(j);
  60.    
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment