我正在尝试在未修饰的alwaysOnTop框架中创建一种工具栏.因此,我希望我的框架位于我的主框架之上,但不希望我的框架位于其他程序的框架之上.我试过这段代码:
public class Test {
private static JFrame mainFrame;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
mainFrame = new JFrame("test");
mainFrame.setSize(800,600);
mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
mainFrame.setVisible(true);
A a = new A();
}
});
}
public static class A extends JDialog {
public A() {
super(mainFrame);
setAlwaysOnTop(true);
setFocusable(false);
setSize(80,60);
setVisible(true);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是尽管使用了JDialog并且对所有者进行了精确处理,框架仍然位于其他应用程序之上(至少使用Ubuntu.可能结果与其他操作系统不同?)
编辑:好的,我在我的对话框中尝试了这段代码:
public static class A extends JDialog {
public A(String name) {
super(mainFrame, …Run Code Online (Sandbox Code Playgroud) 我怎样才能刷新/删除/删除所有索引文件/中使用Apache Lucene.This磁盘数据是到目前为止我的代码和我仍然无法删除索引files.Please帮我...
测试:
public class Test {
private static final String INDEX_DIR = "/home/amila/Lucene/REST/indexing";
public static void main(String[] args) {
try {
ContentIndexer contentIndexer = new ContentIndexer(INDEX_DIR);
contentIndexer.flushDisk();
System.out.println("Flushed");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
ContentIndexer:
public class ContentIndexer {
private IndexWriter writer;
public ContentIndexer(String indexDir) throws IOException {
// create the index
if (writer == null) {
writer = new IndexWriter(FSDirectory.open(new File(indexDir)),
new IndexWriterConfig(Version.LUCENE_36,
new StandardAnalyzer(Version.LUCENE_36)));
}
}
public void flushDisk() {
try {
writer.deleteAll();
} …Run Code Online (Sandbox Code Playgroud) 我有一个包含json格式的HashMap客户列表的文件.
像这样:
{"Davide":{"name":"Davide","cf":"FRCDVD","pi":"1234",
"telephone":"333","website":"www","sector":"Student","address":"Rome"}}
Run Code Online (Sandbox Code Playgroud)
这只是列表的一个客户.每次调用控制器时,我都想从文件中获取数据并将它们转换为HashMap列表.
我尝试这样做:
HashMap<String, Customer> listCustomer = new HashMap<>();
listCustomer = new ObjectMapper().readValue(pathCustomerFile, HashMap.class); //This line gives me error
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误:
org.codehaus.jackson.JsonParseException:意外字符('/'(代码47)):也许是(非标准)评论?(因为功能'ALLOW_COMMENTS'未启用解析器而未被识别为一个)
我怎样才能做到这一点?
我希望有人可以帮助我,这就是我想要做的.
我有一个JTextPane,我想截取特定的JTextPane坐标和大小,到目前为止,我可以做一个JTextPane大小的截图,但我无法得到我的截图总是得到的特定坐标(0,0 )坐标.
这是我的方法:
void capturaPantalla ()
{
try
{
int x = txtCodigo.getX();
int y = txtCodigo.getY();
Rectangle areaCaptura = new Rectangle(x, y, txtCodigo.getWidth(), txtCodigo.getHeight());
BufferedImage capturaPantalla = new Robot().createScreenCapture(areaCaptura);
File ruta = new File("P:\\captura.png");
ImageIO.write(capturaPantalla, "png", ruta);
JOptionPane.showMessageDialog(null, "Codigo de barras guardado!");
}
catch (IOException ioe)
{
System.out.println(ioe);
}
catch(AWTException ex)
{
System.out.println(ex);
}
}
Run Code Online (Sandbox Code Playgroud) 我需要编写一个随机字符串生成类,它从31个字符的字符集和一些字母表中生成7char字符串(10 + 26-5,省略5个元音).简单的数学给出了一组31 ^ 7种可能的组合~275亿.我对bday悖论有疑问,我进行了一些测试,重复数量呈指数级增长.我可以做些什么来避免这种情况吗?
At 1 million, duplicates encountered till now = 19
At 2 million, duplicates encountered till now = 69
At 3 million, duplicates encountered till now = 157
At 4 million, duplicates encountered till now = 280
At 5 million, duplicates encountered till now = 470
At 6 million, duplicates encountered till now = 662
At 7 million, duplicates encountered till now = 896
At 8 million, duplicates encountered till now = 1185
At 9 million, …Run Code Online (Sandbox Code Playgroud) 我是android开发的新手.这是我遇到的问题.我正在使用Android Studio.我查了很多网站,他们说要导入相关的课程.完成后,问题仍然存在.任何帮助表示赞赏.
任何人都可以帮我这个,我一直在寻找解决方案.
这是代码:
package com.example.veeresh.myapplication;
//import statements
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(
//error: cannot find symbol class onClickListener
new Button.onClickListener()
{
public void onClick(View v)
{
TextView text1 = (TextView)findViewById(R.id.text1);
text1.setText("Veeresh Here");
}
}
);
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
错误:(
24,27 )错误:无法找到符号类onClickListener 错误:任务':app:compileDebugJava'的执行失败.
编译失败; 请参阅编译器错误输出以获取详细信
在下面的代码中,我有两种不同的方法来实例化类的对象B.
public interface A {}
public class B implements A {}
public static void main(String[] args)
{
A test1 = new B();
B test2 = new B();
}
Run Code Online (Sandbox Code Playgroud)
变量test1和test2有什么区别?
我何时应该使用Interface类型(type1)进行实例化,何时不应该?
我是android的初学者,我想知道为什么当我在定义TextView后放置我的 setContentView()时,我的应用程序崩溃,即
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv=(TextView) findViewById(R.id.tv);
Linkify.addLinks(tv, Linkify.WEB_URLS|Linkify.EMAIL_ADDRESSES|
Linkify.PHONE_NUMBERS);
setContentView(R.layout.activity_main); //After TextView
}
Run Code Online (Sandbox Code Playgroud)
但是当我在定义TextView之前放入我的 setContentView()时,我的应用运行正常.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //Before TextView
TextView tv=(TextView) findViewById(R.id.tv);
Linkify.addLinks(tv, Linkify.WEB_URLS|Linkify.EMAIL_ADDRESSES|
Linkify.PHONE_NUMBERS);
}
Run Code Online (Sandbox Code Playgroud)
为什么会这样以及如何添加setContentView()才能产生差异?
我正在解决一个竞争问题,在问题中,我使用扫描仪获取用户输入。
这些是 2 个代码段,一个关闭扫描器,一个不关闭扫描器。
关闭扫描仪
import java.util.Scanner;
public class JImSelection {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = Integer.valueOf(scanner.nextLine());
while (n-- > 0) {
double number = (Math.log(Long.valueOf(scanner.nextLine())) / Math.log(2));
System.out.println((int) number - number == 0 ? "Yes" : "No");
}
scanner.close();
}
}
Run Code Online (Sandbox Code Playgroud)
不关闭扫描仪
import java.util.Scanner;
public class JImSelection {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = Integer.valueOf(scanner.nextLine());
while (n-- > 0) {
double …Run Code Online (Sandbox Code Playgroud) 所以我一直在尝试用Java实现LinkedList,Stack,Queue.
对于每一个我正在使用节点类,现在我真的不想讨论我的实现是如何,因为我知道有更好的方法来做到这一点,我只想关注我的问题.
public class Node<E> {
private E data;
private Node<E> next;
private Node<E> prev;
public Node(E data) {
this.data = data;
this.next = null;
this.prev = null;
}
public E getData() {
return this.data;
}
public Node<E> getNext() {
return this.next;
}
public Node<E> getPrev() {
return this.prev;
}
public void setPrev(Node<E> prev) {
this.prev = prev;
}
public void setData(E data) {
this.data = data;
}
public void setNext(Node<E> next) {
this.next = next;
}
}
Run Code Online (Sandbox Code Playgroud)
现在有了节点类,我一直在混淆垃圾收集器的工作方式,所以我们说这是我的队列类
public …Run Code Online (Sandbox Code Playgroud) java ×10
android ×2
swing ×2
apache ×1
coordinates ×1
flush ×1
hashmap ×1
json ×1
jtextpane ×1
lucene ×1
nodes ×1
probability ×1
queue ×1
random ×1
screenshot ×1
user-input ×1