目前,我有一个Java Standalone Swing Application.
现在,当用户点击Swing应用程序中的按钮时,我想启动另一个Java应用程序(Say:calculator.jar)
我可以知道这样做的便携方式是什么?这样它可以在多个操作系统中运行?
我想知道哪种方法正确?
_tcscpy(tchar_pointer, _tcslen(tchar_pointer), _T("Hello World"));
Run Code Online (Sandbox Code Playgroud)
要么
_tcscpy(tchar_pointer, _tcsclen(tchar_pointer), _T("Hello World"));
Run Code Online (Sandbox Code Playgroud)
要么
_tcscpy(tchar_pointer, ???, _T("Hello World"));
Run Code Online (Sandbox Code Playgroud) 在C编程中,每当我尝试第一次执行cat时,我都需要
TCHAR file_name[1024];
// Use memset or set the first byte to 0?
file_name[0] = 0;
_tcscat(file_name, TEMP_DIRECTORY_PATH);
_tcscat(file_name, file);
Run Code Online (Sandbox Code Playgroud)
我看到大多数程序员都在使用memset.但是,对我来说,我只是将第一个字节设置为0,让_tcscat知道从哪里开始.
我不确定是否有任何缺点/陷阱,而不是使用memset?
谢谢.
我使用Joshua Bloch介绍的Java builder模式.有时,我发现某些字段比原始类型与默认值一样初始化更昂贵.
因此,我的策略是什么.
我不确定这样做是否有益?有没有可能发生的捕获?就像,线程安全问题?到目前为止,我没有看到任何问题.
package sandbox;
import java.util.Calendar;
/**
*
* @author yccheok
*/
// Builder Pattern
public class NutritionFacts {
private final int servingSize;
private final int servings;
private final int calories;
private final int fat;
private final int sodium;
private final int carbohydrate;
private final java.util.Calendar calendar; // !!!
public static class Builder {
// Required parameters
private final int servingSize;
private final int servings;
// Optional parameters - initialized to default values …Run Code Online (Sandbox Code Playgroud) 通过参考Multi Columns Combo Box for Swing的答案,我设法实现了3个多列JComboBox如下.

但是,这并不完美.我的意图是没有水平滚动条,如下所示.

我的问题是,我如何拥有一个比JComboBox本身更宽的JComboBox下拉列表?我只是想摆脱水平滚动条.然而,能够将3列放入单个列表中.
目前,我计划从vector中删除所有项目,这是集合中找不到的.
例如 :
#include <vector>
#include <set>
#include <string>
#include <iostream>
using namespace std;
int main() {
std::set<string> erase_if_not_found;
erase_if_not_found.insert("a");
erase_if_not_found.insert("b");
erase_if_not_found.insert("c");
std::vector<string> orders;
orders.push_back("a");
orders.push_back("A");
orders.push_back("A");
orders.push_back("b");
orders.push_back("c");
orders.push_back("D");
// Expect all "A" and "D" to be removed.
for (std::vector<std::string>::iterator itr = orders.begin(); itr != orders.end();) {
if (erase_if_not_found.find(*itr) == erase_if_not_found.end()) {
orders.erase(itr);
// Begin from start point again? Do we have a better way?
itr = orders.begin();
} else {
++itr;
}
}
for (std::vector<std::string>::iterator itr = orders.begin(); …Run Code Online (Sandbox Code Playgroud) 我正在使用Apache + mod-wsgi.
在我的httpd.conf中,我在文件末尾有以下附加行.
LoadModule wsgi_module modules/mod_wsgi-win32-ap22py27-3.3.so
WSGIScriptAlias / "C:/Projects/Folder/web/"
<Directory "C:/Projects/Folder/web">
AllowOverride None
Options None
Order deny,allow
Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)
当我index.py通过http://localhost/script/index.py在Windows中执行以下脚本时
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
Run Code Online (Sandbox Code Playgroud)
工作得很好.
但是,当我import utils在第一行添加时index.py,我得到了
ImportError: No module named utils
Run Code Online (Sandbox Code Playgroud)
utils.py 与目录相同 index.py
我需要设置任何其他配置吗?
我尝试@dan_waterworth给出的建议
import sys, os
sys.path.append(os.path.dirname(__file__))
Run Code Online (Sandbox Code Playgroud)
通过导入我自己的模块,我没有得到更多错误.但是,当我导入通过easy_install安装的模块时,会发生错误.
File "C:/Projects/Folder/web/script\\connection.py", line 1, in <module>
import psycopg2
File "build\\bdist.win32\\egg\\psycopg2\\__init__.py", …Run Code Online (Sandbox Code Playgroud) 当前,因为返回值set.add始终是None.我必须做以下事情.
if 1 in s:
print 'already found'
return
s.add(1)
Run Code Online (Sandbox Code Playgroud)
如果可以的话会不会很好
if not s.add(1):
print 'already found'
return
Run Code Online (Sandbox Code Playgroud) 通常,当我想将Web服务器文本文件传输到客户端时,这就是我所做的
import cgi
print "Content-Type: text/plain"
print "Content-Disposition: attachment; filename=TEST.txt"
print
filename = "C:\\TEST.TXT"
f = open(filename, 'r')
for line in f:
print line
Run Code Online (Sandbox Code Playgroud)
对ANSI文件非常好.但是,比方说,我有一个二进制文件a.exe(此文件在Web服务器的秘密路径中,用户不能直接访问该目录路径).我希望使用类似的方法来转移.我怎么能这样做?
我使用以下代码.
#!c:/Python27/python.exe -u
import cgi
print "Content-Type: application/octet-stream"
print "Content-Disposition: attachment; filename=jstock.exe"
print
filename = "C:\\jstock.exe"
f = open(filename, 'rb')
for line in f:
print line
Run Code Online (Sandbox Code Playgroud)
但是,当我将下载的文件与原始文件进行比较时,似乎在每一行之后都有一个额外的空格(或更多).

我意识到我必须将以下代码(用于模板专业化)放在 CPP 文件而不是头文件中?有什么办法可以在头文件中制作它吗?
template<> inline UINT AFXAPI HashKey<const error_code &> (const error_code & e)
{
// Hash code method required for MFC CMap.
// This hash code generation method is picked from Joshua Bloch's
// Effective Java.
unsigned __int64 result = 17;
result = 37 * result + e.hi;
result = 37 * result + e.lo;
return static_cast<UINT>(result);
}
Run Code Online (Sandbox Code Playgroud)
如果将上述函数放在 error_code.h 中,我会得到错误
错误 C2912:显式特化;'UINT HashKey(const error_code &)' 不是函数模板的特化
关于为什么我需要进行上述模板专业化的一些参考资料。http://www.codeproject.com/KB/architecture/cmap_howto.aspx。以下代码摘自文章,是MFC源代码的一部分。
// inside <afxtemp.h>
template<class ARG_KEY>
AFX_INLINE UINT AFXAPI HashKey(ARG_KEY …Run Code Online (Sandbox Code Playgroud) c++ ×3
java ×3
python ×3
apache ×1
c ×1
content-type ×1
mod-wsgi ×1
swing ×1
visual-c++ ×1
windows ×1