JAVA按钮图片改变如何实现 在线等
importjavax.swing.JFrame;importjavax.swing.ImageIcon;importjavax.swing.JButton;import...
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.EventListener;
import java.awt.event.ActionEvent;
public class Home03 extends JFrame implements ActionListener{
public static void main(String agrs[]){
new Home03();
}
JButton button0 = new JButton("我是美女");
JButton button1 = new JButton("我是帅哥");
ImageIcon icon = new ImageIcon("kof3.gif");
JLabel label0 = new JLabel();
JLabel label1 = new JLabel("我是美女");
public Home03(){
JPanel panel0 = new JPanel(new GridLayout(1,2));
JPanel panel1 = new JPanel(new GridLayout(1,2));
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
label0.setIcon(icon);
panel1.add(button0);
panel1.add(button1);
panel0.add(panel2);
panel0.add(panel3);
panel2.setLayout(new BorderLayout());
panel3.setLayout(new BorderLayout());
panel2.add(label0);
panel3.add(label1);
this.add(panel1,"South");
this.add(panel0);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setSize(400,400);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(button0)){
icon = new ImageIcon("kof3.gif");
label1 = new JLabel("我是美女");
}
else{
icon = new ImageIcon("kof1.gif");
label1 = new JLabel("我是帅哥");
}
}
}
这个程序是 捕捉按钮 然后图片变成相应的 提示字也变
分左右 问题是 我现在图片想放在左面的中间 JLabel 放了图片不知道如何移动
还有点按钮图片和字都不变 展开
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.EventListener;
import java.awt.event.ActionEvent;
public class Home03 extends JFrame implements ActionListener{
public static void main(String agrs[]){
new Home03();
}
JButton button0 = new JButton("我是美女");
JButton button1 = new JButton("我是帅哥");
ImageIcon icon = new ImageIcon("kof3.gif");
JLabel label0 = new JLabel();
JLabel label1 = new JLabel("我是美女");
public Home03(){
JPanel panel0 = new JPanel(new GridLayout(1,2));
JPanel panel1 = new JPanel(new GridLayout(1,2));
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
label0.setIcon(icon);
panel1.add(button0);
panel1.add(button1);
panel0.add(panel2);
panel0.add(panel3);
panel2.setLayout(new BorderLayout());
panel3.setLayout(new BorderLayout());
panel2.add(label0);
panel3.add(label1);
this.add(panel1,"South");
this.add(panel0);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setSize(400,400);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(button0)){
icon = new ImageIcon("kof3.gif");
label1 = new JLabel("我是美女");
}
else{
icon = new ImageIcon("kof1.gif");
label1 = new JLabel("我是帅哥");
}
}
}
这个程序是 捕捉按钮 然后图片变成相应的 提示字也变
分左右 问题是 我现在图片想放在左面的中间 JLabel 放了图片不知道如何移动
还有点按钮图片和字都不变 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询