问题描述
- 在窗体中添加button时 eclipse运行后提示挂起是什么意思是,该怎么改
-
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
时间: 2024-11-01 09:37:28