- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class Ch01 {
- public static void main(String[] args) {
-
- JFrame f=new JFrame("元件配置練習");
- JLabel l1=new JLabel("預設");
- JLabel l2=new JLabel("靠左",JLabel.LEFT);
- JLabel l3=new JLabel("置中",JLabel.CENTER);
- JLabel l4=new JLabel("靠右",JLabel.RIGHT);
- JLabel l5=new JLabel("其他");
- l1.setBounds(8, 0, 180, 30);
- l2.setBounds(8, 35, 180, 30);
- l3.setBounds(8, 70, 180, 30);
- l4.setBounds(8, 105, 180, 30);
- l5.setBounds(50, 140, 100, 30);
- f.setBounds(100, 100, 200, 200);
- f.setVisible(true);
- f.setResizable(false);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f.setLayout(null);
- f.add(l1);
- f.add(l2);
- f.add(l3);
- f.add(l4);
- f.add(l5);
- }
- }
複製代碼 |