Java插入的图片显示不出来
packagepic;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt....
package pic;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
public class Pic extends JFrame implements ActionListener {
JRadioButton a1,a2,a3;
JCheckBox b1,b2,b3;
JLabel l1,l2,l3;
public Pic()
{
a1 = new JRadioButton("哈哈");
a2 = new JRadioButton("呵呵");
a3 = new JRadioButton("呜呜");
b1 = new JCheckBox("哈哈");
b2 = new JCheckBox("呵呵");
b3 = new JCheckBox("呜呜");
l1 = new JLabel();
l2 = new JLabel();
l3 = new JLabel();
this.add(a1);
this.add(l1);
this.add(b1);
this.add(l1);
this.add(a2);
this.add(l2);
this.add(b2);
this.add(l2);
this.add(a3);
this.add(l3);
this.add(b3);
this.add(l3);
a1.addActionListener(this);
a2.addActionListener(this);
a3.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
this.setLayout(new GridLayout(3,4));
this.setVisible(true);
this.setSize(800,800);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
new Pic();
}
public void actionPerformed(ActionEvent arg0) {
if(a1.isSelected())
l1.setIcon(new ImageIcon("1.jpeg"));
if(a2.isSelected())
l2.setIcon(new ImageIcon("2.jpg"));
if(a3.isSelected())
l3.setIcon(new ImageIcon("3.jpg"));
if(b1.isSelected())
l1.setIcon(new ImageIcon("1.jpeg"));
if(b2.isSelected())
l1.setIcon(new ImageIcon("2.jpg"));
if(b3.isSelected())
l1.setIcon(new ImageIcon("3.jpg"));
}
}
哪里出了问题吗? 展开
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
public class Pic extends JFrame implements ActionListener {
JRadioButton a1,a2,a3;
JCheckBox b1,b2,b3;
JLabel l1,l2,l3;
public Pic()
{
a1 = new JRadioButton("哈哈");
a2 = new JRadioButton("呵呵");
a3 = new JRadioButton("呜呜");
b1 = new JCheckBox("哈哈");
b2 = new JCheckBox("呵呵");
b3 = new JCheckBox("呜呜");
l1 = new JLabel();
l2 = new JLabel();
l3 = new JLabel();
this.add(a1);
this.add(l1);
this.add(b1);
this.add(l1);
this.add(a2);
this.add(l2);
this.add(b2);
this.add(l2);
this.add(a3);
this.add(l3);
this.add(b3);
this.add(l3);
a1.addActionListener(this);
a2.addActionListener(this);
a3.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
this.setLayout(new GridLayout(3,4));
this.setVisible(true);
this.setSize(800,800);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
new Pic();
}
public void actionPerformed(ActionEvent arg0) {
if(a1.isSelected())
l1.setIcon(new ImageIcon("1.jpeg"));
if(a2.isSelected())
l2.setIcon(new ImageIcon("2.jpg"));
if(a3.isSelected())
l3.setIcon(new ImageIcon("3.jpg"));
if(b1.isSelected())
l1.setIcon(new ImageIcon("1.jpeg"));
if(b2.isSelected())
l1.setIcon(new ImageIcon("2.jpg"));
if(b3.isSelected())
l1.setIcon(new ImageIcon("3.jpg"));
}
}
哪里出了问题吗? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询