- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class Ch01 {
- public static void main(String args[])
- {
- JLabel l1=new JLabel("預設");
- l1.setBounds(10, 10, 180, 20);
-
- JLabel l2=new JLabel("靠左",JLabel.LEFT);
- l2.setBounds(10, 40, 180, 20);
-
- JLabel l3=new JLabel("置中",JLabel.CENTER);
- l3.setBounds(10, 70, 180, 20);
-
- JLabel l4=new JLabel("靠右",JLabel.RIGHT);
- l4.setBounds(10, 100, 180, 20);
-
- JLabel l5=new JLabel("其他");
- l5.setBounds(80, 100, 180, 50);
-
- JFrame f=new JFrame("JLabel");
- f.setBounds(100,100,250,250);
- 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);
-
- }
- }
複製代碼 |