我想创建一个简单的Swing应用程序.然而,我对Swing的经历非常非常非常少.我想创建一个窗口应用程序,每隔5分钟刷新一次,我会用屏幕抓取内容.我正在使用Clojure编写代码.我认为Swing是采用这种方式的方法,但如果还有其他更好的选择,我也希望能够更多地了解这些.
使用Swing我需要用什么代码?(我应该使用哪些课程等)
谢谢,亚历克斯
我正在尝试测量几种方法的执行时间.所以我想多做一个方法而不是重复相同的代码.
这是我的代码:
private void MeasureExecutionTime(Method m)
{
startTime = System.nanoTime();
try
{
m();
}
finally
{
endTime = System.nanoTime();
}
elapsedTime = endTime - startTime;
System.out.println("This takes " + elapsedTime + " ns.");
}
Run Code Online (Sandbox Code Playgroud)
假设我有myMethod(),我怎么MeasureExecutionTime()用来衡量myMethod执行时间?
这是我的代码:
<input type="text" onkeyup="if(this.value.length > 0) document.getElementById('start_button').disabled = false; else document.getElementById('start_button').disabled = true;"/>
<input type="button" value="Click to begin!" id="start_button" disabled/>
Run Code Online (Sandbox Code Playgroud)
这有效但效率仍然不高,因为用户可以删除文本框内的文本,并在按住DELETE键时单击按钮.有没有更有效的方法来实现这个使用JavaScript?
让我们说你有两个数组:
int[] a = {2, 3, 4};
int[] b = {4, 5, 6};
Run Code Online (Sandbox Code Playgroud)
你如何将数组a设置为数组b并保持它们不同的不同对象?就像我想的那样:
a = b;
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为它只是制作一个"参考"数组b.那么,设置两个数组相同的唯一方法是保持它们是不同的对象,以循环遍历一个数组的每个元素并将其设置为另一个数组吗?
那么ArrayList呢?当你有对象时,你如何设置一个ArrayList等于另一个?
我自己,我总是使用ActionListener摇摆事件处理程序(例如按钮单击),它是我在大多数swing应用程序中看到的最常见的监听器.
但是,这里的一些Swing专业人员在stackoverflow中经常建议使用Action而不是ActionListener.这样做有什么好处?
我正在使用JFileChooser来选择文件,我试图限制显示只显示jpg或jpeg文件.我尝试过FileFilter和ChoosableFileFilter,它不限制文件选择.这是我的代码:
JFileChooser chooser = new JFileChooser();
FileFilter filter = new FileNameExtensionFilter("JPEG file", new String[] {"jpg", "jpeg"});
chooser.setFileFilter(filter);
chooser.addChoosableFileFilter(filter);
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
debug.put("You chose to open this file: " + chooser.getSelectedFile().getAbsolutePath());
File selectedFile = new File(chooser.getSelectedFile().getAbsolutePath());
...
Run Code Online (Sandbox Code Playgroud) 要创建阿拉伯语 JFileChooser (RTL),我使用以下命令:
\n\n我的文件选择器:
\n\nimport javax.swing.JOptionPane;\nimport javax.swing.UIManager;\nimport javax.swing.JFileChooser;\nimport javax.swing.filechooser.FileNameExtensionFilter;\nimport javax.swing.filechooser.FileView;\nimport java.io.File;\nimport java.awt.ComponentOrientation;\nimport java.awt.Dimension;\npublic class MyFileChooser extends JFileChooser\n{\n private String extension;\n private String title;\n public MyFileChooser(String extension, String title)\n {\n super();\n this.extension = extension;\n this.title = title;\n addChoosableFileFilter(new FileNameExtensionFilter(String.format("(*.%1$s) \xd9\x81\xd9\x82\xd8\xb7 %1$s \xd9\x85\xd9\x84\xd9\x81\xd8\xa7\xd8\xaa", extension), extension));\n applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);\n //setPreferredSize(new Dimension(450, 350));\n }\n\n @Override public String getDialogTitle()\n {\n return title;\n }\n\n @Override public File getSelectedFile()\n {\n File selectedFile = super.getSelectedFile();\n if(selectedFile != null)\n {\n String name = selectedFile.getName();\n if(!name.contains(".")) selectedFile = new File(selectedFile.getParentFile(), …Run Code Online (Sandbox Code Playgroud) 当我运行以下Visual Basic代码时:
Dim b As Double
b = (2 ^ 16 - 1) * Math.Sqrt(Math.Sqrt((a / (2 ^ 8 - 1))))
Run Code Online (Sandbox Code Playgroud)
(假设a是一个双倍,其值为15.0)
我得到的结果b大约是32,275.
但是,当我运行以下Java代码时,应该执行与上面相同的操作:
double b;
b = (2 ^ 16 - 1) * Math.sqrt(Math.sqrt((a / (2 ^ 8 - 1))));
Run Code Online (Sandbox Code Playgroud)
再次a15岁,我得到了一个非常不同的结果:大约17岁.
两者都在解决这个等式:

为什么会这样?对于我正在进行的工作,Visual Basic会产生我正在寻找的结果.
我只是面对一个我自己无法解决的问题.我尝试在我的BorderPane中放置一个包含TextField和HTML-Editor的vBox,但不使用完整的空间.另一个问题是,如果我收缩窗口,html编辑器与我的左选项窗口重叠.

private void initEditor()
{
editor = new HTMLEditor();
editor.setId("editor");
editor.lookup(".top-toolbar").setDisable(true);
editor.lookup(".top-toolbar").setManaged(false);
((ToolBar) editor.lookup(".bottom-toolbar")).getItems().addAll(FXCollections.observableArrayList(((ToolBar)editor.lookup(".top-toolbar")).getItems()));
editorBox = new VBox();
TextField field = new TextField();
field.setPrefHeight(36);
field.setId("editor-title");
editorBox.setFillWidth(true);
editorBox.getChildren().addAll(field, editor);
root.setCenter(editorBox);
}
Run Code Online (Sandbox Code Playgroud) 如何控制/限制提交给的任务ExecutorService?我有SMSTask发送SMS消息,我需要控制执行程序,以便它只能发送最多N条消息/秒.
java ×9
swing ×4
jfilechooser ×2
action ×1
arabic ×1
arrays ×1
button ×1
clojure ×1
concurrency ×1
filefilter ×1
html ×1
html-editor ×1
int ×1
javafx ×1
javascript ×1
math ×1
methods ×1
vb.net ×1