Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


k murali
datepick
2 Answer(s)      4 years and 8 months ago
Posted in : Java Beginners


sir,when i am click on a submit button the datepicker is appeared sir

Advertisement
View Answers

April 22, 2010 at 11:15 AM


Hi Friend,

We have modified your code.

import java.awt.*;
import java.text.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.util.*;
import java.sql.*;

class DatePicker {
JButton[] button = new JButton[49];
int month = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH);
int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR);;
JLabel l = new JLabel("",JLabel.CENTER);
String day = "";
JDialog d;
public DatePicker(JFrame parent) {
d = new JDialog();
d.setModal(true);
String[] header = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"};
JPanel p1 = new JPanel(new GridLayout(7,7));
p1.setPreferredSize(new Dimension(430,120));
for(int x = 0; x < button.length; x++){
final int selection = x;
button[x] = new JButton();
button[x].setFocusPainted(false);
if(x>6)button[x].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
day = button[selection].getActionCommand();
d.dispose();}});
if(x < 7){
button[x].setText(header[x]);
}
p1.add(button[x]);
}
JPanel p2 = new JPanel(new GridLayout(1,3));
JButton previous = new JButton("<< Previous");
previous.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
month--;
setDates();}});
p2.add(previous);
p2.add(l);
JButton next = new JButton("Next >>");
next.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
month++;setDates();}});
p2.add(next);
d.add(p1,BorderLayout.CENTER);
d.add(p2,BorderLayout.SOUTH);
d.pack();
d.setLocationRelativeTo(parent);
setDates();
d.setVisible(true);
}
public void setDates(){
for(int x = 7; x < button.length; x++) button[x].setText("");
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MMMM yyyy");
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(year,month,1);
int dayOfWeek = cal.get(java.util.Calendar.DAY_OF_WEEK);
int daysInMonth = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
for(int x = 6+dayOfWeek,day = 1; day <= daysInMonth; x++,day++) button[x].setText(""+day);
l.setText(sdf.format(cal.getTime()));
d.setTitle("Date Picker");
}
public String displayDatePicked() {
if(day.equals("")) return day;
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy");
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(year,month,Integer.parseInt(day));
return sdf.format(cal.getTime());
}
}
public class DailySales extends JPanel{
static final int CURRENTDATE_COLUMN_INDEX=0;
static final int CNAME_COLUMN_INDEX=1;
static final int TID_COLUMN_INDEX=2;
static final int CITY_COLUMN_INDEX=3;
static final int TOTALAMOUNT_COLUMN_INDEX=4;
JScrollPane scrollPane;
JTable table;
Vector columnNames ;
Vector data ;
JPanel p=new JPanel();
String mon=null;
DefaultTableModel model;
int columns;
ResultSet rs,rs1,rs2;
ResultSetMetaData md ;
JPanel mainPanel;
JLabel titleLabel,totalramountLabel,totaliamountLabel,dateLabel;
JTextField totalramountField,dateField,totaliamountField;
JButton submit;
String qa;
String amttotal;
String issuedamttotal,receivedamttotal;
JPanel jp=new JPanel();


April 22, 2010 at 11:15 AM


continue..

public DailySales(){
p.setLayout(null);
Font labelFont=new Font("timesroman",Font.BOLD,20);
setSize(1024,618);
setLayout(null);
mainPanel=new JPanel();
mainPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
mainPanel.setSize(1024,100);
totaliamountLabel=new JLabel("Total Issued Amt",JLabel.CENTER);
totaliamountLabel.setFont(new Font("timesroman",Font.BOLD,15));
totaliamountLabel.setBounds(100,310,300,30);
add(totaliamountLabel);
totalramountLabel=new JLabel("Total Received Amount",JLabel.CENTER);
totalramountLabel.setFont(new Font("timesroman",Font.BOLD,15));
totalramountLabel.setBounds(350,310,300,30);
add(totalramountLabel);
totaliamountField=new JTextField();
totaliamountField.setBounds(310,310,100,30);
add(totaliamountField);
totalramountField=new JTextField();
totalramountField.setBounds(650,310,100,30);
add(totalramountField);
dateField=new JTextField();
add(dateField);

titleLabel=new JLabel("DailyTransactions",JLabel.CENTER);
titleLabel.setFont(new Font("timesroman",Font.BOLD,20));
add(titleLabel);

dateLabel=new JLabel("Transactions On:",JLabel.CENTER);
dateLabel.setFont(new Font("timesroman",Font.BOLD,14));
add(dateLabel);

titleLabel.setBounds(373,40,278,36);
dateLabel.setBounds(345,80,120,30);
dateField.setBounds(465,80,120,30);

System.out.println("date ....................:");
submit=new JButton("SUBMIT");
add(submit);
submit.setBounds(600,80,90,30);
final JFrame f=new JFrame();
f.add(this);
f.setVisible(true);
f.setSize(1024,618);
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
dateField.setText(new DatePicker(f).displayDatePicked());
}
});
}
public static void main(String[]args){
DailySales s=new DailySales();
}
}

Thanks


Related Tutorials/Questions & Answers:
jquery popup datepicker
() { $('#popupDatepicker').datepick(); }); </script> </head> <
Advertisements
How to automatically change the value of the textbox based on the dropdown list?
() { $('#popupDatepicker').datepick({dateFormat: 'yyyy-mm-dd'}); $('#inlineDatepicker').datepick({onSelect: showDate}); }); function showDate(date) { alert
jQuery UI Widget : Datepicker
; $(function() { $('#popupDatepicker').datepick
Sending emails and insert into trable
into booking set vehiType='$vehitype', datePick='$pdate',timePick='$ptime
 

 

 

DMCA.com