import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class ButtonFrame extends JFrame{
public ButtonFrame(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,100,384,160);
JPanel contentPane=new JPanel();
contentPane.setVisible(true);
contentPane.setBorder(new EmptyBorder(5,5,5,5));;;
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel=new JPanel();
panel.setBounds(0, 0, 368, 122);
contentPane.add(panel);
panel.setLayout(null);
JButton messageButton = new JButton("普通按钮");
messageButton.setBounds(54, 33, 108, 46);
panel.add(messageButton);
java.net.URL url=getClass().getResource("D:/log.png");
ImageIcon icon=new ImageIcon(url);
JButton imageButton = new JButton(icon);
imageButton.setBounds(196, 14, 108, 85);
panel.add(imageButton);
}
public static void main(String[] args){
new ButtonFrame();
}
}
location或者什么变量是否为null