Java Swing設定圖示Icon
阿新 • • 發佈:2019-02-14
該方法就是設定圖示方法 setIconImage()
public class Login extends JFrame{ private JLabel nameLabel = new JLabel("登入名:"); private JLabel passwordLabel = new JLabel("密碼:"); private JTextField nameTextField = new JTextField(); private JPasswordField passwordPasswordField = new JPasswordField(); private JButton btnLogin = new JButton("登入"); private JButton btnCancle = new JButton("取消"); private Master master = new Master(); public Login(){ this.setTitle("寵物管理系統"); this.setSize(500,500); this.setLocationRelativeTo(null); this.setVisible(true); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.getContentPane().setBackground(new Color(255, 255, 255)); // 這一條就是 this.setIconImage(new ImageIcon("src/cn/jbit/epet/image/dog.jpg").getImage()); this. init(); }