在按钮中添加照片
class Actions implements ActionListener {
public void actionPerformed(ActionEvent e) {
// Get the button that was clicked
JButton theButton = (JButton) e.getSource();
// Set it's background color to white
Color color = theButton.getBackground();
if(upload.isSelected()){Icon i=new ImageIcon(upload.getText());
}
if(start.isSelected()){
for(int i=0;i<buttonNum;i++){
Color check=buttons[i].getBackground();
if(check==Color.green){
buttons[i].setBackground(Color.white);
}
}
theButton.setBackground(Color.green);}
else if(end.isSelected()){
for(int i=0;i<buttonNum;i++){
Color check=buttons[i].getBackground();
if(check==Color.red){
buttons[i].setBackground(Color.white);
}
}
theButton.setBackground(Color.red);}
else if (color==Color.black)
{
theButton.setBackground(Color.white);}
else{theButton.setBackground(Color.black);
}
}
}
此功能将使用for循环创建一些按钮。我想添加一个函数,在选择上传按钮后,当我单击“循环创建的按钮”之一时,它将在按钮上放置照片。
class Actions implements ActionListener {
public void actionPerformed(ActionEvent e) {
// Get the button that was clicked
JButton theButton = (JButton) e.getSource();
// Set it's background color to white
Color color = theButton.getBackground();
if(upload.isSelected()){Icon i=new ImageIcon(upload.getText());
}
if(start.isSelected()){
for(int i=0;i<buttonNum;i++){
Color check=buttons[i].getBackground();
if(check==Color.green){
buttons[i].setBackground(Color.white);
}
}
theButton.setBackground(Color.green);}
else if(end.isSelected()){
for(int i=0;i<buttonNum;i++){
Color check=buttons[i].getBackground();
if(check==Color.red){
buttons[i].setBackground(Color.white);
}
}
theButton.setBackground(Color.red);}
else if (color==Color.black)
{
theButton.setBackground(Color.white);}
else{theButton.setBackground(Color.black);
}
}
}
This function will create some buttons using a for loop. I want to add a function that after the upload button selected, when I clicked one of the buttons created by for loop, it will put a photo on the button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论