【发布时间】:2015-02-18 12:33:50
【问题描述】:
我正在尝试从这里使用 jDatePicker 工具:sourceforge.net/projects/jdatepicker/files/latest/download,我已将 .jar 文件放在 C:\Program Files (x86)\BlueJ\lib \userlib 并且它已在 BlueJ 首选项中得到认可,但我不知道如何在我的项目中实际使用它。我尝试了各种导入命令,但没有成功。有什么想法吗?
更新:好的,我现在可以编译它,但是小程序没有运行,BlueJ 只是说“小程序没有初始化”:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.util.*;
import java.util.Calendar;
import java.util.Date;
import net.sourceforge.jdatepicker.*;
import net.sourceforge.jdatepicker.impl.*;
import net.sourceforge.jdatepicker.util.*;
public class Task1 extends java.applet.Applet implements ActionListener
{
public void init()
{
setLayout(null);
setSize(200,240);
JButton btnConfirm=new JButton("Confirm"); //initalises the button
btnConfirm.setBounds(15,2,100,20);
add(btnConfirm); //paints it on the screen
btnConfirm.addActionListener(this);
TextField text = new TextField(20);
text.setBounds(5,24,185,20);
add(text);
UtilDateModel model = new UtilDateModel();
JDatePanelImpl datePanel = new JDatePanelImpl(model);
JDatePickerImpl datePicker = new JDatePickerImpl(datePanel);
datePicker.setBounds(50,80,185,20);
add(datePicker);
}
/* Use the method actionPerformed to trap the event button clicked */
public void actionPerformed(ActionEvent evt)
{
JOptionPane.showMessageDialog(null,"ALERT MESSAGE","TITLE",JOptionPane.WARNING_MESSAGE);
}
}
【问题讨论】:
-
import org.jdatepicker.JDatePicker;但是 jar 文件需要存在于类路径中。 -
好的,blueJ 似乎已经意识到了这一点,但是当我开始关注本教程 codejava.net/java-se/swing/… 时,以下行不起作用,因为它说它找不到这 3 个的符号类: UtilDateModel 模型 = 新 UtilDateModel(); JDatePanelImpl datePanel = new JDatePanelImpl(model); JDatePickerImpl datePicker = new JDatePickerImpl(datePanel);即使尝试 import org.jdatepicker.*
-
这些类在其他包中,你也需要导入这些包中的类。查看我的答案了解更多详情。