1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
| package basic_0; import java.util.ArrayList; import javax.swing.*; import java.awt.*; import java.util.Scanner; public class BasicZc8 { public static void main(String[] args) { ArrayList<String> list = new ArrayList<>(); list.add("weiguang1"); list.add("weiguang2"); list.add("weiguang3"); System.out.println(list); System.out.println(list.get(0)); System.out.println(list.get(1)); System.out.println(list.get(2)); System.out.println("-------------------------------"); for (int i = 0; i < list.size(); i++) { String s = list.get(i); System.out.println(s); } System.out.println(list.remove(2)); System.out.println(list); System.out.println(list.remove("java3")); System.out.println(list); list.set(0, "weiguang4"); System.out.println(list); System.out.println("-------------------------------"); login(); System.out.println("窗口已运行~~~"); System.out.println("-------------------------------"); Animal a = new Animal() { @Override public void cry() { System.out.println("歪比巴伯~~~");} }; a.cry(); Run p1 = () -> { System.out.println("跑跑跑~"); }; p1.Run(); System.out.println("-------------------------------"); String s1 = "Hi,微光"; System.out.println(s1); System.out.println(s1.length()); String s2 = new String(); System.out.println(s2); String s3 = new String("Hello,微光"); System.out.println(s3); char[] chars = {'h','e','l','l','o',',','微','光'}; String s4 = new String(chars); System.out.println(s4); byte[] bytes = {97, 98, 99, 65, 66, 67}; String s5 = new String(bytes); System.out.println(s5); System.out.println("========================================"); String t1 = "abc"; String t2 = "abc"; System.out.println(t1 == t2); String t3 = new String("abc"); String t4 = new String("abc"); System.out.println(t3 == t4); System.out.println("========================================"); String okLoginName = "admin"; System.out.println("请您输入您的登录名称:"); Scanner sc = new Scanner(System.in); String loginName = sc.next(); if(okLoginName.equals(loginName)){ System.out.println("恭喜您,登录成功!"); }else{ System.out.println("登录失败!"); } System.out.println("========================================"); System.out.println("请您用手机号码登录:"); String phone = sc.next(); System.out.println("系统显示以下手机号码进入:"); String newPhone = phone.substring(0, 3) + "****" + phone.substring(7); System.out.println(newPhone); } public static void login() { JFrame frame = new JFrame("公司项目登录界面"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 300); frame.setLocationRelativeTo(null); frame.getContentPane().setBackground(new Color(245, 245, 245)); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(10, 10, 10, 10); gbc.fill = GridBagConstraints.HORIZONTAL; JLabel titleLabel = new JLabel("欢迎登录"); titleLabel.setFont(new Font("楷体", Font.BOLD, 24)); titleLabel.setForeground(new Color(64, 64, 64)); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 2; gbc.anchor = GridBagConstraints.CENTER; panel.add(titleLabel, gbc); gbc.gridy++; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.LINE_START; panel.add(new JLabel("用户名:"), gbc); gbc.gridx++; gbc.fill = GridBagConstraints.HORIZONTAL; JTextField usernameField = new JTextField(20); panel.add(usernameField, gbc); gbc.gridy++; gbc.gridx = 0; gbc.fill = GridBagConstraints.NONE; panel.add(new JLabel("密码:"), gbc); gbc.gridx++; gbc.fill = GridBagConstraints.HORIZONTAL; JPasswordField passwordField = new JPasswordField(20); panel.add(passwordField, gbc); gbc.gridy++; gbc.gridx = 0; gbc.gridwidth = 2; gbc.fill = GridBagConstraints.HORIZONTAL; JButton loginButton = new JButton("登录"); loginButton.setBackground(new Color(0, 128, 255)); loginButton.setForeground(Color.WHITE); loginButton.setFont(new Font("楷体", Font.BOLD, 14)); panel.add(loginButton, gbc); frame.add(panel); frame.setVisible(true); } abstract static class Animal{ public abstract void cry(); } @FunctionalInterface interface Run{ void Run(); } }
|