- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class Morris {
- public static void main(String[] args) {
- JFrame f1 = new JFrame("JTextField");
- JLabel lb1 = new JLabel("預設");
- JLabel lb2 = new JLabel("靠左", JLabel.LEFT);
- JLabel lb3 = new JLabel("靠右", JLabel.RIGHT);
- JLabel lb4 = new JLabel("置中", JLabel.CENTER);
- JLabel lb5 = new JLabel("其他");
-
- f1.setBounds(100, 100, 200, 200);
- f1.setVisible(true);
- f1.setResizable(false);
- f1.setLayout(null);
- f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- lb1.setBounds(8, 0, 180, 30);
- lb2.setBounds(8, 35, 180, 30);
- lb3.setBounds(8, 70, 180, 30);
- lb4.setBounds(8, 105, 180, 30);
- lb5.setBounds(50, 140, 180, 30);
-
- f1.add(lb1);
- f1.add(lb2);
- f1.add(lb3);
- f1.add(lb4);
- f1.add(lb5);
- }
- }
複製代碼 |