ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 210824_Swing+label+Icon+Date
    Swing 2021. 8. 24. 17:48

    public class SwingCompEx01 extends JFrame{

     

    Container cp;

    JLabel label1,label2,label3,label4;

    Icon icon1=new ImageIcon("/Library/sist0730/image/img3.gif");

    Icon icon2=new ImageIcon("/Library/sist0730/image/img6.gif");

    JTextField text1;

     

    public SwingCompEx01(String title) {

    super(title);

     

    cp=this.getContentPane();

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.setBounds(200,300,400,400);  //정사각형

    cp.setBackground(new Color(155,255,200));

     

    initDesign();

    this.setVisible(true);

    }

     

     

    public void initDesign() {

     

    this.setLayout(null);

     

    text1=new JTextField();

    text1.setBounds(10, 20, 80, 30);

    this.add(text1);  //보일수 있게 넣기

     

    label1=new JLabel("안녕?", JLabel.CENTER);  //라벨 이름,위치

    label1.setBounds(10, 100, 200, 30);

    label1.setOpaque(true);  //라벨이 불투명모드로 됨, 투명모드는 false

    this.add(label1);

     

    label2=new JLabel("Happy Day", icon1, JLabel.RIGHT);

    label2.setBounds(10, 150, 200, 30);

    label2.setBorder(new LineBorder(Color.RED));  //보더로 넣어보기

    this.add(label2);

     

    label3=new JLabel("자바스윙공부중", icon2, JLabel.CENTER);

    label3.setBounds(10, 210, 500, 50);

    label3.setBorder(new TitledBorder("Slist"));  //주로 제목

    this.add(label3);

     

    //라벨에 날짜 넣어보기

    SimpleDateFormat sdf=new SimpleDateFormat("yyyy년 MM월 dd일 HH시mm분");

    label4=new JLabel(sdf.format(new Date()),icon2,JLabel.CENTER);

    label4.setBounds(10, 260, 250, 50);

     

    label4.setBorder(new LineBorder(Color.pink, 10));

    this.add(label4);

    }

     

     

    public static void main(String[] args) {

     

    new SwingCompEx01("텍스트 & 라벨");

    }

    }

     

     

    댓글

Designed by Tistory.