在VB6中调用Form_Load()和Form_Activate()函数的顺序是什么?"激活"在表格的上下文中意味着什么?
考虑以下抽象类 -
public abstract class Car
{
public abstract void drive(double miles);
}
Run Code Online (Sandbox Code Playgroud)
这是扩展上述类的示例类(用于说明目的).
public class Ferrari extends Car
{
private String lastUsed; // Ferrari specific field not in Car
private boolean f1Car; // Ferrari specific field not in Car
@XmlElement
public void setF1Car(boolean f1Car)
{
this.f1Car = f1Car;
}
public boolean isF1Car() { return f1Car; }
@XmlElement
public void setLastUsed(String lastUsed)
{
this.lastUsed = lastUsed;
}
public String getLastUsed() { return lastUsed; }
public void drive(double miles)
{
// …Run Code Online (Sandbox Code Playgroud) 考虑这个示例python代码.它从stdin读取并写入文件.
import sys
arg1 = sys.argv[1]
f = open(arg1,'w')
f.write('<html><head><title></title></head><body>')
for line in sys.stdin:
f.write("<p>")
f.write(line)
f.write("</p>")
f.write("</body></html>")
f.close()
Run Code Online (Sandbox Code Playgroud)
假设我想修改同一个程序来写入stdout.然后,我将不得不更换的每个实例f.write()有sys.stdout.write().但那太繁琐了.我想知道是否有一种方法可以指定f为别名sys.stdout,因此将f.write()其视为sys.stdout.write().
我在HTML中有一个按钮(正方形)列表,如下所示 -
<td><button id="18" ></button></td>
<td><button id="28" ></button></td>
<td><button id="38" ></button></td>
...
Run Code Online (Sandbox Code Playgroud)
早些时候,对于每个按钮,我不得不将代码放在按钮标签本身中以添加事件处理程序,如下所示 -
<button id="18" onclick="squareWasClicked(event)">
function squareWasClicked(event)
{
var element = event.target;
// more code
}
Run Code Online (Sandbox Code Playgroud)
但现在我发现这不是好习惯.所以相反,我试图从我的JavaScript代码中添加事件处理程序.但我不知道该怎么做.到目前为止,我试过这个 -
function assignEventsToSquares()
{
var i,j;
for(i=1;i<=8;i++)
{
for(j=1;j<=8;j++)
{
var squareID = "" + i + "" + j;
var square = document.getElementById(squareID);
square.onclick = squareWasClicked();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这只是调用squareWasClicked()函数.那么如何将其添加为事件处理程序,以便在单击方格时调用该函数?另外,我怎么说呢
square.onclick = squareWasClicked(event);
Run Code Online (Sandbox Code Playgroud)
在JavaScript代码中未检测到事件.请帮忙.
当我尝试为textarea设置scrollTop值时,我遇到了一个问题。我的JavaScript代码如下-
var element = document.getElementById("messageTextArea");
console.log("scrollTop = "+element.scrollTop);
console.log("scrollHeight = "+element.scrollHeight);
element.scrollTop = element.scrollHeight; // doesn't work!
console.log("The value is-->"+element.scrollTop); // no change!
element = document.getElementById("messageTextArea");
console.log("Now scrollTop = "+element.scrollTop); // no change!
console.log("Now scrollHeight = "+element.scrollHeight);
Run Code Online (Sandbox Code Playgroud)
Firefox控制台日志提供以下内容-
scrollTop = 0
scrollHeight = 86
The value is-->0
Now scrollTop = 0
Now scrollHeight = 86
Run Code Online (Sandbox Code Playgroud)
我真正想做的是,当文本不适合实际的宽度和高度并且激活了滚动条时,以某种方式将文本区域自动向下滚动到最大。
这是解释问题的两个屏幕截图-
这是我目前拥有的-

这就是我想要的-

请帮忙!
我想在我在文件中搜索的某个单词 (SetupAX) 之后指定空格。
我正在以这种方式尝试 findstr 命令 -
findstr /n /r "SetupAX[ \r\n\t]" XYZ.frm
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用。如果我不放空格,我会得到类似的结果 -
findstr /n /r "SetupAX" XYZ.frm
158: If Filled() Then Call SetupAXForB
170: SetupAXForC
196: SetupAX //<-- correct
242: Call SetupAX //<-- correct
276: Call SetupAXN
...
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?我只想要“SetupAX”而不是“SetupAX...”的实例。谢谢。
import java.util.ArrayList;
public class ListOfClasses
{
private ArrayList<Class> classes;
public ArrayList<Class> getClasses()
{
return classes;
}
public void setClasses(ArrayList<Class> classes)
{
this.classes = classes;
}
}
Run Code Online (Sandbox Code Playgroud)
为此,我在日食中收到以下警告 -
类是原始类型.应参数化对泛型类的引用
这是在之前的问题中提出的,但答案是针对Spring Framework的.但即使没有与Spring有任何关系,我也会得到这个警告.那么问题是什么?
有时,我遇到的情况是我需要测试的是程序的执行是否达到某个点而没有抛出任何异常,或者程序被中断或陷入无限循环或某事.
我不明白的是如何为此编写单元测试.
例如,考虑以下"单元测试" -
@Test
public void testProgramExecution()
{
Program program = new Program();
program.executeStep1();
program.executeStep2();
program.executeStep3();
// if execution reaches this point, that means the program ran successfully.
// But what is the best practice?
// If I leave it like this, the test will "pass",
// but I am not sure if this is good practice.
}
Run Code Online (Sandbox Code Playgroud)
通常,在测试结束时,我有一个声明如下 -
assertEquals(expectedString, actualString);
Run Code Online (Sandbox Code Playgroud)
但是如何为上述情况编写assertEquals或其他类型的测试语句?
这是我为了测试目的需要做的事情。我需要一种根据某些预设条件(例如处理的项目数)随时使 Spring Batch 作业失败的方法。但是,到目前为止,我还没有找到类似的东西。
我发现 Spring Batch 有这样的东西 -
<step id="step1" parent="s1" next="step2">
<step id="step2" parent="s2">
<fail on="FAILED" exit-code="EARLY TERMINATION"/>
<next on="*" to="step3"/>
</step>
<step id="step3" parent="s3">
Run Code Online (Sandbox Code Playgroud)
但我正在寻找的是这样的——
public void myJobFailingMethod()
{
if(conditionsMatch())
{
// fail the job
}
}
Run Code Online (Sandbox Code Playgroud)
这该怎么做?
更新:作业也可能在步骤之外失败。
我正在使用Tomcat 5.5和Spring 3.2.在web.xml部署描述符中,我有以下配置 -
<error-page>
<error-code>500</error-code>
<location>/500.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/403.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
无法解释的行为发生在类似于下面的方法中 -
public ModelAndView fileDownload(HttpServletRequest request,
HttpServletResponse response) throws Exception
{
String filename = (String) request.getParameter("filename");
//...more code
File file = new File(...+ filename); // pseudo code
OutputStream out = response.getOutputStream();
InputStream stream = new FileInputStream(file); // FileNotFoundException here
//...more code
}
Run Code Online (Sandbox Code Playgroud)
当发生FileNotFoundException时,我没有看到我的自定义500.jsp用于呈现错误页面,而是在页面上看到了异常的整个堆栈跟踪.如果我只是颠倒两个语句的顺序如下,
InputStream stream = new FileInputStream(file); // FileNotFoundException here
OutputStream out = response.getOutputStream();
Run Code Online (Sandbox Code Playgroud)
一切正常,我得到了正确的500.jsp在页面上呈现.
为什么会这样?唯一的区别是在后一种情况下,响应对象的OutputStream未打开.
java ×5
spring ×2
containers ×1
findstr ×1
generics ×1
html ×1
java-ee ×1
javascript ×1
jaxb ×1
marshalling ×1
python ×1
regex ×1
scrollbar ×1
spring-batch ×1
textarea ×1
tomcat ×1
unit-testing ×1
vb6 ×1