吴裕雄--天生自然JAVA图形界面编程学习笔记:按钮组件JButton

import javax.swing.JFrame ;
import javax.swing.JButton ;
import java.awt.Font ;
public class JButtonDemo01{
    public static void main(String args[]){
        JFrame frame = new JFrame("Welcome To MLDN") ;    // 实例化窗体对象
        JButton but = new JButton("按我") ;     
        Font fnt = new Font("Serief",Font.BOLD,28);
        but.setFont(fnt) ;
        frame.add(but) ;
        frame.setSize(200,70) ;
        frame.setLocation(300,200) ;
        frame.setVisible(true) ;
    }
};
import javax.swing.JFrame ;
import javax.swing.JButton ;
import javax.swing.Icon ;
import javax.swing.ImageIcon ;
import java.io.File ;
import java.awt.Font ;
public class JButtonDemo02{
    public static void main(String args[]){
        JFrame frame = new JFrame("Welcome To MLDN") ;    // 实例化窗体对象
        String picPath = "d:" + File.separator + "mldn.gif" ;
        Icon icon = new ImageIcon(picPath) ;
        JButton but = new JButton(icon) ;     
        frame.add(but) ;
        frame.setSize(300,160) ;
        frame.setLocation(300,200) ;
        frame.setVisible(true) ;
    }
};

猜你喜欢

转载自www.cnblogs.com/tszr/p/12398783.html
今日推荐