import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Point; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; //================================================= // File Name : JFrame_demo //------------------------------------------------------------------------------ // Author : Common //主类 //Function : JFrame_demo public class JFrame_demo { public static void main(String[] args) { // TODO 自动生成的方法存根 JFrame f = new JFrame("Swing窗口"); //实例化窗体对象 String picPath = "/home/common/software/database/photo.jpg"; Icon icon = new ImageIcon(picPath); JButton but = new JButton(icon); f.add(but); //向容器中加入组建 Dimension dim = new Dimension(); //实例化Dimension对象 dim.setSize(230,80); //设置大小 f.setSize(dim); //设置组件大小 f.setBackground(Color.WHITE); Point point = new Point(300,200); //设置现实的坐标点 f.setLocation(point); f.setVisible(true); } }