我正在尝试使用此处的jDatePicker工具:sourceforge.net/projects/jdatepicker/files/latest/download我将.jar文件放在C:\ Program Files(x86)\ BlueJ \ lib中\ userlib并且已经在BlueJ首选项中被识别,但我不知道如何在我的项目中实际使用它。我尝试了各种各样的导入命令,但它没有尝试。有什么想法吗?
更新:好的,我现在已经开始编译,但applet没有运行,BlueJ只是说“Applet没有初始化”:
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);
}
}
答案 0 :(得分:0)
你需要告诉java在哪里找到这个库。您可以通过添加将库放入类路径的位置来执行此操作。
通常,您的IDE通过提供GUI来支持您执行此操作。 对于BlueJ,请看一下:http://www.bluej.org/faq.html#faq_How_do_I_use_custom_class_libraries__JARs__
答案 1 :(得分:0)
要导入Java文件中的其他类,需要添加一个带有类的完全限定名称的import语句(包含文件名)。
要导入JDatePicker
课程,您需要添加:
import org.jdatepicker.JDatePicker;
如果要导入包中的所有类,可以使用*
:
import org.jdatepicker.*;
类必须存在于Classpath中。当您在BlueJ\lib\userlib
文件夹中添加JAR文件时,这应该足以正确导入类。
您可能需要在其他包中导入其他类,如:
import org.jdatepicker.impl.*;
import org.jdatepicker.util.*;
根据需要导入所需的类或包。