目录

  • 目录

    • 基础知识练习

      • String 类实现大小写转换的方法
      • 截取字符串中的部分内容
      • 用正则表达式判断手机号码是否合法
      • 用字符串生成器追加字符
      • 用连接运算符连接字符串
      • 去除字符串中的首尾控格
      • 获取字符串长度
      • 格式化时间
      • 格式化日期
      • 字符串的切割
    • 进阶练习
      • 用户登录验证
      • 验证ip地址的有效性
      • 判断本地文件类型
      • 命令行的简单实现
    • 数组
      • 冒泡排序
      • 直接选择排序法
      • 快速排序法
      • 反转数组中元素的顺序
      • 利用数组随机抽取幸运观众
    • 案列集锦
      • 歌手打分小程序
    • 数组的基础练习
      • 创建数组和数组之间数据的复制
      • 对数组排序并输出数组中最小的值
      • 将数组中指定索引位置的元素替换
      • 将二维数组的行列互换
      • 实现数组的复制功能
      • 排序数组并输出排序后的数组
      • 获得一维数组的长度 并输出
      • 利用一维数组输出7行杨辉三角形
      • 利用for循环输出二维数组中的值
      • 用for循环为int 型数组赋值
      • 将字符串反向输出
      • 简易电子时钟
      • 随机获取试题
      • 学生信息管理
      • 金额大小写转换

基础知识练习

String 类实现大小写转换的方法

public class Var { // 新建类public static void main(String[] args) { // 主方法String str = new String("hello WORD");// 转换为小写String newstr = str.toLowerCase();// 转换为大写String newstr2 = str.toUpperCase();System.out.println("转换为小写为:" + newstr);System.out.println("转换为大写为:" + newstr2);}
}

截取字符串中的部分内容

public class Eval { // 新建类public static void main(String[] args) { // 主方法String str = new String("We are students");String str2 = new String("I like Java");String newstr = str.substring(1, 3);String newstr2 = str2.substring(1, 3);if (newstr.equalsIgnoreCase(newstr2)) {System.out.println("两个字符相同");} else {System.out.println("两个字符不相同");}}
}

用正则表达式判断手机号码是否合法

public class Eval { // 新建类public static void main(String[] args) { // 主方法String regex = "^13\\d{9}|15[09]\\d{8}$";String text = "13000000000";if (text.matches(regex)) {System.out.println(text + " 是合法的手机号");}else{System.out.println(text + " 不是合法的手机号");}}
}

用字符串生成器追加字符

public class Eval { // 新建类public static void main(String[] args) { // 主方法String str = "CSDN";StringBuilder builder = new StringBuilder(str);for (int i = 1; i <= 10; i++) {builder.append(i);}System.out.println(builder.toString());}
}

用连接运算符”+”连接字符串

public class Example {public static void main(String[] args) {System.out.println("MWQ" + 9412);    // 与int型连接输出结果是MWQ9412System.out.println("10" + 7.5F);         // 与float型连接输出结果是107.5System.out.println("This is " + true);   // 与布尔型连接输出结果是This is trueSystem.out.println("MR" + "MWQ");    // 字符串间连接输出结果是MRMWQ// 与引用类型连接输出结果是路径:C:\text.txtSystem.out.println("路径:" + (new java.io.File("C:/text.txt"))); System.out.println();System.out.println(100 + 6.4 + "MR");    //字符串在后输出结果是106.4MRSystem.out.println("MR" + 100 + 6.4);    //字符串在前输出结果是MR1006.4}
}

去除字符串中的首尾控格

public class Example {public static void main(String[] args) {// 定义一个字符串,首尾均有空格String str = " ABC ";// 输出字符串的长度为5System.out.println(str + "长度为 : " + str.length());// 去掉字符串的首尾空格String str2 = str.trim();// 输出字符串的长度为3System.out.println(str2 + "长度为 : " + str2.length());}
}

获取字符串长度

public class Example {public static void main(String[] args) {String nameStr = "WuYang";int length = nameStr.length(); // 获得字符串的长度为10System.out.println(nameStr + " 的长度为:" + length);}
}

格式化时间

package com.ityang.java;
import java.util.Date;
public class Example {public static void main(String[] args) {Date today = new Date();// 格式化后为"03:06:53 下午"格式的时间String a = String.format("%tr", today); // 格式化为"15:06:53"格式的时间String b = String.format("%tT", today); // 格式化为"15:06"格式的时间String c = String.format("%tR", today); System.out.println(a);System.out.println(b);System.out.println(c);}
}

格式化日期

package com.ityang.java;
import java.util.Date;
import java.util.Locale;public class Example2 {public static void main(String[] args) {Date today = new Date();// 格式化后的字符串为月份的英文缩写String a = String.format(Locale.US, "%tb", today);  System.out.println("格式化后的字符串为月份的英文缩写: " + a);// 格式化后的字符串为月份的英文全写String b = String.format(Locale.US, "%tB", today);System.out.println("格式化后的字符串为月份的英文缩写: " + b);// 格式化后的字符串为星期(如:星期一)String c = String.format("%ta", today);System.out.println("月格式化后的字符串为星期: " + c);// 格式化后的字符串为星期(如:星期一)String d = String.format("%tA", today);System.out.println("格式化后的字符串为星期: " + d);// 格式化后的字符串为4位的年份值String e = String.format("%tY", today);System.out.println("格式化后的字符串为4位的年份值: " + e);// 格式化后的字符串为2位的年份值String f = String.format("%ty", today);System.out.println("格式化后的字符串为2位的年份值: " + f);// 格式化后的字符串为2位的月份值String g = String.format("%tm", today);System.out.println("格式化后的字符串为2位的月份值: " + g);// 格式化后的字符串为2位的日期值String h = String.format("%td", today);System.out.println("格式化后的字符串为2位的日期值: " + h);// 格式化后的字符串为1位的日期值String i = String.format("%te", today);System.out.println("格式化后的字符串为1位的日期值: " + i);}
}

字符串的切割

package com.ityang.java;
public class Example3 {public static void main(String[] args) {// 定义字符串String str = "book:and:food:and:drink";// 将字符串拆分为数组String[] arr = str.split(":",4);// 遍历数组元素for (String s : arr) {// 打印输出到控制台System.out.println("\"" + s + "\"");}}
}

进阶练习

用户登录验证

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.lzw.BackgroundPanel;
import com.swtdesigner.SwingResourceManager;public class MainFrame extends JFrame {private static final long serialVersionUID = -401441768279319010L;private JPasswordField passwordField;private JTextField usernameText;/*** Launch the application* @param args*/public static void main(String args[]) {EventQueue.invokeLater(new Runnable() {public void run() {try {MainFrame frame = new MainFrame();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame*/public MainFrame() {super();setTitle("用户登录");setBounds(100, 100, 500, 375);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final BackgroundPanel backgroundPanel = new BackgroundPanel();backgroundPanel.setImage(SwingResourceManager.getImage(MainFrame.class, "/res/background.jpg"));getContentPane().add(backgroundPanel, BorderLayout.CENTER);final JLabel usernameLable = new JLabel();usernameLable.setText("用户名:");usernameLable.setBounds(130, 166, 52, 18);backgroundPanel.add(usernameLable);final JLabel passwordLable = new JLabel();passwordLable.setText("密码:");passwordLable.setBounds(144, 199, 39, 18);backgroundPanel.add(passwordLable);usernameText = new JTextField();usernameText.setBounds(195, 164, 165, 22);backgroundPanel.add(usernameText);passwordField = new JPasswordField();passwordField.setBounds(195, 194, 165, 22);backgroundPanel.add(passwordField);final JButton submit = new JButton();submit.addActionListener(new ActionListener() {// 验证用户登录public void actionPerformed(final ActionEvent e) {// 从文本框中获取用户名String username = usernameText.getText();// 从密码框中获取密码String password = new String(passwordField.getPassword());// 用户登录信息String info = "";//判断用户名是否为null或空的字符串if(username == null || username.isEmpty()){info = "用户名为空!";}//判断密码是否为null或空的字符串else if(password == null || password.isEmpty()){info = "密码为空!";}//如果用户名与密码均为"mrsoft",则登录成功else if(username.equals("wuyang") && password.equals("wuyang")){info = "恭喜,登录成功";}else{info = "用户名或密码错误!";}// 通过对话框弹出用户登录信息JOptionPane.showMessageDialog(null,info);}});submit.setText("登录");submit.setBounds(162, 244, 69, 24);backgroundPanel.add(submit);final JButton reset = new JButton();reset.addActionListener(new ActionListener() {public void actionPerformed(final ActionEvent e) {// 重置按钮方法// 清空用户名文本框usernameText.setText("");// 清空密码文本框passwordField.setText("");}});reset.setText("重置");reset.setBounds(276, 244, 69, 24);backgroundPanel.add(reset);//}}

验证ip地址的有效性

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import com.lzw.BackgroundPanel;
import com.swtdesigner.SwingResourceManager;public class MainFrame extends JFrame {private static final long serialVersionUID = -5588352205398329108L;private JTextArea textArea;private JTextField textField;/*** Launch the application* @param args*/public static void main(String args[]) {EventQueue.invokeLater(new Runnable() {public void run() {try {MainFrame frame = new MainFrame();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame*/public MainFrame() {super();setTitle("验证IP地址的有效性");setResizable(false);setBounds(100, 100, 433, 227);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final BackgroundPanel backgroundPanel = new BackgroundPanel();backgroundPanel.setImage(SwingResourceManager.getImage(MainFrame.class, "/res/bg.jpg"));getContentPane().add(backgroundPanel, BorderLayout.CENTER);textField = new JTextField();textField.setBounds(148, 45, 138, 19);backgroundPanel.add(textField);final JLabel label = new JLabel();label.setText("请输入IP地址:");label.setBounds(46, 45, 96, 17);backgroundPanel.add(label);textArea = new JTextArea();textArea.setBounds(46, 97, 331, 64);backgroundPanel.add(textArea);final JButton button = new JButton();button.addActionListener(new ActionListener() {public void actionPerformed(final ActionEvent e) {String text = textField.getText();// 实例化StringUtil类StringUtil val = new StringUtil();// 验证String info = val.matches(text);// 输出验证信息textArea.setText(info);}});button.setText("验证");button.setBounds(307, 43, 70, 22);backgroundPanel.add(button);final JLabel label_1 = new JLabel();label_1.setText("验证信息:");label_1.setBounds(46, 76, 82, 15);backgroundPanel.add(label_1);//}}----

/**
* IP地址验证类
* @author wuyang
*/
public class StringUtil {

/*** 验证ip是否合法* @param text ip地址* @return 验证信息*/
public String matches(String text) {if(text != null && !text.isEmpty()){// 定义正则表达式String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\." +"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." +"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." +"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";// 判断ip地址是否与正则表达式匹配if(text.matches(regex)){// 返回判断信息return text + "\n是一个合法的IP地址!";}else{// 返回判断信息return text + "\n不是一个合法的IP地址!";}}// 返回判断信息return "请输入要验证的IP地址!";
}

}


####鉴别非法电话号码import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import com.lzw.BackgroundPanel;
import com.swtdesigner.SwingResourceManager;public class MainFrame extends JFrame {private static final long serialVersionUID = -5588352205398329108L;private JTextArea textArea;private JTextField textField;/*** Launch the application* @param args*/public static void main(String args[]) {EventQueue.invokeLater(new Runnable() {public void run() {try {MainFrame frame = new MainFrame();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame*/public MainFrame() {super();setResizable(false);setTitle("鉴别非法电话号码");setBounds(100, 100, 456, 262);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final BackgroundPanel backgroundPanel = new BackgroundPanel();backgroundPanel.setImage(SwingResourceManager.getImage(MainFrame.class, "/res/bg.jpg"));getContentPane().add(backgroundPanel, BorderLayout.CENTER);textField = new JTextField();textField.setBounds(155, 38, 155, 22);backgroundPanel.add(textField);textArea = new JTextArea();textArea.setBounds(51, 96, 336, 114);backgroundPanel.add(textArea);final JLabel label = new JLabel();label.setText("请输入电话号码:");label.setBounds(51, 40, 110, 18);backgroundPanel.add(label);final JLabel label_1 = new JLabel();label_1.setText("验证信息:");label_1.setBounds(51, 72, 66, 18);backgroundPanel.add(label_1);final JButton button = new JButton();button.addActionListener(new ActionListener() {public void actionPerformed(final ActionEvent e) {// 获取文本框中内容String text = textField.getText();// 设置返回结果textArea.setText(StringUtil.check(text));}});button.setText("验证");button.setBounds(327, 38, 60, 22);backgroundPanel.add(button);//}}

public class StringUtil {public static String check(String text){if(text == null || text.isEmpty()){return "请输入电话号码!";}// 定义正则表达式String regex = "^\\d{3}-?\\d{8}|\\d{4}-?\\d{8}$";// 判断输入数据是否为电话号码if(text.matches(regex)){return text + "\n是一个合法的电话号码!";}else{return text + "\n不是一个合法的电话号码!";}}
}

判断本地文件类型

/*** 自定义字符串工具类* @author wuyang */
public class StringUtil {/*** 判断文件类型* @param name 文件名* @return 判断的结果信息*/public static String getType(String name){// 提示信息String type = name + " : 未知文件类型!";// 判断扩展名if(name.endsWith(".jpg") || name.endsWith(".gif") || name.endsWith(".bmp")){type = name + " :\n 为图片文件!";}else if(name.endsWith(".java")){type = name + " :\n 为java文件!";}else if(name.endsWith(".txt")){type = name + " :\n 为文本文件!";}else if(name.endsWith(".pdf")){type = name + " :\n 为电子文档!";}else if(name.endsWith(".exe")){type = name + " :\n 为可执行文件!";}else if(name.endsWith(".doc")){type = name + " :\n 为word文档文件!";}else if(name.endsWith(".xls")){type = name + " :\n 为Excel电子表格!";}else if(name.endsWith(".rar")  || name.endsWith(".zip")){type = name + " :\n 为压缩文件!";}// 返回提示信息return type;}
}

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import com.lzw.BackgroundPanel;
import com.swtdesigner.SwingResourceManager;public class MainFrame extends JFrame {private static final long serialVersionUID = 1272119087959058558L;private JTextField textField;/*** Launch the application* @param args*/public static void main(String args[]) {EventQueue.invokeLater(new Runnable() {public void run() {try {MainFrame frame = new MainFrame();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame*/public MainFrame() {super();setResizable(false);setTitle("判断本地文件类型");setBounds(100, 100, 517, 146);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final BackgroundPanel backgroundPanel = new BackgroundPanel();backgroundPanel.setImage(SwingResourceManager.getImage(MainFrame.class, "/res/bg.jpg"));getContentPane().add(backgroundPanel, BorderLayout.CENTER);textField = new JTextField();textField.setBounds(87, 47, 288, 22);backgroundPanel.add(textField);final JButton button = new JButton();button.addActionListener(new ActionListener() {public void actionPerformed(final ActionEvent e) {// 实例化文件选择类FileChooser fileChooser = new FileChooser();// 文件路径String filePath = fileChooser.getFilePath();// 文件名称String fileName = fileChooser.getFileName();// 将文件路径字符串放置到文本框中textField.setText(filePath);// 通过自定义字符串工具类判断文件类型String fileType = StringUtil.getType(fileName);// 消息提示文件类型JOptionPane.showMessageDialog(null, fileType);}});button.setText("打开文件");button.setBounds(392, 46, 90, 25);backgroundPanel.add(button);final JLabel label = new JLabel();label.setText("路径:");label.setBounds(32, 49, 49, 18);backgroundPanel.add(label);//}}

命令行的简单实现

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;public class Main {// 命令private static final String COMMAND = "java";// 主方法public static void main(String[] args) {BufferedReader br = null;while (true) {try {// 提示输入命令System.out.println("Please enter command:");// 获取输入br = new BufferedReader(new InputStreamReader(System.in));// 读取输入命令的字符串String in = br.readLine();// 执行命令command(in);} catch (IOException e) {e.printStackTrace();}}}// 执行命令public static void command(String s) {// 显示信息String message = "Usage: java [-Option]\n" + "where [options] are:\n"+ "\t [-help,-?] \t显示帮助信息\n" + "\t [-ver] \t显示版本信息\n"+ "\t [-home] \t显示吴杨博客主页地址\n" + "\t [-desc] \t显示程序的描述信息\n"+ "\t [-exit] \t退出操作\n";// 判断所输入的命令是否是已指定的命令if (s.startsWith(COMMAND)) {// 判断所输入的命令的长度if (s.length() > COMMAND.length()) {// 判断命令的参数if (s.endsWith(" -help") || s.endsWith(" -?")) {// 帮助信息} else if (s.endsWith(" -ver")) {// 版本信息message = "当前版本为2.0\n";} else if (s.endsWith(" -home")) {// 主页信息message = "吴杨的博客主页:http://blog.csdn.net/qq_28334041/article/details/66472712";} else if (s.endsWith(" -desc")) {// 描述信息message = "本程序意在搭建简单的命令行模式";} else if (s.endsWith(" -exit")) {// 退出程序System.out.println("您已退出命令行程序\n");System.exit(0);} else {// 未定义的参数值message = "Error:不支持此命令!\n";}}} else if (s.equalsIgnoreCase("exit")) {// 退出程序System.out.println("您已退出命令行程序\n");System.exit(-1);} else {// 未定义的命令message = "'" + s + "' 不是内部或外部命令,也不是可运行程序\n" + "或批处理文件\n";}// 输出执行信息System.out.println(message);}
}

数组

冒泡排序

public class BubbleSort {public static void main(String[] args) {int[] array = new int[] { 5, 1, 2, 8, 4, 6, 9, 7, 3, 0 };int temp;                                                                  // 临时变量System.out.println("原有数组内容:");printArray(array);// 从小到大排序for (int i = 1; i < array.length; i++) {                                          // 排序数组的范围(整个数组)for (int j = 0; j < array.length - i; j++) {                         // 比较相邻元素,较大的数往后冒泡if (array[j] > array[j + 1]) {temp = array[j];                                       // 交换相邻两个数array[j] = array[j + 1];array[j + 1] = temp;}}}System.out.println("从小到大排序后的结果:");printArray(array);                                                      // 输出冒泡排序后的数组内容}/*** 遍历数组的方法,该方法输出数组所有内容* @param array 要遍历的数组*/public static void printArray(int[] array) {for (int i : array) {System.out.print(i + " ");}System.out.println("\n");}
}

直接选择排序法

public class SelectSort {public static void main(String[] args) {int[] array = new int[] { 5, 1, 2, 8, 4, 6, 9, 7, 3, 0 };int temp;                                                           // 临时变量System.out.println("原有数组内容:");printArray(array);                                               // 输出原有数组int index;                                                           // 索引变量for (int i = 1; i < array.length; i++) {                                   // 正序排列index = 0;for (int j = 1; j <= array.length - i; j++) {if (array[j] > array[index]) {index = j;}}// 交换在data.length-i和index两个位置上的数组元素temp = array[array.length - i];array[array.length - i] = array[index];array[index] = temp;}System.out.println("正序排列数组内容:");printArray(array);                                               // 输出排序后的数组}/*** 遍历数组的方法,该方法输出数组所有内容* @param array 要遍历的数组*/public static void printArray(int[] array) {for (int i : array) {System.out.print(i + " ");}System.out.println("\n");}
}

快速排序法

public class QuickSort {public static void main(String[] args) {char[] array = { 'a', 'b', 'f', 'e', 'g', 'd', 'h', 'c', 'j', 'i' };System.out.println("原有数组内容:");printArray(array); // 输出原有数组quickSort(array, 0, array.length - 1);System.out.println("正序排列数组内容:");printArray(array); // 输出排序后的数组}/*** 快速排序方法* * @param sortarray*            要排序的数组* @param lowIndex*            起始索引* @param highIndex*            最大索引*/private static void quickSort(char sortarray[], int lowIndex, int highIndex) {int lo = lowIndex; // 记录最小索引int hi = highIndex; // 记录最大索引int mid; // 记录分界点元素if (highIndex > lowIndex) {mid = sortarray[(lowIndex + highIndex) / 2]; // 确定中间分界点元素值while (lo <= hi) {while ((lo < highIndex) && (sortarray[lo] < mid))++lo; // 确定不大于分界元素值的最小索引while ((hi > lowIndex) && (sortarray[hi] > mid))--hi; // 确定大于分界元素值的最大索引if (lo <= hi) { // 如果最小与最大索引没有重叠char temp = sortarray[lo]; // 交换数组元素sortarray[lo] = sortarray[hi];sortarray[hi] = temp; // 交换两个索引的元素++lo; // 递增最小索引--hi; // 递减最大索引}}if (lowIndex < hi) // 递归排序没有未分解元素quickSort(sortarray, lowIndex, hi);if (lo < highIndex) // 递归排序没有未分解元素quickSort(sortarray, lo, highIndex);}}/*** 遍历数组的方法,该方法输出数组所有内容* * @param array*            要遍历的数组*/public static void printArray(char[] array) {for (char i : array) { // 遍历数组System.out.print(i + " "); // 输出数组内容}System.out.println("\n"); // 输出换行符}
}

反转数组中元素的顺序

public class ReverseSort {public static void main(String[] args) {// 创建一个数组int[] array = { 10, 20, 30, 40, 50, 60 };// 调用排序对象的方法将数组反转System.out.println("数组原有内容:");showArray(array);// 输出排序前的数组值int temp;int len = array.length;for (int i = 0; i < len / 2; i++) {temp = array[i];array[i] = array[len - 1 - i];array[len - 1 - i] = temp;}System.out.println("数组反转后内容:");showArray(array);// 输出排序后的数组值}/*** 显示数组所有元素* * @param array*            要显示的数组*/public static void showArray(int[] array) {for (int i : array) {// foreach格式遍历数组System.out.print("\t" + i);// 输出每个数组元素值}System.out.println();}
}

利用数组随机抽取幸运观众

public class ArrayExample {public static void main(String[] args) {// 定义人员数组String[] personnelArray = { "赵云", "张飞", "吕布", "貂蝉", "关羽", "诸葛亮", "刘备" };double randomNum = (double) Math.random(); // 生成随机数字int index = (int) (randomNum * personnelArray.length); // 把随机数转换为数组索引// 定义中奖信息String info = "本次抽取观众人员:\n\t" + personnelArray[index] + "\n恭喜"+ personnelArray[index] + "成为本次观众抽奖的大奖得主。" + "\n\n我们将为"+ personnelArray[index] + "颁发:\n\t过期的酸奶二十箱。";System.out.println(info);// 输出中奖信息}}
}

案列集锦

歌手打分小程序

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.util.Arrays;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;import com.swtdesigner.SwingResourceManager;public class MainFrame extends JFrame {private static final long serialVersionUID = 6061185921095535754L;/*** Launch the application* @param args*/public static void main(String args[]) {EventQueue.invokeLater(new Runnable() {public void run() {try {MainFrame frame = new MainFrame();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame*/public MainFrame() {super();setResizable(false);setTitle("歌手打分程序");setBounds(100, 100, 500, 375);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final BackgroundPanel backgroundPanel = new BackgroundPanel();backgroundPanel.setImage(SwingResourceManager.getImage(MainFrame.class, "/res/bg.jpg"));getContentPane().add(backgroundPanel, BorderLayout.CENTER);final DoubleText grade1 = new DoubleText();grade1.setBounds(303, 40, 125, 22);backgroundPanel.add(grade1);final JLabel label = new JLabel();label.setForeground(Color.WHITE);label.setText("评委一:");label.setBounds(238, 42, 59, 18);backgroundPanel.add(label);final JLabel label_1 = new JLabel();label_1.setForeground(Color.WHITE);label_1.setText("评委二:");label_1.setBounds(238, 79, 59, 18);backgroundPanel.add(label_1);final JLabel label_2 = new JLabel();label_2.setForeground(Color.WHITE);label_2.setText("评委三:");label_2.setBounds(238, 116, 59, 18);backgroundPanel.add(label_2);final JLabel label_3 = new JLabel();label_3.setForeground(Color.WHITE);label_3.setText("评委四:");label_3.setBounds(238, 157, 59, 18);backgroundPanel.add(label_3);final JLabel label_4 = new JLabel();label_4.setForeground(Color.WHITE);label_4.setText("评委五:");label_4.setBounds(238, 200, 59, 18);backgroundPanel.add(label_4);final DoubleText grade2 = new DoubleText();grade2.setBounds(303, 77, 125, 22);backgroundPanel.add(grade2);final DoubleText grade3 = new DoubleText();grade3.setBounds(303, 114, 125, 22);backgroundPanel.add(grade3);final DoubleText grade4 = new DoubleText();grade4.setBounds(303, 155, 125, 22);backgroundPanel.add(grade4);final DoubleText grade5 = new DoubleText();grade5.setBounds(303, 198, 125, 22);backgroundPanel.add(grade5);final JButton button = new JButton();button.addActionListener(new ActionListener() {public void actionPerformed(final ActionEvent e) {// 创建成绩数组double[] grades = {grade1.getDouble(),grade2.getDouble(),grade3.getDouble(),grade4.getDouble(),grade5.getDouble()};// 对数组排序Arrays.sort(grades);// 总分double sum = 0;// 最低分double min = grades[0];// 最高分double max = grades[grades.length - 1];// 计算去掉最高分与最低分的分数总和for (int i = 1; i < grades.length - 1 ; i++) {sum += grades[i];}// 实例化DecimalFormat对象,用于格式化十进制数字DecimalFormat format = new DecimalFormat();// 设置格式化格式format.applyPattern("#.##");// 计算平均分double avg = sum/3;// 实例化StringBuffer对象StringBuffer sb = new StringBuffer();// 追加最低分sb.append("去掉一个最低分:" + format.format(min) + " 分\n");// 追加最高分sb.append("去掉一个最高分:" + format.format(max) + " 分\n");// 追加平均分sb.append("平均得分:" + format.format(avg) + " 分");// 弹出提示窗口JOptionPane.showMessageDialog(null, sb.toString());}});button.setIcon(SwingResourceManager.getIcon(MainFrame.class, "/res/bt.png"));button.setBounds(284, 249, 103, 31);backgroundPanel.add(button);//}}

数组的基础练习

创建数组和数组之间数据的复制

import java.util.Arrays; //导入java.util.Arrays类
public class Eval {      // 创建类public static void main(String[] args) {// 创建数组arr1int arr1[] = new int[] { 1, 2, 3, 4, 5 };// 创建数组arr2int arr2[] = Arrays.copyOf(arr1, 3);// 复制源数组中从下标0开始的3个元素到目的数组,从下标0的位置开始存储。System.out.println("数组arr1:");// 遍历数组并输出元素for (int i = 0; i < arr1.length; i++){System.out.print(arr1[i]);}System.out.println();System.out.println("数组arr2:");// 遍历数组并输出元素for (int j = 0; j < arr2.length; j++){System.out.print(arr2[j]);}}
}

对数组排序并输出数组中最小的值

import java.util.Arrays;
public class Eval { // 创建类public static void main(String[] args) {int arr[] = new int[] { 10, 2, 3, 4, 5, 6, 7, 8, 9 };//对数组按升序进行排序Arrays.sort(arr);System.out.println("排序后的数组为:");for (int i : arr) {System.out.print(i + " ");}System.out.println();//输出数组中的最小值System.out.println("最小值为: " + arr[0]);}
}

将数组中指定索引位置的元素替换

import java.util.Arrays;
public class Eval { // 创建类public static void main(String[] args) {// 创建字符串数组String arr[] = new String[] { "ac", "bc", "dc", "yc" };// 打印数组print(arr);// 将数组的第3个元素填充为"bb"Arrays.fill(arr, 2, 3, "bb");// 打印数组print(arr);}// 打印数组中的元素public static void print(String[] arr){// 遍历数组for (String str : arr) {System.out.print(str + " ");}System.out.println();}
}

将二维数组的行列互换

public class Eval { // 创建类public static void main(String[] args) {// 创建2维数组int arr[][]= new int[][]{{1,2,3},{4,5,6},{7,8,9}};System.out.println("行列互调前:");// 输出2维数组for (int i = 0; i < arr.length; i++) {for (int j = 0; j < arr.length; j++) {System.out.print(arr[i][j] + " ");}System.out.println();}System.out.println("行列互调后:");// 输出2维数组for (int i = 0; i < arr.length; i++) {for (int j = 0; j < arr.length; j++) {System.out.print(arr[j][i] + " ");}System.out.println();}}
}

实现数组的复制功能

import java.util.Arrays;
public class Example {public static void main(String[] args) {// 创建数组arr1int arr1[] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };// 通过复制arr1创建数组arr2int arr2[] = Arrays.copyOf(arr1, arr1.length);// 遍历数组并打印输出for (int i = 0; i < arr2.length; i++) {System.out.print(arr2[i] + " ");}}
}

排序数组并输出排序后的数组

import java.util.Arrays;
public class Example {public static void main(String[] args) {// 创建int型数组numint[] num = { 30, 20, 25, 40, 8 };System.out.println("排序前:");print(num);// 对数组进行排序Arrays.sort(num);System.out.println("排序后:");print(num);}public static void print(int[] arr){// 遍历数组并打印输出for (int i = 0; i < arr.length; i++) {System.out.print(arr[i] + " ");}System.out.println();}
}

获得一维数组的长度 并输出

public class Example {public static void main(String[] args) {// 创建int型数组int[] arrInt = new int[12];// 创建boolean型数组boolean arrBoolean[] = new boolean[4];// 输出数组的长度System.out.println("arrInt 的长度为:" + arrInt.length); // 输出值为12System.out.println("arrBoolean 的长度为:" + arrBoolean.length); // 输出值为4}
}

利用一维数组输出7行杨辉三角形

public class Example {public static void main(String[] args) {int i, yh[] = new int[7];for (i = 0; i < 7; i++) {yh[i] = 1;for (int j = i - 1; j > 0; j--)yh[j] = yh[j - 1] + yh[j];for (int j = 0; j <= i; j++)System.out.print(yh[j] + "\t");System.out.println();}}
}

利用for循环输出二维数组中的值

public class Example {public static void main(String[] args) {// 创建二维数组int arr[][] = { { 1, 2, 3 }, { 4, 5, 6 } };// 遍历二维数组并输出其中的元素for (int i = 0; i < arr.length; i++) {for (int j = 0; j < arr[0].length; j++){System.out.print(arr[i][j]+"  ");}System.out.println();}}
}

用for循环为int 型数组赋值

public class Example {public static void main(String[] args) {// 声明数组时,方括号可以写在数据类型的右侧,也可以写在数组名的右侧int[] num = new int[10]; // num是数组名,方括号在数据类型右侧// 对数组元素赋值for (int i = 0; i < 10; i++) {num[i] = i + 1;}// 遍历数组并输出for (int i = 0; i < 10; i++) {System.out.print(i + " ");}}
}

将字符串反向输出

/*** 数组工具类* @author wuyang*/
public class ArrayUtil {// 反转字符串方法public static String reverse(String text){// 实例化StringBufferStringBuffer sb = new StringBuffer();// 判断字符串是否为空if(text != null && !text.isEmpty()){// 将字符串转为字符数组char[] arr = text.toCharArray();// 反向获取for(int i = arr.length - 1; i >=0; i--){sb.append(arr[i]);}}// 返回转字符串return sb.toString();}
}

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import com.lzw.BackgroundPanel;
import com.swtdesigner.SwingResourceManager;public class MainFrame extends JFrame {private static final long serialVersionUID = -1368705126832671635L;private JTextField textField_1;private JTextField textField;/*** Launch the application* @param args*/public static void main(String args[]) {EventQueue.invokeLater(new Runnable() {public void run() {try {MainFrame frame = new MainFrame();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame*/public MainFrame() {super();setResizable(false);setTitle("字符串反向输出");setBounds(100, 100, 484, 242);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final BackgroundPanel backgroundPanel = new BackgroundPanel();backgroundPanel.setImage(SwingResourceManager.getImage(MainFrame.class, "/res/bg.jpg"));getContentPane().add(backgroundPanel, BorderLayout.CENTER);textField = new JTextField();textField.setBounds(97, 65, 278, 22);backgroundPanel.add(textField);final JLabel label = new JLabel();label.setText("请输入:");label.setBounds(97, 41, 52, 18);backgroundPanel.add(label);textField_1 = new JTextField();textField_1.setBounds(97, 143, 278, 22);backgroundPanel.add(textField_1);final JButton button = new JButton();button.addActionListener(new ActionListener() {public void actionPerformed(final ActionEvent e) {// 获取所输入的字符串String text = textField.getText();// 判断输入内容是否有效if(text == null || text.isEmpty()){// 提示错误信息JOptionPane.showMessageDialog(null, "请输入内容!");}else{// 将字符串反转textField_1.setText(ArrayUtil.reverse(text));}}});button.setText("反转");button.setBounds(186, 104, 69, 22);backgroundPanel.add(button);//}}

简易电子时钟

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.util.Calendar;import javax.swing.JFrame;
import javax.swing.JLabel;public class MainFrame extends JFrame {private static final long serialVersionUID = 7791539566768257092L;/*** Launch the application* @param args*/public static void main(String args[]) {EventQueue.invokeLater(new Runnable() {public void run() {try {MainFrame frame = new MainFrame();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame*/public MainFrame() {super();setTitle("简易电子时钟");setResizable(false);setBounds(100, 100, 362, 152);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final ClockPanel clockPanel = new ClockPanel();getContentPane().add(clockPanel, BorderLayout.CENTER);final JLabel label = new JLabel();label.setForeground(Color.ORANGE);label.setFont(new Font("黑体", Font.BOLD, 22));// 定义数组String[] weeks = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"}; // 实例化Calendar对象Calendar c = Calendar.getInstance();// 获取今天是一周的第几天int index = c.get(Calendar.DAY_OF_WEEK) - 1;// 输出结果label.setText(weeks[index]);label.setBounds(136, 72, 92, 25);clockPanel.add(label);}}

随机获取试题

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextPane;import com.swtdesigner.SwingResourceManager;public class MainFrame extends JFrame {private static final long serialVersionUID = 6061185921095535754L;/*** Launch the application* @param args*/public static void main(String args[]) {EventQueue.invokeLater(new Runnable() {public void run() {try {MainFrame frame = new MainFrame();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame*/public MainFrame() {super();setTitle("随机抽奖");setBounds(100, 100, 429, 286);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final BackgroundPanel backgroundPanel = new BackgroundPanel();backgroundPanel.setImage(SwingResourceManager.getImage(MainFrame.class, "/res/bg.jpg"));getContentPane().add(backgroundPanel, BorderLayout.CENTER);final JLabel label = new JLabel();label.setForeground(Color.BLUE);label.setFont(new Font("", Font.BOLD, 14));label.setBounds(76, 52, 203, 28);backgroundPanel.add(label);final JTextPane textPane = new JTextPane();textPane.setForeground(new Color(255, 255, 255));textPane.setFont(new Font("", Font.BOLD, 14));textPane.setOpaque(false);textPane.setBounds(88, 100, 271, 121);backgroundPanel.add(textPane);final JButton button = new JButton();button.addActionListener(new ActionListener() {public void actionPerformed(final ActionEvent e) {//创建试题数组String[][] questions = {{"脑筋急转弯","1+1在什么情况不等于2?"},{"抢答题","1+1在什么情况等于2?"},{"脑筋急转弯","地上一个猴,树上骑个\n猴,总共有几只猴?"},{"抢答题","明天的明天的明天是哪一天?"},{"计算题","55*55等于多少?"}};// 实例化Random用于生成随机数Random rand = new Random();// 生成随机数int index = rand.nextInt(questions.length);// 获取试题String[] ques = questions[index];// 显示题目 label.setText(ques[0]);// 显示内容textPane.setText(ques[1]);}});button.setText("抽取试题");button.setBounds(325, 10, 86, 28);backgroundPanel.add(button);}}

学生信息管理

/*** 自定义数组工具类* @author wuyang*/
public class ArrayUtil {// 创建学生信息集合数组private static String[][] students;/*** 向学生集合数组中添加学生信息* @param student 学生信息* @return 学生集合数组*/public static String[][] add(String[] student){// 判断学生信息数据是否有效if(student == null || student.length != 4){return null;}// 判断学生信息数据是否已创建if(students == null){// 实例化学生信息数据students = new String[][]{{student[0],student[1],student[2],student[3]}};}else{// 创建一个二维数组String[][] temp = new String[students.length + 1][student.length];// 将学生信息数据复制到二维数组中System.arraycopy(students, 0, temp, 0, students.length);// 将新的学生数据添加到二维数组temp中for (int i = 0; i < student.length; i++) {// 添加数据temp[temp.length -1][i] = student[i];}// 更新数组students = temp;}// 返回所有学生信息return students;}
}

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import com.lyq.StudentPanel;public class MainFrame extends JFrame {private static final long serialVersionUID = 746654481079475727L;private JTextField tf_sex;private JTextField tf_age;private JTextField tf_name;private JTextField tf_id;/*** Launch the application* @param args*/public static void main(String args[]) {EventQueue.invokeLater(new Runnable() {public void run() {try {MainFrame frame = new MainFrame();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame*/public MainFrame() {super();setResizable(false);setTitle("学生信息管理");getContentPane().setLayout(null);setBounds(100, 100, 402, 288);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final JLabel label = new JLabel();label.setHorizontalAlignment(SwingConstants.RIGHT);label.setText("学号:");label.setBounds(10, 25, 66, 18);getContentPane().add(label);final JLabel label_1 = new JLabel();label_1.setHorizontalAlignment(SwingConstants.RIGHT);label_1.setText("年龄:");label_1.setBounds(10, 64, 66, 18);getContentPane().add(label_1);final JLabel label_2 = new JLabel();label_2.setHorizontalAlignment(SwingConstants.RIGHT);label_2.setText("姓名:");label_2.setBounds(170, 25, 66, 18);getContentPane().add(label_2);final JLabel label_3 = new JLabel();label_3.setHorizontalAlignment(SwingConstants.RIGHT);label_3.setText("性别:");label_3.setBounds(170, 64, 66, 18);getContentPane().add(label_3);tf_id = new JTextField();tf_id.setBounds(82, 23, 87, 22);getContentPane().add(tf_id);tf_name = new JTextField();tf_name.setBounds(242, 23, 87, 22);getContentPane().add(tf_name);tf_age = new JTextField();tf_age.setBounds(82, 62, 87, 22);getContentPane().add(tf_age);tf_sex = new JTextField();tf_sex.setBounds(242, 62, 87, 22);getContentPane().add(tf_sex);final StudentPanel studentPanel = new StudentPanel();final JButton button = new JButton();button.addActionListener(new ActionListener() {public void actionPerformed(final ActionEvent e) {// 获取学号String id = tf_id.getText();// 获取姓名String name = tf_name.getText();// 获取年龄String age = tf_age.getText();// 获取性别String sex = tf_sex.getText();// 获取学号if(!id.isEmpty() && !name.isEmpty() && !age.isEmpty() && !sex.isEmpty()){// 使用数组创建一条学生信息数据String[] student = {id,name,age,sex};// 将学生信息添加到集合中String[][] students = ArrayUtil.add(student);// 显示学生信息studentPanel.setStudents(students);}}});button.setText("添加");button.setBounds(250, 96, 79, 22);getContentPane().add(button);studentPanel.setBounds(0, 145, 395, 117);getContentPane().add(studentPanel);//}}

金额大小写转换

import java.text.DecimalFormat;import javax.swing.JOptionPane;/*** 金额转换* @author wuyang*/
public class ConvertMoney {// 大写数字private final static String[] STR_NUMBER = { "零", "壹", "贰", "叁", "肆", "伍","陆", "柒", "捌", "玖" };// 单位private final static String[] STR_UNIT = { "", "拾", "佰", "仟", "万", "拾","佰", "仟", "亿", "拾", "佰", "仟" };// 单位private final static String[] STR_UNIT2 = {"厘","分","角"};/*** 获取可数部分* @param num 金额* @return 金额整数部分*/public static String getInteger(String num) {// 判断是否包含小数点if (num.indexOf(".") != -1) {num = num.substring(0, num.indexOf("."));   }// 反转字符串num = new StringBuffer(num).reverse().toString();// 创建一个StringBuffer对象StringBuffer temp = new StringBuffer();// 加入单位for (int i = 0; i < num.length(); i++) {temp.append(STR_UNIT[i]);temp.append(STR_NUMBER[num.charAt(i) - 48]);}// 反转字符串num = temp.reverse().toString();num = numReplace(num, "零拾", "零");   // 替换字符串的字符num = numReplace(num, "零佰", "零");   // 替换字符串的字符num = numReplace(num, "零仟", "零");   // 替换字符串的字符num = numReplace(num, "零万", "万");   // 替换字符串的字符num = numReplace(num, "零亿", "亿");   // 替换字符串的字符num = numReplace(num, "零零", "零");   // 替换字符串的字符num = numReplace(num, "亿万", "亿");   // 替换字符串的字符// 如果字符串以零结尾将其除去if(num.lastIndexOf("零") == num.length()-1){num = num.substring(0, num.length() -1);}return num;}/*** 获取小数部分* @param num 金额* @return 金额的小数部分*/public static String getDecimal(String num){// 判断是否包含小数点if (num.indexOf(".") == -1) {return "";}num = num.substring(num.indexOf(".") + 1);//反转字符串num = new StringBuffer(num).reverse().toString();// 创建一个StringBuffer对象StringBuffer temp = new StringBuffer();// 加入单位for (int i = 0; i < num.length(); i++) {temp.append(STR_UNIT2[i]);temp.append(STR_NUMBER[num.charAt(i) - 48]);}// 替换字符串的字符num = temp.reverse().toString();num = numReplace(num, "零角", "零");   // 替换字符串的字符num = numReplace(num, "零分", "零");   // 替换字符串的字符num = numReplace(num, "零厘", "零");   // 替换字符串的字符num = numReplace(num, "零零", "零");   // 替换字符串的字符// 如果字符串以零结尾将其除去if(num.lastIndexOf("零") == num.length()-1){num = num.substring(0, num.length() -1);}return num;}/*** 替换字符串中内容* @param num 字符串* @param oldStr 被替换内容* @param newStr 新内容* @return 替换后的字符串*/public static String numReplace(String num,String oldStr,String newStr){while(true){// 判断字符串中是否包含指定字符if(num.indexOf(oldStr) == -1){break;}// 替换字符串 num = num.replaceAll(oldStr, newStr);}// 返回替换后的字符串return num;}/*** 金额转换* @param d 金额* @return 转换成大写的全额*/public static String convert(double d){// 实例化DecimalFormat对象DecimalFormat df = new DecimalFormat("#0.###");// 格式化double数字String strNum = df.format(d);// 判断是否包含小数点if (strNum.indexOf(".") != -1) {String num = strNum.substring(0, strNum.indexOf("."));// 整数部分大于12不能转换if(num.length() > 12){JOptionPane.showMessageDialog(null, "数字太大,不能完成转换!");return "";}}// 小数点String point = "";if(strNum.indexOf(".") != -1){point = "元";}else{point = "元整";}// 转换结果String result = getInteger(strNum) + point + getDecimal(strNum);// 判断是字符串是否已"元"结尾if(result.startsWith("元")){// 截取字符串result = result.substring(1, result.length());}// 返回新的字符串return result;}
}

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextPane;import com.swtdesigner.SwingResourceManager;public class MainFrame extends JFrame {private static final long serialVersionUID = 1272119087959058558L;private DoubleText doubleText;/*** Launch the application* @param args*/public static void main(String args[]) {EventQueue.invokeLater(new Runnable() {public void run() {try {MainFrame frame = new MainFrame();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame*/public MainFrame() {super();setResizable(false);setTitle("金额大小写转换程序");setBounds(100, 100, 450, 300);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final BackgroundPanel backgroundPanel = new BackgroundPanel();backgroundPanel.setImage(SwingResourceManager.getImage(MainFrame.class, "/bg.jpg"));getContentPane().add(backgroundPanel, BorderLayout.CENTER);final JLabel label = new JLabel();label.setText("小写金额:");label.setBounds(29, 160, 66, 18);backgroundPanel.add(label);doubleText = new DoubleText();doubleText.setBounds(107, 158, 218, 22);backgroundPanel.add(doubleText);final JTextPane textPane = new JTextPane();textPane.setBounds(29, 192, 387, 52);backgroundPanel.add(textPane);final JButton button = new JButton();button.addActionListener(new ActionListener() {public void actionPerformed(final ActionEvent e) {// 获取金额double value = doubleText.getDouble();// 将金额转换大写String valueCase = ConvertMoney.convert(value);// 将转换后的金额显示在textPane中textPane.setText(valueCase);}});button.setText(">>");button.setBounds(339, 155, 77, 23);backgroundPanel.add(button);//}}

java 基础知识学习2相关推荐

  1. JAVA基础知识学习全覆盖

    文章目录 一.JAVA基础知识 1.一些基本概念 1.Stringbuffer 2.局部变量成员变量 3.反射机制 4.protect 5.pow(x,y) 6.final ,finally,fina ...

  2. java基础知识学习小总结(一)

    此文转载自:https://blog.csdn.net/weixin_44734093/article/details/109715246 什么是java Java是一门面向对象编程语言,不仅吸收了C ...

  3. Java基础知识学习笔记总结

    Java学习笔记总结 java基础复习 1. 抽象类可以有构造器,可以有一个非抽象的父类 2. 垃圾回收机制回收的是堆里面的内存,栈里面的数据自动入栈自动出栈 3. 引用类型的数据在堆当中,内存中操作 ...

  4. Java基础知识学习:简单随手记录(3)

    学习视频链接:https://www.bilibili.com/video/BV1fh411y7R8?p=1&vd_source=1635a55d1012e0ef6688b3652cefcdf ...

  5. 超详细的java基础知识学习(java SE、javaEE)笔记 核心重点!

    标识符 Java 的标识符是由字母.数字.下划线_.以及美元符$组成,但是首字母不可以是数字.Java 标识符大小写敏感,长度无限制,不能是 Java 中的关键字.命名规则:要见名知意! u  变量要 ...

  6. Java基础知识学习:简单随手记录(1)

    学习视频链接:https://www.bilibili.com/video/BV1fh411y7R8?p=1&vd_source=1635a55d1012e0ef6688b3652cefcdf ...

  7. JAVA基础知识学习

    1.各个方面知识 很全面的知识总结(推荐): https://www.yuque.com/crow/simpread/23aba84d-73b3-4950-9621-bf511b2d088a#cf65 ...

  8. Java基础知识学习巩固2--int和Integer有什么区别及扩展

    这个问题之前首先要介绍下Java数据类型, 一.Java基本类型,主要有8种,分别是: 1.boolean(布尔型即只有true和false), 2.char(字节型16 位 Unicode 字符), ...

  9. Java基础知识学习01-环境变量的配置、数据类型

    Java  SE(Java Platform Standard Edition)  标准版    用于桌面程序开发 Java EE (Java Platform  Enterprise Edition ...

最新文章

  1. 【Science】CMU机器学习系主任:八个关键标准判别深度学习任务成功与否
  2. 大咖 | 斯坦福教授骆利群:为何人脑比计算机慢1000万倍,却如此高效?
  3. 每日一皮:公司来了个程序员鼓励师...
  4. 初始python(二)
  5. C#语法:委托与方法
  6. CVPR 2020 | CMU HKUST提出binary网络自动化搜索,同时实现超高压缩与高精度
  7. python学习(八)定制类和枚举
  8. 进程控制2--exec族
  9. VC6 Win7 x64 提示 Remote Executable path And File Name
  10. vue-cli 脚手架移除、安装(最新版安装)、检测安装结果 - npm篇
  11. 点击文本框内容消失,移开内容自动显示(两种方法)(原创)
  12. origin8.1中文乱码设置方法
  13. 如何做好客户需求分析
  14. C++ 多种取整函数的使用和区别: ceil() floor() round() trunc() rint() nearbyint()
  15. 编程之美-2.3-寻找发帖“水王”
  16. 利用Xutils框架进行断点续传下载
  17. 驱动字库芯片GT23L24M0140
  18. DotAsterisk(点星PBX)IPPBX V4.1下载地址
  19. CSS display的属性
  20. R语言学习:卡方检验

热门文章

  1. 强化学习用 Sarsa 算法与 Q-learning 算法实现FrozenLake-v0
  2. 根据经纬度坐标计算实际距离
  3. Black-Scholes-Merton 方程解(基于风险中性定价)
  4. Unity中键名称与键位对应一览
  5. 全网 Vue 最XXXXXXX...... 男人看了沉默,女人看了流泪
  6. JAVA程序开发参考手册
  7. ftp(文件传输协议)服务
  8. 怎么装win7与linux双,装双系统win7和linux_win7与linux双系统
  9. 磁盘盘符隐藏并访问隐藏磁盘的文件数据
  10. java pdf添加透明水印_如何使用PDF编辑工具在PDF文件中添加透明水印