如何将 jDatePicker 导入 BlueJ Java 程序?
How can I import jDatePicker into a BlueJ Java program?
我正在尝试使用此处的 jDatePicker 工具:sourceforge.net/projects/jdatepicker/files/latest/download 并将 .jar 文件放在 C:\Program Files (x86)\BlueJ\lib\userlib 中在 BlueJ 首选项中得到认可,但我不知道如何在我的项目中实际使用它。我已经尝试了各种导入命令,但没有成功。有什么想法吗?
更新:好的,我现在可以编译了,但是小程序没有 运行,BlueJ 只是说 "Applet not initialised":
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);
}
}
您需要告诉 java 图书馆在哪里。您可以通过添加将库放入类路径的位置来完成此操作。
通常,您的 IDE 通过提供 GUI 来支持您完成此过程。
对于 BlueJ,请看这里:http://www.bluej.org/faq.html#faq_How_do_I_use_custom_class_libraries__JARs__
要在您的 Java 文件中导入其他 classes,您需要使用 class 的完整限定名称(包中的文件名)添加导入语句.
要导入 JDatePicker
class,您需要添加:
import org.jdatepicker.JDatePicker;
如果要导入一个包中的所有classes,可以使用*
:
import org.jdatepicker.*;
classes 必须存在于类路径中。当您在 BlueJ\lib\userlib
文件夹中添加 JAR 文件时,这应该足以正确导入 classes。
您可能需要在其他包中导入其他 classes,例如:
import org.jdatepicker.impl.*;
import org.jdatepicker.util.*;
根据需要导入所需的 classes 或包。
我正在尝试使用此处的 jDatePicker 工具:sourceforge.net/projects/jdatepicker/files/latest/download 并将 .jar 文件放在 C:\Program Files (x86)\BlueJ\lib\userlib 中在 BlueJ 首选项中得到认可,但我不知道如何在我的项目中实际使用它。我已经尝试了各种导入命令,但没有成功。有什么想法吗?
更新:好的,我现在可以编译了,但是小程序没有 运行,BlueJ 只是说 "Applet not initialised":
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);
}
}
您需要告诉 java 图书馆在哪里。您可以通过添加将库放入类路径的位置来完成此操作。
通常,您的 IDE 通过提供 GUI 来支持您完成此过程。 对于 BlueJ,请看这里:http://www.bluej.org/faq.html#faq_How_do_I_use_custom_class_libraries__JARs__
要在您的 Java 文件中导入其他 classes,您需要使用 class 的完整限定名称(包中的文件名)添加导入语句.
要导入 JDatePicker
class,您需要添加:
import org.jdatepicker.JDatePicker;
如果要导入一个包中的所有classes,可以使用*
:
import org.jdatepicker.*;
classes 必须存在于类路径中。当您在 BlueJ\lib\userlib
文件夹中添加 JAR 文件时,这应该足以正确导入 classes。
您可能需要在其他包中导入其他 classes,例如:
import org.jdatepicker.impl.*;
import org.jdatepicker.util.*;
根据需要导入所需的 classes 或包。