zoukankan      html  css  js  c++  java
  • 第一次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 }

     非常简单,作为博客园的开端,附上界面结果图:

     

    看似简单的知识背后,承载的是收获和成长!
  • 相关阅读:
    HOW TO MAKE IT FLOW ?
    ansys14.0 从入门到精通
    ansys 14.0
    C++ GUI Qt4 编程 (第二版)
    零基础学QT编程
    医学成像与医学图像处理
    曾巩传
    c++ 编程调试秘笈
    matlab实用教程
    不要重复发明轮子-C++STL
  • 原文地址:https://www.cnblogs.com/wxywxy/p/6681509.html
Copyright © 2011-2022 走看看