- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class Ch09 {
- public static void main(String[] args) {
-
- JFrame fm=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, 25, 180, 30);
- l3.setBounds(8, 50, 180, 30);
- l4.setBounds(8, 75, 180, 30);
- l5.setBounds(100, 100, 100, 30);
- fm.setBounds(100, 100, 200, 200);
- fm.setVisible(true);
- fm.setResizable(false);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fm.setLayout(null);
- fm.add(l1);
- fm.add(l2);
- fm.add(l3);
- fm.add(l4);
- fm.add(l5);
- }
- }
複製代碼 |