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