jwxjava的简单介绍

博主:adminadmin 2022-12-26 03:00:20 69

本篇文章给大家谈谈jwxjava,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java怎么往excel写数据

public void export(ListPSbLnode li, String dateString,String[] title) throws WriteException, IOException {

// 准备设置excel工作表的标题

// 创建Excel工作薄

WritableWorkbook wwb = null;

try {

// 输出的excel的路径

String filePath1 = Const.pathStr+Const.pathStr4+Const.pathStr3;

File file = new File(filePath1);

if(!file.exists()){

file.mkdir();

}

String filePath=filePath1+Const.pathStr4+Const.pathStr6+dateString+Const.pathStr5;

// 新建立一个jxl文件,即在C盘下生成testJXL.xls

OutputStream os = new FileOutputStream(filePath);

wwb = Workbook.createWorkbook(os);

// 添加第一个工作表并设置第一个Sheet的名字

WritableSheet sheet = wwb.createSheet("设备清单", 0);

Label label;

for (int i = 0; i title.length; i++) {

// Label(x,y,z) 代表单元格的第x+1列,第y+1行, 内容z

// 在Label对象的子对象中指明单元格的位置和内容

label = new Label(i, 0, title[i]);

// 将定义好的单元格添加到工作表中

sheet.addCell(label);

}

for (int i = 0; i li.size(); i++) {

int j = 0;

j = i + 1;

//填充单元格

//获取区域名称

label = new Label(0, j, li.get(i).getQyName());

sheet.addCell(label);

//获取区域名称

label = new Label(1, j, li.get(i).getJzName());

sheet.addCell(label);

//获取设备名称

label = new Label(2, j, li.get(i).getLnodeName());

sheet.addCell(label);

// //获取设备类型名称

label = new Label(3, j, li.get(i).getSbxh());

sheet.addCell(label);

//获取运行状态

label = new Label(4, j, li.get(i).getYxzh());

sheet.addCell(label);

//获取删除状态

label = new Label(5, j, li.get(i).getDeleteFlag());

sheet.addCell(label);

//获取启用状态

label = new Label(6, j, li.get(i).getQyzt());

sheet.addCell(label);

//获取设备投运日期

label = new Label(7, j, li.get(i).getSbtyri());

sheet.addCell(label);

//获取使用年限

jxl.write.Number numb1 = new jxl.write.Number(8, j, li.get(i).getSynx());

sheet.addCell(numb1);

//获取区域名称

label = new Label(9, j, li.get(i).getAddUser());

sheet.addCell(label);

//获取区域名称

label = new Label(10, j, li.get(i).getUpdUser());

sheet.addCell(label);

//获取区域名称

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

String newdate = sdf.format(li.get(i).getUpdTime());

label = new Label(11, j, newdate);

sheet.addCell(label);

//获取区域名称

SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");

String newdate2 = sdf2.format(li.get(i).getAddTime());

label = new Label(12, j, newdate2);

sheet.addCell(label);

//获取区域名称

label = new Label(13, j, li.get(i).getZcbh());

sheet.addCell(label);

//获取区域名称

label = new Label(14, j, li.get(i).getSbcs());

sheet.addCell(label);

//获取区域名称

jxl.write.Number numb2 = new jxl.write.Number(15, j, li.get(i)

.getSbll());

sheet.addCell(numb2);

//获取区域名称

label = new Label(16, j, li.get(i).getRldw());

sheet.addCell(label);

//获取区域名称

label = new Label(17, j, li.get(i).getWxghjl());

sheet.addCell(label);

}

// 写入数据

wwb.write();

} catch (Exception e) {

e.printStackTrace();

}finally{

// 关闭文件

wwb.close();

}

}

Const文件:

/**路径:C盘*/

public static String pathStr = "C:";

/**路径://*/

public static String pathStr2 = "//";

/**文件夹:workspace*/

public static String pathStr3 = "exportFile";

/**文件名:world*/

public static String pathStr6 = "Equipment";

/**路径:/*/

public static String pathStr4 = "/";

/**路径:.xls*/

public static String pathStr5 = ".xls";

java中setContentPane()的问题

代码能编译通过,不知道你编译时出现什么错误?

GridBagConstraints.EAST,GridBagConstraints.NONE这两个属性值

赋给GridBagConstraints.anchor、fill表示当控件大小比显示区域小时,控件显示位置GridBagConstraints.EAST表示水平靠右,垂直居中,GridBagConstraints.NONE表示对显示区域与控件之间的空白区域不把控件拉伸来填充。

请教大家一个java的编程问题。

//LMS.java

//所有类写在一个文件内,请将以下内容保存成 LMS.java,编译运行即可,GUI版

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.FlowLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.ArrayList;

import java.util.List;

import javax.swing.BorderFactory;

import javax.swing.Box;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTextField;

import javax.swing.UIManager;

import javax.swing.border.Border;

public class LMS {

public static void main(String[] args){

try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}catch(Exception e){}

new LibraryGUI(new Library()).setVisible(true);

}

}

//书籍类

class Book implements ComparableBook{

private String name;//书名

private String publisher;//出版社

private Author au;//作者

private String sn;//书号

public Book(String name,String sn,String publisher,Author au){

this.name=name;this.sn=sn;this.publisher=publisher;this.au=au;

}

public String getName(){ return name; }

public String getPublisher(){ return publisher; }

public String getSerialNumber(){ return sn; }

public Author getAuthor(){ return au; }

public boolean equals(Object o){ return o instanceof Book ((Book)o).sn.equals(sn); }

public String toString(){ return "书名:"+name+" 书号:"+sn+" 作者:"+au+" 出版社:"+publisher; }

//排序优先顺序:书名,作者,出版社,书号是唯一的,所以不作排序项目

public int compareTo(Book b) {

if(b.name.equals(name))

if(b.au.equals(au))

return b.publisher.compareTo(this.publisher);

else return b.au.getName().compareTo(au.getName());

else return b.name.compareTo(name);

}

}

//作者类

class Author{

private String name;

private String phone;

private String addr;

public Author(String name,String phone,String addr){

this.name=name;this.phone=phone;this.addr=addr;

}

public String getName(){ return name; }

public String getPhone(){ return phone; }

public String getAddr(){ return addr; }

public String getFullInfo(){ return "Name:"+name+" Phone:"+phone+" Addr:"+addr; }

public String toString(){ return name; }

}

//图书库类

class Library{

//存放书籍的容器

private ListBook lib = new ArrayListBook();

//加入图书

public void addBook(Book b){ lib.add(b); }

//删除图书

public void removeBook(Book b){ lib.remove(b); }

//取得全部图书

public ListBook getAllBooks(){ return lib; }

//根据条件查询图书,书名模糊查找,书号和作者精确查找

public ListBook query(String bookName, String bookSN, String bookAu) {

ListBook tmp = new ArrayListBook();

if(bookName.isEmpty())

for(int i=0; ilib.size(); i++)

tmp.add(lib.get(i));

else

for(int i=0; ilib.size(); i++)

if(lib.get(i).getName().indexOf(bookName)-1)

tmp.add(lib.get(i));

if(!bookSN.isEmpty())

for(int i=0; itmp.size(); i++)

if(! (tmp.get(i).getSerialNumber().equals(bookSN))){

tmp.remove(i);

--i;

}

if(!bookAu.isEmpty())

for(int i=0; itmp.size(); i++)

if(!(tmp.get(i).getAuthor().getName().equals(bookAu))){

tmp.remove(i);

--i;

}

return tmp;

}

}

//GUI部分

class LibraryGUI extends JFrame implements ActionListener{

private JTextField bname,bpub,bsn,bauname,bauaddr,bauphone;

private JTextField qbname,qbsn,qauname;

private JPanel north,addp,add1,add2,quep,disp,mainp;

private JButton addb,queb,del;

private Library lib;

private JScrollPane jsp;

private Box box;

LibraryGUI(Library lib){

super("图书XX系统");

this.lib=lib;

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().setLayout(new BorderLayout());

this.setSize(740,600);

this.setLocationRelativeTo(null);

//新增面板

addp=new JPanel(new GridLayout(2,1));

add1=new JPanel(new FlowLayout(FlowLayout.LEFT));

add2=new JPanel(new FlowLayout(FlowLayout.LEFT));

addp.add(add1);addp.add(add2);

addp.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10,10,10,10),BorderFactory.createLineBorder(Color.LIGHT_GRAY)));

JLabel l;

l=new JLabel("书名:");

add1.add(l);

bname=new JTextField(16);

add1.add(bname);

l=new JLabel(" 书号:");

add1.add(l);

bsn=new JTextField(20);

add1.add(bsn);

l=new JLabel(" 出版社:");

add1.add(l);

bpub=new JTextField(30);

add1.add(bpub);

l=new JLabel("作者:");

add2.add(l);

bauname=new JTextField(16);

add2.add(bauname);

l=new JLabel(" 电话:");

add2.add(l);

bauphone=new JTextField(20);

add2.add(bauphone);

l=new JLabel(" 住址:");

add2.add(l);

bauaddr=new JTextField(46);

add2.add(bauaddr);

add1.add(new JLabel(" "));

addb=new JButton(" 新 增 ");

add1.add(addb);

addb.addActionListener(this);

//查询面板

quep=new JPanel(new FlowLayout(FlowLayout.LEFT));

quep.setBorder(addp.getBorder());

l=new JLabel("书名:");

quep.add(l);

qbname=new JTextField(16);

quep.add(qbname);

l=new JLabel(" 书号:");

quep.add(l);

qbsn=new JTextField(20);

quep.add(qbsn);

l=new JLabel(" 作者:");

quep.add(l);

qauname=new JTextField(16);

quep.add(qauname);

quep.add(new JLabel(" "));

queb=new JButton(" 查 询 ");

quep.add(queb);

queb.addActionListener(this);

del=new JButton(" 删 除 ");

quep.add(del);

del.addActionListener(this);

//

north=new JPanel(new BorderLayout());

north.add(addp,BorderLayout.NORTH);

north.add(quep,BorderLayout.SOUTH);

this.getContentPane().add(north,BorderLayout.NORTH);

//显示面板

disp=new JPanel(new BorderLayout());

disp.setBorder(addp.getBorder());

this.getContentPane().add(disp);

mainp=new JPanel(new BorderLayout());

mainp.setBackground(Color.white);

box=Box.createVerticalBox();

mainp.add(box,BorderLayout.NORTH);

jsp=new JScrollPane(mainp,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

disp.add(jsp);

}

public void actionPerformed(ActionEvent e) {

if(e.getSource()==addb)

createNewBook();

else if(e.getSource()==queb)

queryBook();

else if(e.getSource()==del)

removeBook();

}

private void removeBook() {

String bn=qbname.getText().trim();

String bsn=qbsn.getText().trim();

String baun=qauname.getText().trim();

if(bn.isEmpty()bsn.isEmpty()baun.isEmpty())

return;

ListBook bks = lib.query(bn,bsn,baun);

for(int i=0; ibks.size(); i++)

lib.removeBook(bks.get(i));

display(lib.getAllBooks());

}

private void queryBook() {

String bn=qbname.getText().trim();

String bsn=qbsn.getText().trim();

String baun=qauname.getText().trim();

display(lib.query(bn,bsn,baun));

}

private void createNewBook() {

Author au = new Author(bauname.getText().trim(),bauphone.getText().trim(),bauaddr.getText().trim());

Book bk = new Book(bname.getText().trim(),bsn.getText().trim(),bpub.getText().trim(),au);

lib.addBook(bk);

display(lib.getAllBooks());

}

private void display(ListBook bks){

box.removeAll();

for(int i=0; ibks.size(); i++){

Book b = bks.get(i);

System.out.println(b);

BookItem bi = new BookItem(b);

bi.setBackground(i%2==0?Color.white:new Color(0xefefef));

box.add(bi);

}

jsp.validate();

}

}

class BookItem extends JPanel{

private static Border border=BorderFactory.createCompoundBorder(

BorderFactory.createMatteBorder(0,0,1,0,Color.LIGHT_GRAY),

BorderFactory.createEmptyBorder(0,5,5,5));

BookItem(Book b){

this.setBorder(border);

this.setLayout(new FlowLayout(FlowLayout.LEFT));

String str="htmltabletr style='color:gray;'" +

"td width=168书名: font color=#000"+b.getName()+"/font/td" +

"td width=188书号:font color=#000"+b.getSerialNumber()+"/font/td" +

"td width=138作者:font color=#000"+b.getAuthor()+"/font/td" +

"td出版社:font color=#000"+b.getPublisher()+"/font/td" +

"/tr/table";

this.add(new JLabel(str));

}

}

java打包后双击可以运行吗

现在的windows都会装j2se的解析器的,所以这就是说,如果打包成jar文件,用这个j2se解析器打开就可以双击运行。**********************下面是jar包的打包方法************************1.建立MANIFEST.MF (在class文件根目录下) 以下内容为文件的基本内容 ================== Manifest-Version: 1.0 Main-Class: a(主类的路径) Created-By: Abc Company (创建人名字) ================== 2.打包 按照lz给的条件 在class文件目录下执行 jar cvfm classes.jar MANIFEST.MF *.* 以上命令将class下所有文件打包到classes.jar,生成在class目录下 3.执行 windows下双击就可以执行。-----------------------------------这个是我推荐的方案,因为简单。**************************MANIFEST.MF 文件详解**************************打开Java的JAR文件我们经常可以看到文件中包含着一个META-INF目录,这个目录下会有一些文件,其中必有一个MANIFEST.MF,这个文件描述了该Jar文件的很多信息,下面将详细介绍MANIFEST.MF文件的内容,先来看struts.jar中包含的MANIFEST.MF文件内容: Manifest-Version: 1.0Created-By: Apache Ant 1.5.1Extension-Name: Struts FrameworkSpecification-Title: Struts FrameworkSpecification-Vendor: Apache Software FoundationSpecification-Version: 1.1Implementation-Title: Struts FrameworkImplementation-Vendor: Apache Software FoundationImplementation-Vendor-Id: org.apacheImplementation-Version: 1.1Class-Path: commons-beanutils.jar commons-collections.jar commons-digester.jar commons-logging.jar commons-validator.jar jakarta-oro.jar struts-legacy.jar如果我们把MANIFEST中的配置信息进行分类,可以归纳出下面几个大类:一. 一般属性1. Manifest-Version 用来定义manifest文件的版本,例如:Manifest-Version: 1.02. Created-By 声明该文件的生成者,一般该属性是由jar命令行工具生成的,例如:Created-By: Apache Ant 1.5.13. Signature-Version 定义jar文件的签名版本4. Class-Path 应用程序或者类装载器使用该值来构建内部的类搜索路径二. 应用程序相关属性1. Main-Class 定义jar文件的入口类,该类必须是一个可执行的类,一旦定义了该属性即可通过 java -jar x.jar来运行该jar文件。 三. 小程序(Applet)相关属性1. Extendsion-List 该属性指定了小程序需要的扩展信息列表,列表中的每个名字对应以下的属性2. extension-Extension-Name3. extension-Specification-Version4. extension-Implementation-Version5. extension-Implementation-Vendor-Id5. extension-Implementation-URL四. 扩展标识属性1. Extension-Name 该属性定义了jar文件的标识,例如Extension-Name: Struts Framework 五. 包扩展属性 1. Implementation-Title 定义了扩展实现的标题2. Implementation-Version 定义扩展实现的版本3. Implementation-Vendor 定义扩展实现的组织 4. Implementation-Vendor-Id 定义扩展实现的组织的标识5. Implementation-URL : 定义该扩展包的下载地址(URL)6. Specification-Title 定义扩展规范的标题7. Specification-Version 定义扩展规范的版本8. Specification-Vendor 声明了维护该规范的组织9. Sealed 定义jar文件是否封存,值可以是true或者false (这点我还不是很理解)六. 签名相关属性签名方面的属性我们可以来参照JavaMail所提供的mail.jar中的一段Name: javax/mail/Address.classDigest-Algorithms: SHA MD5 SHA-Digest: AjR7RqnN//cdYGouxbd06mSVfI4=MD5-Digest: ZnTIQ2aQAtSNIOWXI1pQpw==这段内容定义类签名的类名、计算摘要的算法名以及对应的摘要内容(使用BASE64方法进行编码)七.自定义属性除了前面提到的一些属性外,你也可以在MANIFEST.MF中增加自己的属性以及响应的值,例如J2ME程序jar包中就可能包含着如下信息MicroEdition-Configuration: CLDC-1.0MIDlet-Name: J2ME_MOBBER Midlet SuiteMIDlet-Info-URL: : /icon.pngMIDlet-Vendor: Midlet Suite VendorMIDlet-1: mobber,/icon.png,mobberMIDlet-Version: 1.0.0MicroEdition-Profile: MIDP-1.0MIDlet-Description: Communicator关键在于我们怎么来读取这些信息呢?其实很简单,JDK给我们提供了用于处理这些信息的API,详细的信息请见java.util.jar包中,我们可以通过给JarFile传递一个jar文件的路径,然后调用JarFile的getManifest方法来获取Manifest信息。****************************打包.exe文件的方案**************************** 对于windows用户来说,将java应用程序打包成.exe最好不过了,现在我介绍两个方法。1、用专业的应用程序打包工具InstallAnywhere,这个软件几乎能在所有平台上运行,当然你要下载到你需要的那个平台的啦!而且它也能打包成各个平台的安装程序。2、用MINI的免费的工具javalunch,JavaLauncher的下载网址是:下载下来的文件是一个名JavaLauncher.zip的压缩包,解压后的目录结构:l source目录包含了JavaLauncher的源程序,是用C语言写的l changes.txt是新版的修改说明l launch.exe是主程序l launcher.cfg是配置文件l readme.txt是一些说明和示例我们只需要launch.exe、launcher.cfg两个文件,将这两个文件复制到打包文件所在的目录。launcher.cfg是一个仅三行内容的文本文件,将它修改如下:.\java1.4.2\jre\bin\javaw.exe -jar myswt.jarl 第一行设置指向JAR包myswt.jar的目录,由于launch.exe和myswt.jar同在一个目录,所以用"."即当前目录。l 第二行设置指向jre\bin\javaw.exe的路径。配置好launcher.cfg后,双击launch.exe即可运行java应用程序。如果仔佃研究eclipse的启动方式,发现eclipse和JavaLauncher的原理一样:eclipse.exe相当于launch.exe,startup.jar相当于myswt.jar。只不过eclipse.exe不象launch.exe要具有通用性,所以它没有*.cfg这样的配置文件,而是将启动信息固化在eclipse.exe中。另:美化图标launch.exe文件的图标太单调了,让我们给它换个好看点的。换程序的图标需要用到一个免费的软件:Resource Hacker,它有中文版,下载网址是:由于这个软件有中文版的,在这里我就不多说了,挺简单的。 ------------------------写了这么一坨,我没看完。没研究这个工具的心情。 ******************************插件实现.exe文件导出**************************** 一 JSmooth 1.出品 Jsmooth,Sourceforge.net 2. 类型 free 3. 下载 . 步骤 a)利用Eclipse将所需要的主类打成可独立运行的jar包,注意添加manifest属性和MainClass。 b)新建一个Jsmooth工程 c) 在sketlon中选择“Console“ 或者 “Windowed“ d) 在Executable中的配置: i. Executable Binary:填写目的输出源的名称。如test.exe. ii. Executable Icon :选择一个好看点的图标 iii. Current Driectory :.(表示当前工程目录,当然也可行换成别的,As you wish.) e) 在Application中的配置: i. Classpath:选中我们所生成的jar包以及运行该jar文件所需要的类库 ii. Main-Class:选中我们所需要运行的主类。 iii. 可选项Use an embedded jar:运行该exe时可能需要到的类库(这里只能有一个类库)。 f) 在JVM Selection中的配置: i. Minimum JVM Version:写一个需要运行该程序所需的最低的就JVM的版本,比如1.4 g) Compile:OK,编译成功后,在你的输出目录上就会有一个崭新的exe程序了。Just enjoy it. 二 exe4J 1. 出品 ej-technologies 2.类型 Shared software,needs license 3.下载 . 步骤 a) 利用Eclipse将所需要的主类打成可独立运行的jar包,注意添加manifest属性和MainClass。 b) 新建一个exe4j工程 c) 选择“JAR in exe“ mode d) 在Configure application中的配置: i. Short name:随便写. ii. Ourput Driectory :选择输出路径。 e) 在Configure Executable中的配置: i. Executable type: 有三个选项,图形,控制台.或服务。从简单点开始吧,这里我们选console ii. Executable name:填写目的输出源的名称。如test.exe iii. Icon file:exe图标文件,但必须是.ico文件 f) 在Configure Java invocation中的配置: i. Classpath:选中我们所生成的jar包以及运行该jar文件所需要的类库 ii. Main-Class:选中我们所需要运行的主类。 iii.Arguments(可选项):输入参数。我们这里暂不需要。 g)在Configure JRE中的配置: i. Minimum Version:写一个需要运行该程序所需的最低的就JVM的版本,比如1.4 h) 一直next,对于所遇到的步骤选项都默认,直到finish:OK。编译成功后,在你的输出目录上就会有一个崭新的exe程序了。Just enjoy it. 三 总结和比较 由Java生成exe的工具还有很多,上面两种是我个人觉得用起来觉得比较方便的。两者的原理基本相同,但具体用起来还是有一点点不太一样的: 1.相同点 a) 最大的相同点当然是他们原理是互通的。都是通过将可运行的java程序打成可执行的jar包。再作转换。 b) 所生成的exe可执行程序,需要在装有比minimum version高的JVM环境下运行。 2. 不同点 a) 生成exe的时候,如果想要exe只需要pure JVM的环境(不需要第三方的类库)就可以运行的话。在JSmooth需要将所有的用到的第三方类库压缩成一个jar包(因为它有个embeded jar的选项),这就比较麻烦,因为当需要的jar多于一个时候,就需要将这些jar包先用jar –xvf 解压缩,在用jar –cvf重新制作新的jar文件,再放到embeded jar选项中去;而exe4J则会把classppath中所用到的jar包也会编译到exe中去。 b) JSmooth是免费的;而exe4J是共享软件,需要注册,否则在执行exe的时候会弹出很惹人烦的提示框。 c)ico文件的选择:exe4J要求严格的ico文件,而JSmooth则可以兼容jpg等其他各式的图片。 以上为转的

jwxjava的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、jwxjava的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-26,除非注明,否则均为首码项目网原创文章,转载请注明出处。