我在Swing应用程序中有一个状态栏,可以连续打印状态.应用程序中的所有对象和类都将使用此setStatus方法绘制状态栏
public def setStatus(statusText){
Thread.start {
ljaStatusBarButton.setText("Status : $statusText . . . .")
sleep(3000)
ljaStatusBarButton.setText("Status : Waiting for user action . . . .")
interrupt() // or stop() ?
}
}
Run Code Online (Sandbox Code Playgroud)
状态栏将显示状态3秒,并恢复为等待用户操作的状态.
这确实可以正常工作,但我担心的是上面的方法将从UI多次调用,这也意味着每次设置状态时都会创建一个新的Thread对象.记住这一点,我最后明确地添加了一个interrupt(),因为我想指示编译器我不再需要这个线程了.而且,我可以在Java的垃圾收集上下注多少,以确保很快就能清除已停止/中断的线程?或者这个多线程对象问题有更好的解决方法吗?
我在使用Microsoft Visual Studio-2005编译器处理C代码时遇到了一个问题.
我试图静态地声明一个大缓冲区:
int gbl_data[4096*4096*256];
Run Code Online (Sandbox Code Playgroud)
编辑:此声明是头文件中的全局变量.
它给出了一个编译错误说 - " 无法分配一个常量大小为0的数组 ".
意味着4096X4096X256的大小变得太大而不是MAX_INT_LIMIT大小(2 ^ 31),并且可能会缠绕并变成-ve左右.但是它应该把错误称为"负下标".
我尝试将常量转换为4096UL x 4096UL x 256UL,仍然是相同的编译错误.
这个错误的原因是什么?
是因为物理内存大小不足以分配这个大尺寸缓冲区还是什么?
有什么办法解决的?
谢谢.
-GM.
如何在 JList 的单个单元格内显示多行。在jtable中,是通过在表格单元格渲染器中添加一个JTextarea来实现的。同样,是否有任何代码可以为包含文本区域的 JList 添加自定义单元格渲染器?如果是,您能给我一个相同的代码片段吗?
或者您认为还有其他更好的方法可以在 Jlist 的单元格内显示多行而不是使用文本区域吗?请帮我!!
下面的类使用一个JInternalFrame来保存一个Textarea,它显示所有重定向的println和err语句.
public class ConsoleFrame extends JInternalFrame
{
JTextArea outArea = new JTextArea(10,100);
static JInternalFrame cons;
public ConsoleFrame()
{
outArea.setLineWrap(true);
JScrollPane pain = new JScrollPane(outArea);
//pain.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
this.add(pain);
this.setVisible(true);
this.setSize(1000,400);
this.setTitle("Groovy Console");
this.closable = false;
this.maximizable = false;
this.isSelected = true;
this.resizable = false;
BasicInternalFrameUI ui = (BasicInternalFrameUI)this.getUI();
Component north = ui.getNorthPane();
MouseMotionListener[] actions =
(MouseMotionListener[])north.getListeners(MouseMotionListener.class);
for (int i = 0; i < actions.length; i++)
north.removeMouseMotionListener( actions[i] );
this.setFocusable(false);
//logger
System.setErr(new PrintStream(new JTextAreaOutputStream(outArea)));
System.setOut(new PrintStream(new JTextAreaOutputStream(outArea)));
setConsole(this);
}
static public JInternalFrame getConsole(){ …Run Code Online (Sandbox Code Playgroud) 我是否可以编写一个sql查询,该查询可以查找数据库中具有列名称为%COL_FAX_ID%的所有表的名称.如果是这样,怎么样?
使用的数据库是oracle或db2.
为什么在方法B和C没问题的情况下不编译方法A?
class A {
methodA() {
}
void methodB() {
}
static methodC() {
}
}
Run Code Online (Sandbox Code Playgroud) 我的textArea行之间的默认间距太笨拙了.我想增加线之间的行间距.有没有办法实现textarea?
PS:我知道可以为JTextPanewith StyledDocument和STyledConstants 设置行间距.我的范围仅限于TextArea,我宁愿不喜欢用textpane替换我的textarea,因为它会搞乱项目中的一些其他功能依赖项.
嗨,我一直在写(和学习)C++,我在程序中正确地编写了所有代码(或者我认为).我收到此错误:
"rands(int)", referenced from:
_main in ccgc4zY9.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我的代码是这样的:
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<cmath>
using namespace std;
int rands(int n);
int hits[10];
int main () {
int n;
int i;
int r;
srand(time(NULL));
cout<<"enter a number of trials to run"<<endl;
cin>>n;
for (i=1; i<=n; i++) {
r=rands(10);
hits[r]++;
}
for (i=0; i<10; i++) {
cout<<i<<":"<<hits[i]<<"<Accuracy";
cout<<static_cast<double>(hits[i])/(n/10)<<endl;
}
return 0;
}
int randns(int n) {
return rand()%n;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏!
我希望链接上的所有点击都能执行特定的操作,但mailto链接除外.我有以下代码按预期工作.它首先将该函数附加到所有链接,然后将其从mailto链接中删除:
<a href="http://www.example.com">example.com</a>
<a href="mailto:someone@www.example.com">Someone</a>
<script type="text/javascript">
$('a').on('click', function () {
theAction();
});
$('a[href^="mailto"]').off('click');
</script>
Run Code Online (Sandbox Code Playgroud)
我想要相同的功能,但使用:not()选择器,因为它看起来更优雅.怎么会这样?
当我尝试乘以charAt时,我收到了"大号":
String s = "25999993654";
System.out.println(s.charAt(0)+s.charAt(1));
Run Code Online (Sandbox Code Playgroud)
结果:103
但是当我想只收到一个号码时,没关系.
在JAVA文档中:
the character at the specified index of this string. The first character is at index 0.
Run Code Online (Sandbox Code Playgroud)
所以我需要解释或解决方案(我认为我应该将字符串转换为int,但在我看来这是不必要的工作)
life = 91
today = System.currentTimeMillis()
expireDate = new Date(today + life * 24 * 3600 * 1000);
Run Code Online (Sandbox Code Playgroud)
new Date(today)Wed Nov 28 15:21:01 GMT+05:30 2012按预期返回今天的日期
为什么new Date(expireDate)回报Tue Nov 20 05:17:16 GMT+05:30 2012在今天的日期之前,实际上我预计会提前约会呢?