第一次Java作業——簡單的登錄界面


千里之行,始於足下,從小做起,一點一滴學編程。

 1 import javax.swing.*;
 2 import java.awt.*;
 3 
 4 public class Homework{
 5     
 6     public static void main(String[] args){
 7         
 8         JFrame frame = new JFrame();
 9         
10         JPanel panel1 = new JPanel();
11         JPanel panel2 = new JPanel();
12         JLabel label0 = new JLabel("      學生成績管理系統");
13         JLabel label1 = new JLabel("用戶名:");
14         JLabel label2 = new JLabel("密碼:");
15         JTextField jtf = new JTextField(10);
16         JPasswordField jpf = new JPasswordField(10);
17         JButton button1 = new JButton("登錄");
18         JButton button2 = new JButton("取消");
19         
20         Font font1 = new Font("SansSerif",Font.BOLD,50);
21         Font font2 = new Font("SansSerif",Font.BOLD,25);
22         Font font3 = new Font("SansSerif",Font.BOLD,35);
23         ImageIcon icon1 = new ImageIcon("1.png");
24         ImageIcon icon2 = new ImageIcon("2.png");
25         ImageIcon icon3 = new ImageIcon("3.png");
26         ImageIcon icon4 = new ImageIcon("4.png");
27         ImageIcon icon5 = new ImageIcon("5.png");
28         
29         frame.add(panel1);
30         panel1.setSize(600, 150);
31         panel1.setBackground(Color.CYAN);
32         panel1.setLayout(new BorderLayout());
33         panel1.add(label0,BorderLayout.CENTER);
34         label0.setFont(font1);
35         label0.setForeground(Color.BLUE);
36         
37         frame.add(panel2);
38         panel2.setSize(460, 220);
39         panel2.setLocation(60, 200);
40         panel2.setLayout(new GridLayout(3,2,20,35));
41         panel2.add(label1);
42         panel2.add(jtf);
43         panel2.add(label2);
44         panel2.add(jpf);
45         panel2.add(button1);
46         panel2.add(button2);
47         label1.setFont(font2);
48         label2.setFont(font2);
49         button1.setFont(font3);
50         button2.setFont(font3);
51         label1.setIcon(icon2);
52         label2.setIcon(icon3);
53         button1.setIcon(icon4);
54         button2.setIcon(icon5);
55         label1.setForeground(Color.BLUE);
56         label2.setForeground(Color.BLUE);
57         button1.setForeground(Color.BLUE);
58         button2.setForeground(Color.BLUE);
59         
60         
61         frame.setTitle("用戶登錄");
62         frame.setIconImage(icon1.getImage());
63         frame.setSize(600,500);
64         frame.setLocation(400, 300);
65         frame.setLayout(null);
66         frame.setResizable(false);
67         frame.setVisible(true);
68         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
69     }
70 }

 非常簡單,作為博客園的開端,附上界面結果圖:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM