Guest User

Untitled

a guest
Jul 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. package frame;
  2.  
  3. import javax.swing.*;
  4. import javax.swing.border.Border;
  5. import java.awt.*;
  6.  
  7.  
  8. /**
  9. * Created by IntelliJ IDEA.
  10. * User: white
  11. * Date: 11/01/29
  12. * Time: 8:07
  13. * To change this template use File | Settings | File Templates.
  14. */
  15. public class Frame7 extends JFrame {
  16. public static void main(String args[]){
  17. Frame7 frame = new Frame7("icon");
  18. frame.setVisible(true);
  19. }
  20.  
  21. Frame7(String title){
  22. setTitle(title);
  23. setBounds(100,100,300,250);
  24. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25.  
  26. //iconの画像を相対パスで取得
  27. ImageIcon icon = new ImageIcon("./src/main/java/frame/d.png");
  28. //アイコンに画像を指定
  29. setIconImage(icon.getImage());
  30.  
  31. //Panelにラベルを貼り付ける
  32. JPanel p1 = new JPanel();
  33. p1.add(new JLabel("title"));
  34. p1.add(new JLabel(icon));
  35.  
  36. //パネルを配置
  37. Container contentPane = getContentPane();
  38. contentPane.add(p1, BorderLayout.NORTH);
  39. }
  40. }
Add Comment
Please, Sign In to add comment