我有白色图标,当我查看该图标时,我想要制作不同的颜色.
这是我的白色图标:
hint.setIcon(newjavax.swing.ImageIcon(getClass().getResource ("white.png")));
Run Code Online (Sandbox Code Playgroud)
当您将鼠标拖到图标上以更改颜色时,我该怎么做?
如何只选择一张不能重复的图片?
我试过这个:
我使用随机,我想删除所选的图片
String[] picture = { "blue", "white", "red", "yellow" };
int number_picture1;
// Random function to find a random picture
Random ran = new Random();
number_picture1 = ran.nextInt(picture.length);
System.out.println(picture[number_picture1]);
// There is still posibility to chose the same picture
int number_picture2;
number_picture2 = ran.nextInt(picture.length);
System.out.println(picture[number_picture2]);
Run Code Online (Sandbox Code Playgroud) 我如何将数字保存在列表中,我可以在其中从最小到最大排序。我创建了新字符串,我在其中插入了所有数字。比我进入 List 并对其进行排序。之后我检查一个数字,我得到颜色 od 图标。
我试过这个:
import java.util.Collections;
import java.util.ArrayList;
import java.io.*;
int colour1 = 1;
int colour2 = 3;
int colour3 = 2;
int colour4 = 3;
String rezerva =colour1, colour2, colour3, colour4;
List<String> myList = new ArrayList(rezerva);
Collections.sort(myList);
colour1 = myList.get(0);
if (colour1==1){
//change icon to red
}
else if (colour1==2){
//change icon to white
}
else {
//change icon to black
}
Run Code Online (Sandbox Code Playgroud)