package java1;import javax.swing.*;
public class JButton1 { public static void main(String[] args) {
JFrame jf=new JFrame();
JPanel jp=new JPanel();
jf.add(jp);
JButton yes=new JButton("yes",new ImageIcon("smile.gif"));
JButton no=new JButton("no",new ImageIcon("cry.gif"));
jp.add(yes);
jp.add(no);
jf.pack();
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
怎么没有笑面和哭面的按钮的?是不是要设置按钮的大小的?
public class JButton1 { public static void main(String[] args) {
JFrame jf=new JFrame();
JPanel jp=new JPanel();
jf.add(jp);
JButton yes=new JButton("yes",new ImageIcon("smile.gif"));
JButton no=new JButton("no",new ImageIcon("cry.gif"));
jp.add(yes);
jp.add(no);
jf.pack();
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
怎么没有笑面和哭面的按钮的?是不是要设置按钮的大小的?
2.检查图片是否太小,显示出来的是一个点。xx.setSize(300, 300);
JPanel jp = new JPanel();
jp.setLayout(null);
JButton yes = new JButton("yes", new ImageIcon(JButton1.class.getResource("/smile.gif")));
yes.setBounds(2,2,100, 30);
JButton no = new JButton("no", new ImageIcon(JButton1.class.getResource("/cry.gif")));
no.setBounds(155,2,100, 30);
jp.add(yes);
jp.add(no);
JFrame jf = new JFrame();
jf.setBounds(12, 12, 300,100);
jf.add(jp);
jf.validate();
jf.setVisible(true); }