请教高手实现下拉日历

hanfengthinker 2007-11-29 01:11:51
我有一个日历的JPanel了
想在JTable 或JCombobox里实现下拉日历
使得点击日期后将日期写在上面
...全文
202 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hanfengthinker 2007-12-01
  • 打赏
  • 举报
回复
那个是处来包吧哪里有下呀
Dead_Knight 2007-11-30
  • 打赏
  • 举报
回复
import mseries.Calendar.*;
import mseries.ui.*;
导入这两个包,然后调用对其中的日期控件类MDateEntryField进行封装即可
nj_dobetter 2007-11-29
  • 打赏
  • 举报
回复
OpenSwing里面有个现成的
marryhong 2007-11-29
  • 打赏
  • 举报
回复
JComboBox的

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

public class MyCity extends JFrame{
JComboBox cmbCity = new JComboBox();
JComboBox cmbTech = new JComboBox();
JPanel p = new JPanel();
JTextArea jta = new JTextArea();
JScrollPane jsp = new JScrollPane(jta);

Connection con;
Statement sta;
ResultSet res;
ResultSet res1;
ResultSet res2;


public MyCity() {
p.add(cmbCity);
p.add(cmbTech);
this.add(p,BorderLayout.NORTH);
this.add(jsp);

cityInit();
techInit(cmbCity.getSelectedItem().toString());

cmbCity.addActionListener(new AAA());
cmbTech.addActionListener(new AAA());

this.setSize(320,240);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}

public void cityInit(){
try{
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// con = DriverManager.getConnection("jdbc:odbc:wang","sa","");
// sta = con.createStatement(1005,1008);
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs",
"sa",
"");
Statement sta=con.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String s = "select * from City";
res = sta.executeQuery(s);
while(res.next()){
cmbCity.addItem(res.getString(2));
}
res.close();
sta.close();
con.close();
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}

public void jtaInit(String ss){
try{
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// con = DriverManager.getConnection("jdbc:odbc:wang","sa","");
// sta = con.createStatement(1005,1008);
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs",
"sa",
"");
Statement sta=con.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);

String s = "select * from Tech where tc='"+ss+"'";
res2 = sta.executeQuery(s);
while(res2.next()){
jta.setText(res2.getString(4));
}
res2.close();
sta.close();
con.close();
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}

public void techInit(String ss){
try{
int n=cmbTech.getItemCount();
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// con = DriverManager.getConnection("jdbc:odbc:wang","sa","");
// sta = con.createStatement(1005,1008);
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs",
"sa",
"");
Statement sta=con.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);

String s = "select * from Tech where Cid=(select Cid from City where City='"+ss+"')" ;
res1 = sta.executeQuery(s);
while(res1.next()){
cmbTech.addItem(res1.getString(3));
}
for(int i=0;i<n;i++){
cmbTech.removeItemAt(0);
}
res1.close();
sta.close();
con.close();
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}

public static void main(String[] args) {
new MyCity();
}

class AAA implements ActionListener{
public void actionPerformed(ActionEvent e){
Object obj = e.getSource();
if(obj==cmbCity){
techInit(cmbCity.getSelectedItem().toString());
}
else if(obj==cmbTech){
if(cmbTech.getSelectedItem().toString()==null){
}
else{
jtaInit(cmbTech.getSelectedItem().toString());
}
}
}
}
}
marryhong 2007-11-29
  • 打赏
  • 举报
回复
我这个是个联动的 和日历 好象同理

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

public class MyC extends JFrame implements MouseListener{
JList city = new JList();
JList tech = new JList();
JTextArea jta = new JTextArea();
JScrollPane jsp = new JScrollPane(jta);

String[] sCity;
String[] sTech;

Connection con;
Statement sta;
ResultSet res;
String sql;

public MyC() {
this.setLayout(new GridLayout(1,3));
this.add(city);
this.add(tech);
this.add(jsp);

city.setBorder(BorderFactory.createTitledBorder("请选择城市"));
tech.setBorder(BorderFactory.createTitledBorder("请选择特产"));
jsp.setBorder(BorderFactory.createTitledBorder("特产简介"));

cInit();
tInit(city.getSelectedValue().toString());

city.addMouseListener(this);
tech.addMouseListener(this);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(320,240);
this.setVisible(true);
}

public void cInit(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:myDB","sa","");
sta = con.createStatement(1005,1008);
sql = "select * from city";
res = sta.executeQuery(sql);

res.last();
int n = res.getRow();
sCity = new String[n];
res.first();
for(int i=0;i<n;i++){
sCity[i] = res.getString(2);
res.next();
}
city.setListData(sCity);
city.setSelectedIndex(0);
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}

public void tInit(String ss){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:myDB","sa","");
sta = con.createStatement(1005,1008);
sql = "select * from tech where cid=(select cid from city where city='"+ss+"')";
res = sta.executeQuery(sql);

res.last();
int n = res.getRow();
sTech = new String[n];
res.first();
for(int i=0;i<n;i++){
sTech[i] = res.getString(3);
res.next();
}
tech.setListData(sTech);
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}

public void jtaInit(String ss){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:myDB","sa","");
sta = con.createStatement(1005,1008);
sql = "select * from tech where tc='"+ss+"'";
res = sta.executeQuery(sql);

while(res.next()){
jta.setText(res.getString(4));
}
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}

public void mouseExited(MouseEvent e){

}

public void mouseEntered(MouseEvent e){

}

public void mouseClicked(MouseEvent e){
Object obj = e.getSource();
if(obj==city){
tInit(city.getSelectedValue().toString());
}else if(obj==tech){
jtaInit(tech.getSelectedValue().toString());
}
}

public void mouseReleased(MouseEvent e){

}

public void mousePressed(MouseEvent e){

}

public static void main(String[] args) {
new MyC();
}
}

方健的专栏 2007-11-29
  • 打赏
  • 举报
回复
java的日历控件很少见,顶一下,期待高手!

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧