NBzhCNfaq20081020
NetBeans 有问必答活动 - 2008/10/20
- 1:【有问必答】netbeans6和ireport不能安装和运行
电脑系统 window xp sp2
CPU AMD 3000+
jdk 6.0
问题:
安装netbeans没有反应,程序自动终止了。
ireport不论是zip版还是安装版 运行都没有反应。
但是eclipse和myeclipse能安装和运行,一般的jar也没问题。
- 2:【有问必答】企业级JAVA用的是什么开发工具
想问一下企业级的JAVA用的开发工具一般是什么?哪种工具比较方便?
蒋健:
主要的Java企业应用包括JSP,Servlet,JSF, EJB, Web Service等类型。
主流的Java集成开发环境比如NetBeans和Eclipse都支持各类企业应用开发。
NetBeans为各类企业应用的创建提供了丰富的向导和强大的编辑调试功能,并且和最新
的Java EE企业应用服务器GlassFish紧密集成,是Java企业开发理想的工具。***
- 3:【有问必答】一个奇怪的IllegalMonitorStateException
源代码在后面,控制台的输出是
0err,no comiled file foundF:\c\hello.exejava.lang.IllegalMonitorStateException
很奇怪,因为输出0,说明程序执行到了我的process函数的最后一个try()catch()块,但是给出一个异常却是在第三个try()catch块中出现的,
另外我对这个IllegalMonitorStateException异常也比较陌生,看doc文档的描述也很不是很懂.请问问题出在哪里,谢谢了.
package acmoj;
import java.io.*;
/**
*
* this class can run a test ,and get the result about the test.
* @version 2008/10/14
* @author lich
*
*/
public class test implements Runnable {
private String source;
private int type;
private int result;
/**
* this will new a porcsee and runing it will get the result
* @param s string means the place of the sourse file of test.
* @param t int.
* 1 means using c and file I/O.
* 2 means using c++ and file I/O.
* 3 means using java and file I/O.
* 4 means using c and console I/O.
* 5 means using c++ and console I/O.
* 6 means using java and console I/O
*/
public test(String s,int t){
source=s;
type=t;
}
/**
* return the result about the test
*
* @return int
* 0 accept
* 1 wrong answer
* 2 compile error
* -1 err,file do not exist.
*/
public int getresult(){
return result;
}
private int process(){
String cmd="";
//try to compile the input file
try{
if(type==2){
cmd="g++ -o "+source+" "+source+".cpp";
Process p=Runtime.getRuntime().exec(cmd);
p.waitFor();
p.destroy();
}
}catch(Exception e){
//this exception should never happen
System.out.print("err,no file found");
return -1;
}
//try to run the compiled programe
try{
if(type==2){v
cmd=source+".exe";
Process p=Runtime.getRuntime().exec(cmd);
this.wait(1000);
p.destroy();
}v
}catch(Exception e){
//if this exception happen means the comile has some errs;
System.out.print("err,no comiled file found"+cmd+e.toString());
return 2;
}
//try to compare the program output and the std output
try{
String stdout,out;
stdout=source+".sout";
out=source+".out";
FileInputStream stdStream = new FileInputStream(stdout);
FileInputStream file=new FileInputStream(out);
int tmp;
while((tmp=stdStream.read())!=-1){
if(tmp!=file.read()){
return 1;
}
}
stdStream.close();
file.close();
return 0;
}catch(Exception e){
return 1;
}
}
/**
* when it runs ,it will try to do things and you can use getresult() to get the result.
* @see #getresult()
*/
public void run() {
result=process();
}
/**
* this main function is used for test.
* @param args the test file names
*/
public static void main(String[[ | ]] args) {
test t=new test("F:
c
hello",2);
new Thread(t).start();
System.out.print(t.getresult());
}
}
- 4:【有问必答】netbean 6.1 下操作 JProgressBar 操作问题
在netbean 6.1中,可以直接新建一个Desktop application 的工程,系统会自动生成N多组件,
其中包括JProgressBar.
可是,它怎么操作呢?
它自己生成的在运行时根本不显示,
自己再拖进去一个?只显示一白条。我通过setValue改变它的值的时候,一点反应也没有。
哪位朋友知道该怎么操作呢?
气得我自己写了一个小程序。
运行后还好,如下:
import java.awt.*;
import javax.swing.*;
public class Progress extends JFrame {
JProgressBar current;
// JTextArea out;
JButton find;
// Thread runner;
int num = 0;
public Progress() {
super("Progress");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.setLayout(new FlowLayout());
current = new JProgressBar(0, 2000);
current.setValue(0);
current.setStringPainted(true);
pane.add(current);
setContentPane(pane);
}
public void iterate() {
while (num < 2000) {
current.setValue(num);
try {
Thread.sleep(1000);
} catch (InterruptedException e) { }
num += 95;
}
}
public static void main(String[[ | ]] arguments) {
Progress frame = new Progress();
frame.pack();
frame.setVisible(true);
frame.iterate();
}
}
可怎么才能操作系统自动生成的那个条呢?
Leon: Netbeans 中该部分运用了新的 Swing 框架 JSR-296,要与该 progressbar 联系,应该产生新的 Task, 在Task中调用 setProgress()即可。下面给了一个简单的事例,你点击 "About"菜单可以看到 Progress 的变化:
@Action public Task showAboutBox() {
return new RefreshTask(DesktopApplication2.getApplication());
}
private class RefreshTask extends Task {
RefreshTask(org.jdesktop.application.Application app) {
super(app);
}
@SuppressWarnings("unchecked")
@Override protected Void doInBackground() {
try {
setProgress(0, 0, 4);
setMessage("Rolling back the current changes...");
setProgress(1, 0, 4);
Thread.sleep(1000L); // remove for real app
setProgress(2, 0, 4);
setMessage("Starting a new transaction...");
Thread.sleep(500L); // remove for real app
setProgress(3, 0, 4);
setMessage("Fetching new data...");
Thread.sleep(1300L); // remove for real app
setProgress(4, 0, 4);
Thread.sleep(1500L); // remove for real app
} catch(InterruptedException ignore) { }
return null;
}
@Override protected void finished() {
setMessage("Done.");
}
}***
- 5:【有问必答】请问使用NetBeans6.x开发visual web jsf 项目时如何使用ajax实现无刷新提交
刚接触 visual web jsf ,感觉很方便,那如何使用ajax实现无刷新提交呢?
能否给个例子或者教程?
Michael: 大多数visual web jsf 组件带有submit()方法用来提交数据,和refresh()方法用来更新数据
小例子:
在文本输入框Onkeyup事件属性里加入以下javascript代码:
var textfield = document.getElementById("form1:textField1");
textfield.submit();
var staticT = document.getElementById("form1:staticText1"); //staticT 和Session里的一个数值绑定,refresh时就能更新
staticT.refresh();***
- 6:【有问必答】将MyEclipse做的项目迁移到NetBeans要注意些什么
很高兴能看到NetBeans6.X有如此多的改进(虽然还是那么吃内存),那请问如果想将以前MyEclipse做的项目迁移到NetBeans开发,需要注意些什么?
Michael: NetBeans带了Eclipse项目引入器,可以试试,应该不需要你再注意什么了,等它自动完成就好了。***

