对不起,伙计们,我删除了我的APPLES和CATS示例:)这是我的问题的更新版本!
我在这里失去理智.我需要能够启发我的人.我曾尝试过几次在这里解释我的问题.希望这次,我的问题会更容易理解.
基本上我有这个框架,并显示一个图像.右侧有一个JList,底部有另一个JLabel面板.这是我框架的屏幕截图.

当我点击图像时,会弹出一个JOptionPane,就像这样.我输入了我的输入.我的JList是一个ArrayList,所以我输入的所有内容都被添加到JList和底部的JPanel.

现在,当我将鼠标悬停在我点击的部分时,你注意到方形消失了).它仅在我单击图像时出现,并且当我将标签悬停在底部时.我的标签,截至目前是LOLZ NOSE和INPUT HERE.

我想要做的是当我将鼠标悬停在标签上时,例如INPUT HERE,它再次显示正方形,其中包含我点击的部分.我现在的问题是,当我点击NOSE时,它应该在鼻子部分显示一个正方形,并且名字NOSE有黑色bg,它不显示.此外,仅显示最后一个标签的正方形,而忽略其他标签的位置点击.
如何获得标签以记住我所做的点击的位置?人们说我应该使用ArrayLists或HashCodes但是我不知道如何实现它们.感谢任何能提供帮助的人.
编辑:我已经完成了矩形,顺便说一句.它仅显示输入的最后一个标签.以下是一些要求的代码片段!
我如何在JLabel上设置文本并更新JList:
public void updateLabel(){
StringBuilder text = new StringBuilder(); //creates empty builder, capacity 16
for(Object s: tagModel.toArray()) //returns an array containing the elements of the tagModel
text.append(" " + s);
repaint();
hoverLabel.setText(text.toString()); //returns a String
hoverLabel.addMouseMotionListener(this);
hoverPanel.add(hoverLabel);
}
Run Code Online (Sandbox Code Playgroud)
点击后我的mouseListener:
@Override
public void mouseClicked(MouseEvent event) {
// TODO Auto-generated method stub
x = event.getX();
y = event.getY();
isRectPresent = true;
repaint();
input = JOptionPane.showInputDialog("Enter tag name:");
if((input != null) && …Run Code Online (Sandbox Code Playgroud) 我需要Arraylist在不使用任何库的情况下将图像上传到服务器。我正在使用Asynctask上传单个图像,它在 httpurlconnection multipart/form-data 的帮助下完美运行。现在我需要更改我的代码以使用上传任何类型的多个文件,Arraylist<String>但我的问题是现有代码FileinputStream不支持 arraylist,我不知道使用什么而不是Fileinputstream将 arraylist 上传到服务器,我不知道也想为此使用任何库。
public class multipart_test extends AsyncTask<Void,Void,String> {
Context context;
String Images;
public static final String TAG = "###Image Uploading###";
public multipart_test(Context context,String Upload_Images) {
this.context = context;
this.Images = Upload_Images;
}
@Override
protected String doInBackground(Void... params) {
BufferedReader reader;
String WebPath = null;
try {
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int …Run Code Online (Sandbox Code Playgroud) 我正忙着准备MCTS 70-536考试,根据考试书(Microsoft Press - .NET Framework - 应用程序开发基础自学训练套件第2版),此代码示例:
ArrayList al = new ArrayList();
al.AddRange(new string[] { "Hello", "world", "this", "is", "a", "test" });
Console.WriteLine(al.BinarySearch("this"));
Run Code Online (Sandbox Code Playgroud)
将值'2'输出到控制台,因为项'this'位于索引2.同意这是我运行该代码时得到的输出.
但是,如果我跑
Console.WriteLine(al.BinarySearch("world"));
Run Code Online (Sandbox Code Playgroud)
我希望在控制台中获得值1,因为'world'将在索引1,但是我得到值-7?
谁能解释一下这是如何工作的?
谢谢
在API级别8中保存ArrayList字符串的最佳方法是什么SharedPreferences?我现在能想到的唯一方法是将所有字符串保存到一个用逗号分隔的字符串中并以这种方式保存.但我不知道字符串是否有最大大小.
有一个更好的方法吗?
我有一个List<string>尺寸,比如XS,S,M,L,XL,XXL,UK 10,UK 12等
我想要的是强制命令是上面的命令,无论列表中的项目顺序如何,我想我需要一个IComparable运算符但不确定.
理想情况下,我想让另一个List具有正确的顺序,它可以在列表中引用它的'place'并重新排序,如果它不存在,它将默认为AZ
我有以下代码 -
import java.util.ArrayList;
public class ArrayListExp{
public static void main (String[] args){
ArrayList<String> name = new ArrayList<String>();
name.add("Chris");
name.add("Lois");
name.add("Meg");
name.add("Meg");
name.add("Brain");
name.add("Peter");
name.add("Stewie");
System.out.println(name);
for ( int i = 0; i < name.size(); i++){
String oldName = name.get(i);
if(oldName.equals("Meg"))
{
name.remove(i);
}
}
System.out.println(name);
}
}
Run Code Online (Sandbox Code Playgroud)
但在这里它给了我输出 -
[Chris, Lois, Meg, Meg, Brain, Peter, Stewie]
[Chris, Lois, Meg, Brain, Peter, Stewie]
Run Code Online (Sandbox Code Playgroud)
我没有明白这一点,为什么这不是删除,Meg但我Meg在这种情况下只尝试了一个它正在工作.而当我Meg在最后添加更多时,我Meg没有从中删除ArrayList.为什么?
我在arraylist中有N个数字.为了得到这个indexOf,arraylist必须迭代最多N次,所以复杂性是O(N)正确的吗?
public ArrayList<String> convertJsonToJsonObject(){
ArrayList<String> mylist = new ArrayList<String> ();
mylist.add("abc");
mylist.add("cfd");
mylist.add("ert");
mylist.add("fg");
mylist.add("ujk");
mylist.add("wer");
mylist.add("dvb");
mylist.add("ert");
System.out.println("JSONObject :: "+(JSONObject)JSONSerializer.toJson(mylist));
}
Run Code Online (Sandbox Code Playgroud)
我在.toJson()方法上有错误,我不确定我犯的是什么错误.
我正在使用Android Studio,我一直遇到一个我不知道如何解决的问题.我不知道这是Android Studio的问题,是Java还是错误.
我有一个类,其构造函数如下:
public MakeQuery(Callable<ArrayList<? extends A>) {
...
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下行创建该类的对象:
Callable<ArrayList<B>> callable = new Callable<ArrayList<B>>() {...};
MakeQuery makeQuery = new MakeQuery(callable);
Run Code Online (Sandbox Code Playgroud)
(当然,课程B延伸A.双重检查)
但是当我调用构造函数时,IDE会告诉我它需要另一种类型的参数.
我犯了什么错误?感谢您的帮助!:)
我有一个简单的问题,可以在Java上完成以下内容吗?
ArrayList<String> arr1 = new ArrayList<String>();
ArrayList<String> arr2 = new ArrayList<String>();
// Processing arrays, filling them with data
for(String str : arr1, arr2) {
//Do stuff
}
Run Code Online (Sandbox Code Playgroud)
意图是迭代第一个数组,然后是下一个数组.
我能想到的最好的方法是使用单独的for循环,当for循环具有相同的内部代码时,这会产生冗余编码.
另一个解决方案是创建一个ArrayLists数组.这使我很容易实现我的意图,即:
ArrayList<ArrayList<String>> arr = new ArrayList<ArrayList<String>>();
// Initialising arr and populating with data
for(ArrayList<String> tempArr : arr) {
for(String str : tempArr) {
//Do stuff
}
}
Run Code Online (Sandbox Code Playgroud)
但这会导致无法读取的代码.有没有一种干净的方式来做后者我不会丢失单独数组的名称?
提前谢谢,Declan