keymasterviriya1150

Untitled

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